parent
5edf5e7419
commit
51e44052b0
|
@ -31,6 +31,25 @@ _R = hidpp10_constants.REGISTERS
|
||||||
_IR = hidpp10_constants.INFO_SUBREGISTERS
|
_IR = hidpp10_constants.INFO_SUBREGISTERS
|
||||||
|
|
||||||
|
|
||||||
|
class ReceiverFactory:
|
||||||
|
@staticmethod
|
||||||
|
def create_receiver(device_info, setting_callback=None):
|
||||||
|
"""Opens a Logitech Receiver found attached to the machine, by Linux device path.
|
||||||
|
|
||||||
|
:returns: An open file handle for the found receiver, or ``None``.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
handle = _base.open_path(device_info.path)
|
||||||
|
if handle:
|
||||||
|
return Receiver(handle, device_info.path, device_info.product_id, setting_callback)
|
||||||
|
except OSError as e:
|
||||||
|
logger.exception("open %s", device_info)
|
||||||
|
if e.errno == _errno.EACCES:
|
||||||
|
raise
|
||||||
|
except Exception:
|
||||||
|
logger.exception("open %s", device_info)
|
||||||
|
|
||||||
|
|
||||||
class Receiver:
|
class Receiver:
|
||||||
"""A Unifying Receiver instance.
|
"""A Unifying Receiver instance.
|
||||||
|
|
||||||
|
@ -376,20 +395,3 @@ class Receiver:
|
||||||
__repr__ = __str__
|
__repr__ = __str__
|
||||||
|
|
||||||
__bool__ = __nonzero__ = lambda self: self.handle is not None
|
__bool__ = __nonzero__ = lambda self: self.handle is not None
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def open(self, device_info, setting_callback=None):
|
|
||||||
"""Opens a Logitech Receiver found attached to the machine, by Linux device path.
|
|
||||||
|
|
||||||
:returns: An open file handle for the found receiver, or ``None``.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
handle = _base.open_path(device_info.path)
|
|
||||||
if handle:
|
|
||||||
return Receiver(handle, device_info.path, device_info.product_id, setting_callback)
|
|
||||||
except OSError as e:
|
|
||||||
logger.exception("open %s", device_info)
|
|
||||||
if e.errno == _errno.EACCES:
|
|
||||||
raise
|
|
||||||
except Exception:
|
|
||||||
logger.exception("open %s", device_info)
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ def _receivers(dev_path=None):
|
||||||
if dev_path is not None and dev_path != dev_info.path:
|
if dev_path is not None and dev_path != dev_info.path:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
r = _receiver.Receiver.open(dev_info)
|
r = _receiver.ReceiverFactory.create_receiver(dev_info)
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("[%s] => %s", dev_info.path, r)
|
logger.debug("[%s] => %s", dev_info.path, r)
|
||||||
if r:
|
if r:
|
||||||
|
@ -125,7 +125,11 @@ def _receivers_and_devices(dev_path=None):
|
||||||
if dev_path is not None and dev_path != dev_info.path:
|
if dev_path is not None and dev_path != dev_info.path:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
d = _device.Device.open(dev_info) if dev_info.isDevice else _receiver.Receiver.open(dev_info)
|
if dev_info.isDevice:
|
||||||
|
d = _device.Device.open(dev_info)
|
||||||
|
else:
|
||||||
|
d = _receiver.ReceiverFactory.create_receiver(dev_info)
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("[%s] => %s", dev_info.path, d)
|
logger.debug("[%s] => %s", dev_info.path, d)
|
||||||
if d is not None:
|
if d is not None:
|
||||||
|
|
|
@ -244,7 +244,7 @@ def _start(device_info):
|
||||||
assert _status_callback and _setting_callback
|
assert _status_callback and _setting_callback
|
||||||
isDevice = device_info.isDevice
|
isDevice = device_info.isDevice
|
||||||
if not isDevice:
|
if not isDevice:
|
||||||
receiver = _receiver.Receiver.open(device_info, _setting_callback)
|
receiver = _receiver.ReceiverFactory.create_receiver(device_info, _setting_callback)
|
||||||
else:
|
else:
|
||||||
receiver = _device.Device.open(device_info, _setting_callback)
|
receiver = _device.Device.open(device_info, _setting_callback)
|
||||||
configuration.attach_to(receiver)
|
configuration.attach_to(receiver)
|
||||||
|
|
Loading…
Reference in New Issue