Exemplo n.º 1
0
    def __init__(self, device_path, device_number, config):

        self._observer_list = []
        self._effect_sync_propagate_up = False
        self._disable_notifications = False

        self.config = config
        self._parent = None
        self._device_path = device_path
        self._device_number = device_number
        self.serial = self.get_serial()

        self._effect_sync = effect_sync.EffectSync(self, device_number)

        self._is_closed = False

        self.logger = logging.getLogger(
            'razer.device{0}'.format(device_number))
        self.logger.info("Initialising device.%d %s", device_number,
                         self.__class__.__name__)

        # Find event files in /dev/input/by-id/ by matching against regex
        self.event_files = []
        for event_file in os.listdir('/dev/input/by-id/'):
            if self.EVENT_FILE_REGEX is not None and self.EVENT_FILE_REGEX.match(
                    event_file) is not None:
                self.event_files.append(
                    os.path.join('/dev/input/by-id/', event_file))

        object_path = os.path.join(self.OBJECT_PATH, self.serial)
        DBusService.__init__(self, self.BUS_PATH, object_path)

        # Register method to get the devices serial
        self.logger.debug("Adding getSerial method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'getSerial',
                             self.get_serial,
                             out_signature='s')

        # Set up methods to suspend and restore device operation
        self.suspend_args = {}
        self.logger.debug(
            "Adding razer.device.misc.suspendDevice method to DBus")
        self.add_dbus_method('razer.device.misc', 'suspendDevice',
                             self.suspend_device)
        self.logger.debug(
            "Adding razer.device.misc.resumeDevice method to DBus")
        self.add_dbus_method('razer.device.misc', 'resumeDevice',
                             self.resume_device)
        self.logger.debug("Adding razer.device.misc.getVidPid method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'getVidPid',
                             self.get_vid_pid,
                             out_signature='ai')

        # Load additional DBus methods
        self.load_methods()
Exemplo n.º 2
0
    def __init__(self, device_path, device_number, config, testing=False):

        self.logger = logging.getLogger(
            'razer.device{0}'.format(device_number))
        self.logger.info("Initialising device.%d %s", device_number,
                         self.__class__.__name__)

        self._observer_list = []
        self._effect_sync_propagate_up = False
        self._disable_notifications = False

        self.config = config
        self._testing = testing
        self._parent = None
        self._device_path = device_path
        self._device_number = device_number
        self.serial = self.get_serial()

        self._effect_sync = effect_sync.EffectSync(self, device_number)

        self._is_closed = False

        # Find event files in /dev/input/by-id/ by matching against regex
        self.event_files = []

        if self._testing:
            search_dir = os.path.join(device_path, 'input')
        else:
            search_dir = '/dev/input/by-id/'

        if os.path.exists(search_dir):
            for event_file in os.listdir(search_dir):
                if self.EVENT_FILE_REGEX is not None and self.EVENT_FILE_REGEX.match(
                        event_file) is not None:
                    self.event_files.append(
                        os.path.join(search_dir, event_file))

        object_path = os.path.join(self.OBJECT_PATH, self.serial)
        DBusService.__init__(self, self.BUS_PATH, object_path)

        # Register method to get the devices serial
        self.logger.debug("Adding getSerial method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'getSerial',
                             self.get_serial,
                             out_signature='s')

        # Set up methods to suspend and restore device operation
        self.suspend_args = {}
        self.method_args = {}
        self.logger.debug(
            "Adding razer.device.misc.suspendDevice method to DBus")
        self.add_dbus_method('razer.device.misc', 'suspendDevice',
                             self.suspend_device)

        self.logger.debug(
            "Adding razer.device.misc.getDeviceMode method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'getDeviceMode',
                             self.get_device_mode,
                             out_signature='s')
        self.logger.debug(
            "Adding razer.device.misc.setDeviceMode method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'setDeviceMode',
                             self.set_device_mode,
                             in_signature='yy')
        self.logger.debug(
            "Adding razer.device.misc.resumeDevice method to DBus")
        self.add_dbus_method('razer.device.misc', 'resumeDevice',
                             self.resume_device)
        self.logger.debug("Adding razer.device.misc.getVidPid method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'getVidPid',
                             self.get_vid_pid,
                             out_signature='ai')
        self.logger.debug("Adding razer.device.misc.version method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'getDriverVersion',
                             razer_daemon.dbus_services.dbus_methods.version,
                             out_signature='s')
        self.logger.debug(
            "Adding razer.device.misc.hasDedicatedMacroKeys method to DBus")
        self.add_dbus_method('razer.device.misc',
                             'hasDedicatedMacroKeys',
                             self.dedicated_macro_keys,
                             out_signature='b')

        # Load additional DBus methods
        self.load_methods()