コード例 #1
0
    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
コード例 #2
0
ファイル: hidwrap.py プロジェクト: rippelchristoph/libhid
    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
コード例 #3
0
    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
コード例 #4
0
ファイル: hidwrap.py プロジェクト: chad3814/libhid
    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
コード例 #5
0
ファイル: hidsensor.py プロジェクト: snim2/python-csp
 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