Example #1
0
	def start(self):
		self._context = usb1.USBContext()
		if not self._context.hasCapability(usb1.CAP_HAS_HOTPLUG):
			raise NoHotplugSupport('Hotplug support is missing. Please update your libusb version.')
		self._context.open()
		self._context.hotplugRegisterCallback(
			self.on_hotplug_event,
			events=usb1.HOTPLUG_EVENT_DEVICE_ARRIVED | usb1.HOTPLUG_EVENT_DEVICE_LEFT,
		)
		self._context.setPollFDNotifiers(self._register_fd, self._unregister_fd)
		for fd, events in self._context.getPollFDList():
			self._register_fd(fd, events)	
Example #2
0
	def start(self):
		self._ctx = usb1.USBContext()
		
		def fd_cb(*a):
			self._changed += 1
		
		def register_fd(fd, events, *a):
			self.daemon.get_poller().register(fd, events, fd_cb)
		
		def unregister_fd(fd, *a):
			self.daemon.get_poller().unregister(fd)
		
		self._ctx.setPollFDNotifiers(register_fd, unregister_fd)
		for fd, events in self._ctx.getPollFDList():
			register_fd(fd, events)	
		self._started = True
Example #3
0
    def __init__(self, callback):
        """
		Constructor
		
		callback:
			function called on usb message 
			takes (SCController, current_time, ControllerInput) as arguments
		"""
        self._handle = None
        self._cb = callback
        self._cscallback = None  # Controller State Callback
        self._cmsg = []
        self._claimed = []
        self._ctx = usb1.USBContext()
        self._controller_connected = False
        self._idle_timeout = 600
        self._enable_gyros = False

        for i in range(len(PRODUCT_ID)):
            pid = PRODUCT_ID[i]
            endpoint = ENDPOINT[i]
            ccidx = CONTROLIDX[i]

            self._handle = self._ctx.openByVendorIDAndProductID(
                VENDOR_ID,
                pid,
                skip_on_error=True,
            )
            if self._handle is not None:
                break

        if self._handle is None:
            raise ValueError('Controller Device not found')

        self._ccidx = ccidx
        dev = self._handle.getDevice()
        cfg = dev[0]

        for inter in cfg:
            for setting in inter:
                number = setting.getNumber()
                if self._handle.kernelDriverActive(number):
                    self._handle.detachKernelDriver(number)
                if (setting.getClass() == 3 and setting.getSubClass() == 0
                        and setting.getProtocol() == 0):
                    self._handle.claimInterface(number)
                    self._claimed.append(number)

        self._transfer_list = []
        transfer = self._handle.getTransfer()
        transfer.setInterrupt(
            usb1.ENDPOINT_IN | endpoint,
            64,
            callback=self._processReceivedData,
        )
        transfer.submit()
        self._transfer_list.append(transfer)

        self._period = LPERIOD

        if pid == 0x1102:
            self._timer = Timer(LPERIOD, self._callbackTimer)
            self._timer.start()
        else:
            self._timer = None

        self._tup = None
        self._lastusb = time.time()