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