diff options
author | Callum Oakley <callum@pusher.com> | 2017-08-19 10:34:45 +0100 |
---|---|---|
committer | Callum Oakley <callum@pusher.com> | 2017-08-19 10:34:45 +0100 |
commit | a6845036e25c4f4d936dcd12cd0ddedd2894b30e (patch) | |
tree | b23b4e8d9d757aa3c0d42be561572533ae0d126c /lib/lufa/Demos/Device/LowLevel/BulkVendor/HostTestApp/test_bulk_vendor.py | |
parent | 84a8aabe5bf8807595f98de44d18f6a31b892edf (diff) | |
parent | 7277f09bbadcce120f819132dec8ff7172caacc4 (diff) | |
download | firmware-a6845036e25c4f4d936dcd12cd0ddedd2894b30e.tar.gz firmware-a6845036e25c4f4d936dcd12cd0ddedd2894b30e.tar.bz2 firmware-a6845036e25c4f4d936dcd12cd0ddedd2894b30e.zip |
Merge branch 'master' of https://github.com/qmk/qmk_firmware
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() |