|
|
@ -360,9 +360,8 @@ class DeviceMgr(ThreadJob): |
|
|
|
# A list of clients. The key is the client, the value is |
|
|
|
# a (path, id_) pair. Needs self.lock. |
|
|
|
self.clients = {} # type: Dict[HardwareClientBase, Tuple[Union[str, bytes], str]] |
|
|
|
# What we recognise. Each entry is a (vendor_id, product_id) |
|
|
|
# pair. |
|
|
|
self.recognised_hardware = set() |
|
|
|
# What we recognise. (vendor_id, product_id) -> Plugin |
|
|
|
self._recognised_hardware = {} # type: Dict[Tuple[int, int], HW_PluginBase] |
|
|
|
# Custom enumerate functions for devices we don't know about. |
|
|
|
self._enumerate_func = set() # Needs self.lock. |
|
|
|
# locks: if you need to take multiple ones, acquire them in the order they are defined here! |
|
|
@ -390,9 +389,9 @@ class DeviceMgr(ThreadJob): |
|
|
|
for client in clients: |
|
|
|
client.timeout(cutoff) |
|
|
|
|
|
|
|
def register_devices(self, device_pairs): |
|
|
|
def register_devices(self, device_pairs, *, plugin: 'HW_PluginBase'): |
|
|
|
for pair in device_pairs: |
|
|
|
self.recognised_hardware.add(pair) |
|
|
|
self._recognised_hardware[pair] = plugin |
|
|
|
|
|
|
|
def register_enumerate_func(self, func): |
|
|
|
with self.lock: |
|
|
@ -642,24 +641,10 @@ class DeviceMgr(ThreadJob): |
|
|
|
devices = [] |
|
|
|
for d in hid_list: |
|
|
|
product_key = (d['vendor_id'], d['product_id']) |
|
|
|
if product_key in self.recognised_hardware: |
|
|
|
# Older versions of hid don't provide interface_number |
|
|
|
interface_number = d.get('interface_number', -1) |
|
|
|
usage_page = d['usage_page'] |
|
|
|
id_ = d['serial_number'] |
|
|
|
if len(id_) == 0: |
|
|
|
id_ = str(d['path']) |
|
|
|
id_ += str(interface_number) + str(usage_page) |
|
|
|
# The BitBox02's product_id is not unique per device, thus use the path instead to |
|
|
|
# distinguish devices. |
|
|
|
if d["product_id"] == 0x2403: |
|
|
|
id_ = d['path'] |
|
|
|
devices.append(Device(path=d['path'], |
|
|
|
interface_number=interface_number, |
|
|
|
id_=id_, |
|
|
|
product_key=product_key, |
|
|
|
usage_page=usage_page, |
|
|
|
transport_ui_string='hid')) |
|
|
|
if product_key in self._recognised_hardware: |
|
|
|
plugin = self._recognised_hardware[product_key] |
|
|
|
device = plugin.create_device_from_hid_enumeration(d, product_key=product_key) |
|
|
|
devices.append(device) |
|
|
|
return devices |
|
|
|
|
|
|
|
@with_scan_lock |
|
|
|