Skip to content

Commit

Permalink
hidapi: skip unsupported devices and handle exception on open
Browse files Browse the repository at this point in the history
  • Loading branch information
vulpes2 authored and pfps committed Jan 2, 2025
1 parent 73ad98d commit 41e6526
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/hidapi/hidapi_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 41e6526

Please sign in to comment.