diff options
author | Jack Humbert <jack.humb@gmail.com> | 2017-07-07 21:33:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-07 21:33:29 +0200 |
commit | 9de443cbf10ac41bc15762c9c83f138f51dd3b9a (patch) | |
tree | d8ddcb428e0b7d9773a1e52c42b60bdca2658beb /lib/lufa/Demos/Device/LowLevel/BulkVendor/HostTestApp/test_bulk_vendor.py | |
parent | 88b3d051b21cb1ddacc6353c5d59b19f03f3a242 (diff) | |
parent | 1c26468ad5a0701e244c99cbcbc547c93b75d515 (diff) | |
download | qmk_firmware-9de443cbf10ac41bc15762c9c83f138f51dd3b9a.tar.gz qmk_firmware-9de443cbf10ac41bc15762c9c83f138f51dd3b9a.tar.xz |
Merge pull request #1471 from qmk/lufa_lib
Update LUFA and move it to /lib/lufa
Diffstat (limited to 'lib/lufa/Demos/Device/LowLevel/BulkVendor/HostTestApp/test_bulk_vendor.py')
-rw-r--r-- | lib/lufa/Demos/Device/LowLevel/BulkVendor/HostTestApp/test_bulk_vendor.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/lufa/Demos/Device/LowLevel/BulkVendor/HostTestApp/test_bulk_vendor.py b/lib/lufa/Demos/Device/LowLevel/BulkVendor/HostTestApp/test_bulk_vendor.py new file mode 100644 index 000000000..fff8ecd78 --- /dev/null +++ b/lib/lufa/Demos/Device/LowLevel/BulkVendor/HostTestApp/test_bulk_vendor.py @@ -0,0 +1,67 @@ +""" + LUFA Library + Copyright (C) Dean Camera, 2017. + + dean [at] fourwalledcubicle [dot] com + www.lufa-lib.org +""" + +""" + LUFA Bulk Vendor device demo host test script. This script will send and + receive a continuous stream of packets to/from to the device, to show + bidirectional communications. + + Requires the pyUSB library (http://sourceforge.net/projects/pyusb/). +""" + +import sys +from time import sleep +import usb.core +import usb.util + +# Bulk Vendor HID device VID and PID +device_vid = 0x03EB +device_pid = 0x206C +device_in_ep = 3 +device_out_ep = 4 + + +def get_vendor_device_handle(): + dev_handle = usb.core.find(idVendor=device_vid, idProduct=device_pid) + return dev_handle + + +def write(device, packet): + device.write(usb.util.ENDPOINT_OUT | device_out_ep, packet, 0, 1000) + print("Sent Packet: {0}".format(packet)) + + +def read(device): + packet = device.read(usb.util.ENDPOINT_IN | device_in_ep, 64, 0, 1000) + print("Received Packet: {0}".format(''.join([chr(x) for x in packet]))) + return packet + + +def main(): + vendor_device = get_vendor_device_handle() + + if vendor_device is None: + print("No valid Vendor device found.") + sys.exit(1) + + vendor_device.set_configuration() + + print("Connected to device 0x%04X/0x%04X - %s [%s]" % + (vendor_device.idVendor, vendor_device.idProduct, + usb.util.get_string(vendor_device, 255, vendor_device.iProduct), + usb.util.get_string(vendor_device, 255, vendor_device.iManufacturer))) + + x = 0 + while 1: + x = x + 1 % 255 + write(vendor_device, "TEST PACKET %d" % x) + read(vendor_device) + sleep(1) + +if __name__ == '__main__': + main() |