diff options
author | Dean Camera <dean@fourwalledcubicle.com> | 2013-07-07 13:09:26 +0200 |
---|---|---|
committer | Dean Camera <dean@fourwalledcubicle.com> | 2013-07-07 13:09:26 +0200 |
commit | 873d288f31d8b9ce1ec79d197b333448076d456d (patch) | |
tree | 328480a1be09092559654b42c376c9f42acb4b71 | |
parent | 8d1376bbe92123465bbad9881832404e762d6342 (diff) | |
download | lufa-873d288f31d8b9ce1ec79d197b333448076d456d.tar.gz lufa-873d288f31d8b9ce1ec79d197b333448076d456d.tar.bz2 lufa-873d288f31d8b9ce1ec79d197b333448076d456d.zip |
Refactor GenericHID Python test script code to make user specific adjustments easier.
-rw-r--r-- | Demos/Device/ClassDriver/GenericHID/HostTestApp/test_generic_hid.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Demos/Device/ClassDriver/GenericHID/HostTestApp/test_generic_hid.py b/Demos/Device/ClassDriver/GenericHID/HostTestApp/test_generic_hid.py index f04892a06..491805509 100644 --- a/Demos/Device/ClassDriver/GenericHID/HostTestApp/test_generic_hid.py +++ b/Demos/Device/ClassDriver/GenericHID/HostTestApp/test_generic_hid.py @@ -19,9 +19,17 @@ import sys from time import sleep import pywinusb.hid as hid +# Generic HID device VID, PID and report payload length (length is increased +# by one to account for the Report ID byte that must be pre-pended) +device_vid = 0x03EB +device_pid = 0x204F +report_length = 1 + 8 + + +def get_hid_device_handle(): + hid_device_filter = hid.HidDeviceFilter(vendor_id=device_vid, + product_id=device_pid) -def get_hid_device_handle(VID, PID): - hid_device_filter = hid.HidDeviceFilter(vendor_id = VID, product_id = PID) valid_hid_devices = hid_device_filter.get_devices() if len(valid_hid_devices) is 0: @@ -31,16 +39,12 @@ def get_hid_device_handle(VID, PID): def send_led_pattern(device, led1, led2, led3, led4): - # Length of the report: one byte for the report ID, remainder is the - # payload length as set in the demo - generic_report_size = 1 + 8 - # Report data for the demo is the report ID (always zero) followed by the # LED on/off data report_data = [0, led1, led2, led3, led4] # Zero-extend the array to the length the report should be - report_data.extend([0] * (generic_report_size - len(report_data))) + report_data.extend([0] * (report_length - len(report_data))) # Send the generated report to the device device.send_output_report(report_data) @@ -53,7 +57,7 @@ def received_led_pattern(report_data): def main(): - hid_device = get_hid_device_handle(VID=0x03EB, PID=0x204F) + hid_device = get_hid_device_handle() if hid_device is None: print("No valid HID device found.") |