72f5f076d3d15dbc839e1b6994830abe70b4e0ad
5 Copyright (C) Dean Camera, 2018.
7 dean [at] fourwalledcubicle [dot] com
12 LUFA Generic HID device demo host test script. This script will send a
13 continuous stream of generic reports to the device, to show a variable LED
14 pattern on the target board. Send and received report data is printed to
17 Requires the pywinusb library (https://pypi.python.org/pypi/pywinusb/).
21 from time
import sleep
25 def get_hid_device_handle():
26 all_hid_devices
= hid
.enumerate()
28 lufa_hid_devices
= [d
for d
in all_hid_devices
if d
['vendor_id'] == 0x03EB and d
['product_id'] == 0x204F]
30 if len(lufa_hid_devices
) is 0:
33 device_handle
= hid
.device()
34 device_handle
.open_path(lufa_hid_devices
[0]['path'])
38 def send_led_pattern(device
, led1
, led2
, led3
, led4
):
39 # Report data for the demo is the report ID (always zero) followed by the
41 report_data
= bytearray(9)
48 # Send the generated report to the device
49 device
.write(report_data
)
51 print("Sent LED Pattern: {0}".format(report_data
[1:5]))
54 def received_led_pattern(report_data
):
55 print("Received LED Pattern: {0}".format(report_data
[1:5]))
59 hid_device
= get_hid_device_handle()
61 if hid_device
is None:
62 print("No valid HID device found.")
66 print("Connected to device.", flush
=True)
68 # Set up the HID input report handler to receive reports
69 hid_device
.set_raw_data_handler(received_led_pattern
)
72 while (hid_device
.is_plugged()):
73 # Convert the current pattern index to a bit-mask and send
74 send_led_pattern(hid_device
,
80 # Compute next LED pattern in sequence
83 # Delay a bit for visual effect
90 if __name__
== '__main__':