receiver: change usb identification of receivers to dictionary to allow adding other fields, add receiver name to dictionary
This commit is contained in:
parent
515f994ab8
commit
907c5ab075
|
@ -78,7 +78,13 @@ def exit():
|
|||
return True
|
||||
|
||||
|
||||
def _match(action, device, vendor_id=None, product_id=None, interface_number=None, hid_driver=None):
|
||||
# The filter is used to determine whether this is a device of interest to Solaar
|
||||
def _match(action, device, filter):
|
||||
vendor_id=filter.get('vendor_id')
|
||||
product_id=filter.get('product_id')
|
||||
interface_number=filter.get('usb_interface')
|
||||
hid_driver=filter.get('hid_driver')
|
||||
|
||||
usb_device = device.find_parent('usb', 'usb_device')
|
||||
# print ("* parent", action, device, "usb:", usb_device)
|
||||
if not usb_device:
|
||||
|
@ -164,7 +170,7 @@ def monitor_glib(callback, *device_filters):
|
|||
# print ("***", action, device)
|
||||
if action == 'add':
|
||||
for filter in filters:
|
||||
d_info = _match(action, device, *filter)
|
||||
d_info = _match(action, device, filter)
|
||||
if d_info:
|
||||
GLib.idle_add(cb, action, d_info)
|
||||
break
|
||||
|
@ -189,7 +195,7 @@ def monitor_glib(callback, *device_filters):
|
|||
m.start()
|
||||
|
||||
|
||||
def enumerate(vendor_id=None, product_id=None, interface_number=None, hid_driver=None):
|
||||
def enumerate(usb_id):
|
||||
"""Enumerate the HID Devices.
|
||||
|
||||
List all the HID devices attached to the system, optionally filtering by
|
||||
|
@ -197,8 +203,9 @@ def enumerate(vendor_id=None, product_id=None, interface_number=None, hid_driver
|
|||
|
||||
:returns: a list of matching ``DeviceInfo`` tuples.
|
||||
"""
|
||||
|
||||
for dev in _Context().list_devices(subsystem='hidraw'):
|
||||
dev_info = _match('add', dev, vendor_id, product_id, interface_number, hid_driver)
|
||||
dev_info = _match('add', dev, usb_id)
|
||||
if dev_info:
|
||||
yield dev_info
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ from .base_usb import ALL as _RECEIVER_USB_IDS
|
|||
def receivers():
|
||||
"""List all the Linux devices exposed by the UR attached to the machine."""
|
||||
for receiver_usb_id in _RECEIVER_USB_IDS:
|
||||
for d in _hid.enumerate(*receiver_usb_id):
|
||||
for d in _hid.enumerate(receiver_usb_id):
|
||||
yield d
|
||||
|
||||
|
||||
|
|
|
@ -26,11 +26,37 @@ from __future__ import absolute_import, division, print_function, unicode_litera
|
|||
_DRIVER = ('hid-generic', 'generic-usb', 'logitech-djreceiver')
|
||||
|
||||
|
||||
# each tuple contains (vendor_id, product_id, usb interface number, hid driver)
|
||||
_unifying_receiver = lambda product_id: (0x046d, product_id, 2, _DRIVER)
|
||||
_nano_receiver = lambda product_id: (0x046d, product_id, 1, _DRIVER)
|
||||
_lenovo_receiver = lambda product_id: (0x17ef, product_id, 1, _DRIVER)
|
||||
_lightspeed_receiver = lambda product_id: (0x046d, product_id, 2, _DRIVER)
|
||||
_unifying_receiver = lambda product_id: {
|
||||
'vendor_id':0x046d,
|
||||
'product_id':product_id,
|
||||
'usb_interface':2,
|
||||
'hid_driver':_DRIVER,
|
||||
'name':'Unifying Receiver'
|
||||
}
|
||||
|
||||
_nano_receiver = lambda product_id: {
|
||||
'vendor_id':0x046d,
|
||||
'product_id':product_id,
|
||||
'usb_interface':1,
|
||||
'hid_driver':_DRIVER,
|
||||
'name':'Nano Receiver'
|
||||
}
|
||||
|
||||
_lenovo_receiver = lambda product_id: {
|
||||
'vendor_id':0x17ef,
|
||||
'product_id':product_id,
|
||||
'usb_interface':1,
|
||||
'hid_driver':_DRIVER,
|
||||
'name':'Nano Receiver'
|
||||
}
|
||||
|
||||
_lightspeed_receiver = lambda product_id: {
|
||||
'vendor_id':0x046d,
|
||||
'product_id':product_id,
|
||||
'usb_interface':2,
|
||||
'hid_driver':_DRIVER,
|
||||
'name':'Lightspeed Receiver'
|
||||
}
|
||||
|
||||
# standard Unifying receivers (marked with the orange Unifying logo)
|
||||
UNIFYING_RECEIVER_C52B = _unifying_receiver(0xc52b)
|
||||
|
|
Loading…
Reference in New Issue