Пример #1
0
    def _on_connect(self):
        # Detect what version of pyusb we are using
        pyusb = self._get_usb_lib_version()

        self.callback = None

        reset = self.conf_client.get_bool("/apps/gnome15/%s/reset_usb" %
                                          self.device.uid)
        timeout = 10000
        reset_wait = 0
        e = self.conf_client.get("/apps/gnome15/%s/timeout" % self.device.uid)
        if e:
            timeout = e.get_int()
        e = self.conf_client.get("/apps/gnome15/%s/reset_wait" %
                                 self.device.uid)
        if e:
            reset_wait = e.get_int()
        if reset and pyusb == 1:
            logger.warning(
                "Using pyusb 1.0. Resetting device causes crash in this version, no reset will be done"
            )
            reset = False

        try:
            self.lg19 = G19(reset, False, timeout, reset_wait)
            self.connected = True
        except usb.USBError as e:
            logger.error("Failed to connect.", exc_info=e)
            raise g15exceptions.NotConnectedException()

        # Start listening for keys
        self.lg19.add_input_processor(self)

        for control in self.get_controls():
            self._do_update_control(control)
Пример #2
0
    def _on_connect(self):
        self.thread = None
        self.callback = None
        self.notify_handles = []

        # Create an empty string buffer for use with monochrome LCD
        self.empty_buf = ""
        for _ in range(0, 861):
            self.empty_buf += chr(0)

        # TODO Enable UINPUT if multimedia key support is required?
        self.timeout = 10000
        e = self.conf_client.get("/apps/gnome15/%s/timeout" % self.device.uid)
        if e:
            self.timeout = e.get_int()

        logger.info("Initialising pylibg15, looking for %s:%s",
                    hex(self.device.controls_usb_id[0]),
                    hex(self.device.controls_usb_id[1]))
        if DEBUG_LIBG15 or (logger.level < logging.WARN
                            and logger.level != logging.NOTSET):
            pylibg15.set_debug(pylibg15.G15_LOG_INFO)
        err = pylibg15.init(False, self.device.controls_usb_id[0],
                            self.device.controls_usb_id[1])
        if err != pylibg15.G15_NO_ERROR:
            raise g15exceptions.NotConnectedException(
                "libg15 returned error %d " % err)
        logger.info("Initialised pylibg15")
        self.connected = True

        for control in self.get_controls():
            self._do_update_control(control)

        self.notify_handles.append(
            self.conf_client.notify_add(
                "/apps/gnome15/%s/joymode" % self.device.uid,
                self._config_changed, None))
        self.notify_handles.append(
            self.conf_client.notify_add(
                "/apps/gnome15/%s/timeout" % self.device.uid,
                self._config_changed, None))
        self.notify_handles.append(
            self.conf_client.notify_add(
                "/apps/gnome15/%s/digital_offset" % self.device.uid,
                self._config_changed, None))
        self.notify_handles.append(
            self.conf_client.notify_add(
                "/apps/gnome15/%s/analogue_offset" % self.device.uid,
                self._config_changed, None))

        self._load_configuration()