Last active
April 10, 2016 01:35
-
-
Save AstraLuma/d5cea052a0b33e423b312ddbd1c00441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import usb1 # Using with_USBContext branch | |
| import sys | |
| REP1 = bytes([0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08]) | |
| REP2 = bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09]) | |
| HID_REPORT = 9 | |
| CONTROL_REQUEST_TYPE_OUT = usb1.RECIPIENT_INTERFACE | usb1.REQUEST_TYPE_CLASS | |
| TO = 200 # Timeout | |
| def spew_tsv(*fields): | |
| print("\t".join(fields)) | |
| with usb1.USBContext() as context: | |
| handle = context.openByVendorIDAndProductID( | |
| 0x1d34, 0x0020 | |
| # skip_on_error=True, | |
| ) | |
| if handle is None: | |
| # Device not present, or user is not allowed to access device. | |
| sys.exit("No handle") | |
| handle.setAutoDetachKernelDriver(True) | |
| with handle.claimInterface(0): | |
| spew_tsv("squeeze", "twist", "push") | |
| while True: | |
| handle.controlWrite(CONTROL_REQUEST_TYPE_OUT, HID_REPORT, 0x0200, 0x0000, REP1, timeout=TO) | |
| handle.controlWrite(CONTROL_REQUEST_TYPE_OUT, HID_REPORT, 0x0200, 0x0000, REP2, timeout=TO) | |
| data = handle.interruptRead(1, 8, timeout=TO) | |
| spew_tsv(data[0], data[1], data[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment