macOS: handle `HIDError` in `hidapi.hidapi_impl._match()` (#2804)
* Fix: handle `HIDError` in `hidapi.hidapi_impl._match()` The `open_path()` function may raise `HIDError` but `_match()`, its caller, does not handle it, unlike other cases after opening the path. This affects to the device enumeration process in `hidapi.enumerate()`, causing some devices to be randomly undiscovered. * hidapi: revert to independent checking of long and short HID++ features with an extensible refactor * Refactor: too long line
This commit is contained in:
parent
cefc502db9
commit
df2df301e2
|
@ -255,20 +255,30 @@ def _match(
|
|||
device["hidpp_short"] = False
|
||||
device["hidpp_long"] = False
|
||||
device_handle = None
|
||||
|
||||
def check_hidpp_short():
|
||||
report = _get_input_report(device_handle, 0x10, 32)
|
||||
if len(report) == 1 + 6 and report[0] == 0x10:
|
||||
device["hidpp_short"] = True
|
||||
|
||||
def check_hidpp_long():
|
||||
report = _get_input_report(device_handle, 0x11, 32)
|
||||
if len(report) == 1 + 19 and report[0] == 0x11:
|
||||
device["hidpp_long"] = True
|
||||
|
||||
try:
|
||||
device_handle = open_path(device["path"])
|
||||
try:
|
||||
report = _get_input_report(device_handle, 0x10, 32)
|
||||
if len(report) == 1 + 6 and report[0] == 0x10:
|
||||
device["hidpp_short"] = True
|
||||
except HIDError as e:
|
||||
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
|
||||
try:
|
||||
report = _get_input_report(device_handle, 0x11, 32)
|
||||
if len(report) == 1 + 19 and report[0] == 0x11:
|
||||
device["hidpp_long"] = True
|
||||
except HIDError as e:
|
||||
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
|
||||
|
||||
for check_func in (check_hidpp_short, check_hidpp_long):
|
||||
try:
|
||||
check_func()
|
||||
except HIDError as e:
|
||||
logger.info(
|
||||
f"Error while {check_func.__name__}"
|
||||
f"on device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}"
|
||||
)
|
||||
except HIDError as e:
|
||||
logger.info(f"Error opening device {device['path']} ({bus_id}/{vid:04X}/{pid:04X}) for hidpp check: {e}")
|
||||
finally:
|
||||
if device_handle:
|
||||
close(device_handle)
|
||||
|
|
Loading…
Reference in New Issue