Skip to content

Commit e7c64fd

Browse files
authored
Merge pull request #143 from adafruit/update-hidtest-py
update hid test py to support list of VIDs
2 parents 7ae98a4 + 8716d79 commit e7c64fd

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
# Install python3 HID package https://pypi.org/project/hid/
22
import hid
33

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)
66

7-
print("Openning HID device with VID = 0x%X" % USB_VID)
7+
print("VID list: " + ", ".join('%02x' % v for v in USB_VID))
88

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

Comments
 (0)