mirror of
https://github.com/brmlab/edubrm.git
synced 2025-06-08 21:03:59 +02:00
28 lines
932 B
Python
28 lines
932 B
Python
import usb
|
|
|
|
class Device:
|
|
|
|
VENDORID = 0x1fc9
|
|
PRODUCTID = 0x0003
|
|
INSIZE = 64
|
|
OUTSIZE = 2
|
|
|
|
def __init__(self):
|
|
usbdev = usb.core.find(idVendor = self.VENDORID, idProduct = self.PRODUCTID)
|
|
if usbdev == None:
|
|
raise Exception('EduBRM device not found')
|
|
usbdev.set_configuration()
|
|
self.epo = usb.util.find_descriptor(usbdev.get_interface_altsetting(),
|
|
custom_match = lambda e: \
|
|
usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_OUT)
|
|
self.epi = usb.util.find_descriptor(usbdev.get_interface_altsetting(),
|
|
custom_match = lambda e: \
|
|
usb.util.endpoint_direction(e.bEndpointAddress) == usb.util.ENDPOINT_IN)
|
|
|
|
# TODO: PWM
|
|
# TODO: SPI
|
|
# TODO: SET/CLEAR PINS
|
|
|
|
def state(self):
|
|
# TODO: format?
|
|
return self.epi.read(self.INSIZE)
|