Created
May 29, 2013 15:15
-
-
Save bwghughes/5671077 to your computer and use it in GitHub Desktop.
pushbutton
This file contains 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
#!/usr/bin/env python | |
import sys, usb.core | |
dev = usb.core.find(idVendor=0x1d34, idProduct=0x0008) | |
if dev is None: | |
sys.exit("No Panic button found in the system"); | |
try: | |
if dev.is_kernel_driver_active(0) is True: | |
dev.detach_kernel_driver(0) | |
except usb.core.USBError as e: | |
sys.exit("Kernel driver won't give up control over device: %s" % str(e)) | |
try: | |
dev.set_configuration() | |
dev.reset() | |
except usb.core.USBError as e: | |
sys.exit("Cannot set configuration the device: %s" % str(e)) | |
endpoint = dev[0][(0,0)][0] | |
while 1: | |
try: | |
data = dev.read(endpoint.bEndpointAddress, endpoint.wMaxPacketSize, | |
timeout=10000) | |
if data is not None and len(data) > 2: | |
if data[0] == 6 and data[2] == 19: | |
# Panic button was pressed! | |
print "OH MY GOD! OH MY GOD! DOUBLE RAINBOW!!!" | |
except usb.core.USBError as e: | |
if e.errno != 110: # 110 is a timeout. | |
sys.exit("Error readin data: %s" % str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment