def start(self): """Starts by default on init, but can be paired with stop()""" if not self._running: ret = hid.hid_init() if ret != hid.HID_RET_SUCCESS: sys.stderr.write("hid_init failed with return code %d.\n" % ret) return self._hid = hid.hid_new_HIDInterface() matcher = hid.HIDInterfaceMatcher() matcher.vendor_id = 0x20ff matcher.product_id = 0x0100 # The following is necessary due to a bug in the firmware. Units # shipped after early February 2010 will likely have the fix and # should successfully open on interface 1. Older units have to # open on interface 1, fail, and then open on interface 0. ret = hid.hid_force_open(self._hid, 1, matcher, 3) if ret != hid.HID_RET_SUCCESS: ret = hid.hid_force_open(self._hid, 0, matcher, 3) if ret != hid.HID_RET_SUCCESS: sys.stderr.write( "hid_force_open failed with return code %d.\n" % ret) return self._running = True
def __init__(self, vendor_id, product_id, interface_number=0, force=True, retries=3): self.is_open = False if not is_initialized(): init() matcher = hid.HIDInterfaceMatcher() matcher.vendor_id = vendor_id matcher.product_id = product_id self.interface = hid.hid_new_HIDInterface() if force: _hid_raise( "force_open", hid.hid_force_open(self.interface, interface_number, matcher, retries)) else: _hid_raise("open", hid.hid_open(self.interface, 0, matcher)) self.is_open = True
def __init__(self, vid, pid, errstream=sys.stderr): self.matcher = hid.HIDInterfaceMatcher() self.matcher.vendor_id = vid self.matcher.product_id = pid return