|
7 | 7 |
|
8 | 8 | import adafruit_usb_host_descriptors
|
9 | 9 |
|
10 |
| -# lists for mouse interface indexes, endpoint addresses, and USB Device instances |
11 |
| -# each of these will end up with length 2 once we find both mice |
12 |
| -mouse_interface_indexes = None |
13 |
| -mouse_endpoint_addresses = None |
| 10 | +keyboard_interface_index = None |
| 11 | +keyboard_endpoint_address = None |
14 | 12 | keyboard = None
|
15 | 13 |
|
16 | 14 | # scan for connected USB devices
|
17 | 15 | for device in usb.core.find(find_all=True):
|
18 |
| - # check for boot mouse endpoints on this device |
19 |
| - kbd_interface_index, kbd_endpoint_address = ( |
| 16 | + # check for boot keyboard endpoints on this device |
| 17 | + keyboard_interface_index, keyboard_endpoint_address = ( |
20 | 18 | adafruit_usb_host_descriptors.find_boot_keyboard_endpoint(device)
|
21 | 19 | )
|
22 | 20 | # if a boot mouse interface index and endpoint address were found
|
23 |
| - if kbd_interface_index is not None and kbd_interface_index is not None: |
| 21 | + if keyboard_interface_index is not None and keyboard_endpoint_address is not None: |
24 | 22 | keyboard = device
|
25 | 23 |
|
26 | 24 | # detach device from kernel if needed
|
27 | 25 | if keyboard.is_kernel_driver_active(0):
|
28 | 26 | keyboard.detach_kernel_driver(0)
|
29 | 27 |
|
30 |
| - # set the mouse configuration so it can be used |
| 28 | + # set the configuration so the keyboard can be used |
31 | 29 | keyboard.set_configuration()
|
32 | 30 |
|
33 | 31 | buf = array.array("b", [0] * 8)
|
34 | 32 |
|
35 | 33 | while True:
|
36 |
| - # try to read data from the mouse |
| 34 | + # try to read data from the keyboard |
37 | 35 | try:
|
38 |
| - count = keyboard.read(mouse_endpoint_addresses, buf, timeout=10) |
| 36 | + count = keyboard.read(keyboard_endpoint_address, buf, timeout=10) |
39 | 37 |
|
40 | 38 | # if there is no data it will raise USBTimeoutError
|
41 | 39 | except usb.core.USBTimeoutError:
|
42 |
| - # Nothing to do if there is no data for this mouse |
| 40 | + # Nothing to do if there is no data for this keyboard |
43 | 41 | continue
|
44 | 42 |
|
45 | 43 | for b in buf:
|
|
0 commit comments