From 033a575a18dc61134100b444b03940c2a48cd01d Mon Sep 17 00:00:00 2001 From: harbaum Date: Tue, 21 Feb 2006 21:43:03 +0000 Subject: [lcd4linux @ 2006-02-21 21:43:03 by harbaum] Keypad support for LCD2USB git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@644 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- drv_LCD2USB.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/drv_LCD2USB.c b/drv_LCD2USB.c index b6aa1fe..c535a96 100644 --- a/drv_LCD2USB.c +++ b/drv_LCD2USB.c @@ -1,4 +1,4 @@ -/* $Id: drv_LCD2USB.c,v 1.6 2006/02/12 14:32:24 harbaum Exp $ +/* $Id: drv_LCD2USB.c,v 1.7 2006/02/21 21:43:03 harbaum Exp $ * * driver for USB2LCD display interface * see http://www.harbaum.org/till/lcd2usb for schematics @@ -24,6 +24,9 @@ * * * $Log: drv_LCD2USB.c,v $ + * Revision 1.7 2006/02/21 21:43:03 harbaum + * Keypad support for LCD2USB + * * Revision 1.6 2006/02/12 14:32:24 harbaum * Configurable bus/device id * @@ -69,19 +72,25 @@ #include "debug.h" #include "cfg.h" +#include "timer.h" #include "qprintf.h" #include "plugin.h" #include "widget.h" #include "widget_text.h" #include "widget_icon.h" #include "widget_bar.h" +#include "widget_keypad.h" #include "drv.h" #include "drv_generic_text.h" +#include "drv_generic_keypad.h" /* vid/pid donated by FTDI */ #define LCD_USB_VENDOR 0x0403 #define LCD_USB_DEVICE 0xC630 +/* number of buttons on display */ +#define L2U_BUTTONS (2) + #define LCD_ECHO (0<<5) #define LCD_CMD (1<<5) #define LCD_DATA (2<<5) @@ -127,11 +136,11 @@ static int drv_L2U_open(char *bus_id, char *device_id) info("%s: scanning USB for LCD2USB interface ...", Name); - if(bus_id != NULL) - info("%s: scanning for bus id: %s", Name, bus_id); + if (bus_id != NULL) + info("%s: scanning for bus id: %s", Name, bus_id); - if(device_id != NULL) - info("%s: scanning for device id: %s", Name, device_id); + if (device_id != NULL) + info("%s: scanning for device id: %s", Name, device_id); usb_debug = 0; @@ -141,15 +150,15 @@ static int drv_L2U_open(char *bus_id, char *device_id) busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { - /* search this bus if no bus id was given or if this is the given bus id */ - if(!bus_id || (bus_id && !strcasecmp(bus->dirname, bus_id))) { + /* search this bus if no bus id was given or if this is the given bus id */ + if (!bus_id || (bus_id && !strcasecmp(bus->dirname, bus_id))) { for (dev = bus->devices; dev; dev = dev->next) { - /* search this device if no device id was given or if this is the given device id */ - if(!device_id || (device_id && !strcasecmp(dev->filename, device_id))) { + /* search this device if no device id was given or if this is the given device id */ + if (!device_id || (device_id && !strcasecmp(dev->filename, device_id))) { if ((dev->descriptor.idVendor == LCD_USB_VENDOR) && (dev->descriptor.idProduct == LCD_USB_DEVICE)) { - info("%s: found LCD2USB interface on bus %s device %s", Name, bus->dirname, dev->filename); + info("%s: found LCD2USB interface on bus %s device %s", Name, bus->dirname, dev->filename); lcd = usb_open(dev); if (usb_claim_interface(lcd, 0) < 0) { error("%s: usb_claim_interface() failed!", Name); @@ -286,9 +295,7 @@ static unsigned long drv_L2U_get_buttons(void) { int buttons = drv_L2U_get(LCD_GET_BUTTONS); - if (buttons != -1) - info("%s: button state 0:%s 1:%s", Name, (buttons & 1) ? "on" : "off", (buttons & 2) ? "on" : "off"); - else { + if (buttons == -1) { error("%s: unable to read button state", Name); buttons = 0; } @@ -433,6 +440,42 @@ static int drv_L2U_brightness(int brightness) return brightness; } +static void drv_L2U_timer(void __attribute__ ((unused)) * notused) +{ + static unsigned long last_but = 0; + unsigned long new_but = drv_L2U_get_buttons(); + int i; + + /* check if button state changed */ + if (new_but ^ last_but) { + + /* send single keypad events for all changed buttons */ + for (i = 0; i < L2U_BUTTONS; i++) + if ((new_but & (1 << i)) ^ (last_but & (1 << i))) + drv_generic_keypad_press(((new_but & (1 << i)) ? 0x80 : 0) | i); + } + + last_but = new_but; +} + +static int drv_L2U_keypad(const int num) +{ + int val = 0; + + /* check for key press event */ + if (num & 0x80) + val = KEY_PRESSED; + else + val = KEY_RELEASED; + + if ((num & 0x7f) == 0) + val += KEY_UP; + + if ((num & 0x7f) == 1) + val += KEY_DOWN; + + return val; +} static int drv_L2U_start(const char *section, const int quiet) { @@ -454,6 +497,7 @@ static int drv_L2U_start(const char *section, const int quiet) DROWS = rows; DCOLS = cols; + KEYPADSIZE = L2U_BUTTONS; /* bus id and device id are strings and not just intergers, since */ /* the windows port of libusb treats them as strings. And this way */ @@ -475,8 +519,9 @@ static int drv_L2U_start(const char *section, const int quiet) if (!controllers) return -1; - /* call get_buttons to make compiler happy ... */ - drv_L2U_get_buttons(); + /* regularly request key state */ + /* Fixme: make 100msec configurable */ + timer_add(drv_L2U_timer, NULL, 100, 0); if (cfg_number(section, "Contrast", 0, 0, 255, &contrast) > 0) { drv_L2U_contrast(contrast); @@ -553,7 +598,7 @@ int drv_L2U_init(const char *section, const int quiet) int asc255bug; int ret; - info("%s: %s", Name, "$Revision: 1.6 $"); + info("%s: %s", Name, "$Revision: 1.7 $"); /* display preferences */ XRES = 5; /* pixel width of one char */ @@ -565,6 +610,7 @@ int drv_L2U_init(const char *section, const int quiet) /* real worker functions */ drv_generic_text_real_write = drv_L2U_write; drv_generic_text_real_defchar = drv_L2U_defchar; + drv_generic_keypad_real_press = drv_L2U_keypad; /* start display */ if ((ret = drv_L2U_start(section, quiet)) != 0) @@ -591,6 +637,10 @@ int drv_L2U_init(const char *section, const int quiet) if (!asc255bug) drv_generic_text_bar_add_segment(255, 255, 255, 255); /* ASCII 255 = block */ + /* initialize generic key pad driver */ + if ((ret = drv_generic_keypad_init(section, Name)) != 0) + return ret; + /* register text widget */ wc = Widget_Text; wc.draw = drv_generic_text_draw; @@ -621,6 +671,7 @@ int drv_L2U_quit(const int quiet) info("%s: shutting down.", Name); drv_generic_text_quit(); + drv_generic_keypad_quit(); /* clear display */ drv_L2U_clear(); -- cgit v1.2.3 127'>127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476