hidapi: be more permissive when recognizing HID++ report descriptors

This commit is contained in:
Peter F. Patel-Schneider 2022-10-27 11:06:46 -04:00
parent d744a24d5c
commit 925172d030
1 changed files with 5 additions and 7 deletions

View File

@ -107,19 +107,17 @@ def _match(action, device, filterfn):
try: # if report descriptor does not indicate HID++ capabilities then this device is not of interest to Solaar try: # if report descriptor does not indicate HID++ capabilities then this device is not of interest to Solaar
from hid_parser import ReportDescriptor as _ReportDescriptor from hid_parser import ReportDescriptor as _ReportDescriptor
from hid_parser import Usage as _Usage # from hid_parser import Usage as _Usage
hidpp_short = hidpp_long = False hidpp_short = hidpp_long = False
devfile = '/sys' + hid_device.get('DEVPATH') + '/report_descriptor' devfile = '/sys' + hid_device.get('DEVPATH') + '/report_descriptor'
with fileopen(devfile, 'rb') as fd: with fileopen(devfile, 'rb') as fd:
with _warnings.catch_warnings(): with _warnings.catch_warnings():
_warnings.simplefilter('ignore') _warnings.simplefilter('ignore')
rd = _ReportDescriptor(fd.read()) rd = _ReportDescriptor(fd.read())
hidpp_short = 0x10 in rd.input_report_ids and 6 * 8 == int( hidpp_short = 0x10 in rd.input_report_ids and 6 * 8 == int(rd.get_input_report_size(0x10))
rd.get_input_report_size(0x10) # and _Usage(0xFF00, 0x0001) in rd.get_input_items(0x10)[0].usages # be more permissive
) and _Usage(0xFF00, 0x0001) in rd.get_input_items(0x10)[0].usages hidpp_long = 0x11 in rd.input_report_ids and 19 * 8 == int(rd.get_input_report_size(0x11))
hidpp_long = 0x11 in rd.input_report_ids and 19 * 8 == int( # and _Usage(0xFF00, 0x0002) in rd.get_input_items(0x11)[0].usages # be more permissive
rd.get_input_report_size(0x11)
) and _Usage(0xFF00, 0x0002) in rd.get_input_items(0x11)[0].usages
if not hidpp_short and not hidpp_long: if not hidpp_short and not hidpp_long:
return return
except Exception as e: # if can't process report descriptor fall back to old scheme except Exception as e: # if can't process report descriptor fall back to old scheme