Changeset 44e2c1a in mainline
- Timestamp:
- 2011-06-18T15:48:51Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ae5f77d5
- Parents:
- bd08239
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbd/kbddev.c
rbd08239 r44e2c1a 319 319 } 320 320 321 static size_t find_in_array_int32(int32_t val, int32_t *arr, size_t arr_size) 322 { 323 for (size_t i = 0; i < arr_size; i++) { 324 if (arr[i] == val) { 325 return i; 326 } 327 } 328 329 return (size_t) -1; 330 } 331 321 332 /*----------------------------------------------------------------------------*/ 322 333 /** … … 339 350 { 340 351 unsigned int key; 341 unsigned int i, j;352 size_t i; 342 353 343 354 /* … … 349 360 * whole input report. 350 361 */ 351 i = 0; 352 while (i < kbd_dev->key_count && kbd_dev->keys[i] != ERROR_ROLLOVER) { 353 ++i; 354 } 355 if (i != kbd_dev->key_count) { 356 usb_log_debug("Phantom state occured.\n"); 357 // phantom state, do nothing 362 i = find_in_array_int32(ERROR_ROLLOVER, kbd_dev->keys, 363 kbd_dev->key_count); 364 if (i != (size_t) -1) { 365 usb_log_debug("Detected phantom state.\n"); 358 366 return; 359 367 } 360 368 361 369 /* 362 * 1) Key releases 363 */ 364 for (j = 0; j < kbd_dev->key_count; ++j) { 365 // try to find the old key in the new key list 366 i = 0; 367 while (i < kbd_dev->key_count 368 && kbd_dev->keys[i] != kbd_dev->keys_old[j]) { 369 ++i; 370 } 371 372 if (i == kbd_dev->key_count) { 373 // not found, i.e. the key was released 374 key = usbhid_parse_scancode(kbd_dev->keys_old[j]); 370 * Key releases 371 */ 372 for (i = 0; i < kbd_dev->key_count; i++) { 373 int32_t old_key = kbd_dev->keys_old[i]; 374 /* Find the old key among currently pressed keys. */ 375 size_t pos = find_in_array_int32(old_key, kbd_dev->keys, 376 kbd_dev->key_count); 377 /* If the key was not found, we need to signal release. */ 378 if (pos == (size_t) -1) { 379 key = usbhid_parse_scancode(old_key); 375 380 if (!usb_kbd_is_lock(key)) { 376 381 usb_kbd_repeat_stop(kbd_dev, key); 377 382 } 378 383 usb_kbd_push_ev(hid_dev, kbd_dev, KEY_RELEASE, key); 379 usb_log_debug2("Key released: %d\n", key); 380 } else { 381 // found, nothing happens 382 } 383 } 384 385 /* 386 * 1) Key presses 384 usb_log_debug2("Key released: %u " 385 "(USB code %" PRIu32 ")\n", key, old_key); 386 } 387 } 388 389 /* 390 * Key presses 387 391 */ 388 392 for (i = 0; i < kbd_dev->key_count; ++i) { 389 // try to find the new key in the old key list 390 j = 0; 391 while (j < kbd_dev->key_count 392 && kbd_dev->keys_old[j] != kbd_dev->keys[i]) { 393 ++j; 394 } 395 396 if (j == kbd_dev->key_count) { 397 // not found, i.e. new key pressed 393 int32_t new_key = kbd_dev->keys[i]; 394 /* Find the new key among already pressed keys. */ 395 size_t pos = find_in_array_int32(new_key, kbd_dev->keys_old, 396 kbd_dev->key_count); 397 /* If the key was not found, we need to signal press. */ 398 if (pos == (size_t) -1) { 398 399 key = usbhid_parse_scancode(kbd_dev->keys[i]); 399 usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,400 kbd_dev->keys[i]);401 400 if (!usb_kbd_is_lock(key)) { 402 401 usb_kbd_repeat_start(kbd_dev, key); 403 402 } 404 403 usb_kbd_push_ev(hid_dev, kbd_dev, KEY_PRESS, key); 405 } else {406 // found, nothing happens404 usb_log_debug2("Key pressed: %u " 405 "(USB code %" PRIu32 ")\n", key, new_key); 407 406 } 408 407 }
Note:
See TracChangeset
for help on using the changeset viewer.