Skip to content

Instantly share code, notes, and snippets.

@AstraLuma
Last active April 10, 2016 01:35
Show Gist options
  • Select an option

  • Save AstraLuma/d5cea052a0b33e423b312ddbd1c00441 to your computer and use it in GitHub Desktop.

Select an option

Save AstraLuma/d5cea052a0b33e423b312ddbd1c00441 to your computer and use it in GitHub Desktop.
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