|
1 | 1 | # Install python3 HID package https://pypi.org/project/hid/
|
2 | 2 | import hid
|
3 | 3 |
|
4 |
| -# default is Adafruit VID |
5 |
| -USB_VID = 0x239A |
| 4 | +# default is TinyUSB (0xcafe), Adafruit (0x239a), RaspberryPi (0x2e8a), Espressif (0x303a) VID |
| 5 | +USB_VID = (0xcafe, 0x239a, 0x2e8a, 0x303a) |
6 | 6 |
|
7 |
| -print("Openning HID device with VID = 0x%X" % USB_VID) |
| 7 | +print("VID list: " + ", ".join('%02x' % v for v in USB_VID)) |
8 | 8 |
|
9 |
| -for dict in hid.enumerate(USB_VID): |
10 |
| - print(dict) |
11 |
| - dev = hid.Device(dict['vendor_id'], dict['product_id']) |
12 |
| - if dev: |
13 |
| - while True: |
14 |
| - # Get input from console and encode to UTF8 for array of chars. |
15 |
| - # hid generic inout is single report therefore by HIDAPI requirement |
16 |
| - # it must be preceeded with 0x00 as dummy reportID |
17 |
| - str_out = b'\x00' |
18 |
| - str_out += input("Send text to HID Device : ").encode('utf-8') |
19 |
| - dev.write(str_out) |
20 |
| - str_in = dev.read(64) |
21 |
| - print("Received from HID Device:", str_in, '\n') |
| 9 | +for vid in USB_VID: |
| 10 | + for dict in hid.enumerate(vid): |
| 11 | + print(dict) |
| 12 | + dev = hid.Device(dict['vendor_id'], dict['product_id']) |
| 13 | + if dev: |
| 14 | + while True: |
| 15 | + # Get input from console and encode to UTF8 for array of chars. |
| 16 | + # hid generic inout is single report therefore by HIDAPI requirement |
| 17 | + # it must be preceeded with 0x00 as dummy reportID |
| 18 | + str_out = b'\x00' |
| 19 | + str_out += input("Send text to HID Device : ").encode('utf-8') |
| 20 | + dev.write(str_out) |
| 21 | + str_in = dev.read(64) |
| 22 | + print("Received from HID Device:", str_in, '\n') |
0 commit comments