From 41e652609b1a86a5173296bc35ef9cf178305772 Mon Sep 17 00:00:00 2001 From: vulpes2 Date: Thu, 2 Jan 2025 13:16:56 +0000 Subject: [PATCH] hidapi: skip unsupported devices and handle exception on open --- lib/hidapi/hidapi_impl.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/hidapi/hidapi_impl.py b/lib/hidapi/hidapi_impl.py index f6fb56b88..044530a20 100644 --- a/lib/hidapi/hidapi_impl.py +++ b/lib/hidapi/hidapi_impl.py @@ -233,6 +233,7 @@ def _match( vid = device["vendor_id"] pid = device["product_id"] + hid_bus_type = device["bus_type"] # Translate hidapi bus_type to the bus_id values Solaar expects if device.get("bus_type") == 0x01: @@ -241,6 +242,14 @@ def _match( bus_id = 0x05 # Bluetooth else: bus_id = None + logger.info(f"Device {device['path']} has an unsupported bus type {hid_bus_type:02X}") + return None + + # Skip unlikely devices with all-zero VID PID or unsupported bus IDs + if vid == 0 and pid == 0: + logger.info(f"Device {device['path']} has all-zero VID and PID") + logger.info(f"Skipping unlikely device {device['path']} ({bus_id}/{vid:04X}/{pid:04X})") + return None # Check for hidpp support device["hidpp_short"] = False @@ -265,7 +274,7 @@ def _match( close(device_handle) logger.info( - "Found device BID %s VID %04X PID %04X HID++ %s %s", + "Found device BID %s VID %04X PID %04X HID++ SHORT %s LONG %s", bus_id, vid, pid, @@ -317,6 +326,8 @@ def _match( ) return d_info + logger.info(f"Finished checking HIDPP support for device {device['path']} ({bus_id}/{vid:04X}/{pid:04X})") + def find_paired_node(receiver_path: str, index: int, timeout: int): """Find the node of a device paired with a receiver"""