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 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(): '''Calls hid_init(), and registers an atexit procedure to clean up at termination time.''' import atexit _hid_raise("init", hid.hid_init()) IS_INITIALIZED[0] = True atexit.register(_finalize_hid)
def __init__(self, hidclasses): self._hidtypes = {} for hidclass in hidclasses: print('Searching for {0} sensors...'.format(hidclass.__name__)) self._hidtypes[hidclass] = HIDMatcher(hidclass.VID, hidclass.PID) self._interfaces = {} retval = hid.hid_init() if retval != hid.HID_RET_SUCCESS: raise HIDError(('hid_init', retval)) return
def __init__(self, id=None, errstream=sys.stderr): self._id = None self._error = errstream # Debugging if DEBUG: hid.hid_set_debug(hid.HID_DEBUG_ALL) hid.hid_set_debug_stream(self._error) hid.hid_set_usb_debug(0) # Initialisation if not hid.hid_is_initialised(): # Doesn't seem to work try: # Belt AND braces, Sir? hid.hid_init() except HIDError: pass self._interface = hid.hid_new_HIDInterface() # Ensure we only use one HIDMatcher class per # type of sensor, with some reflection-fu. #if not 'MATCHER' in self.__class__.__dict__: if not hasattr(self.__class__, 'MATCHER'): self.__class__.MATCHER = HIDMatcher(self.__class__.VID, self.__class__.PID) return
def init(): import atexit _hid_raise("init", hid.hid_init()) IS_INITIALIZED[0] = True atexit.register(_finalize_hid)