Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
- `hid='hid'`: use hidapi (backend depends on hidapi build options)
- `hid='hidraw'`: specifically try to use hidraw (Linux; depends on
hidapi build options)
"""
if not hid:
if sys.platform.startswith('linux'):
hid = 'hidraw'
elif sys.platform == 'darwin':
hid = 'hid'
else:
hid = 'usb'
api = globals()[hid]
if hid.startswith('hid'):
handles = HidapiDevice.enumerate(api, vendor, product)
else:
handles = PyUsbHid.enumerate(vendor, product)
drivers = sorted(find_all_subclasses(UsbHidDriver), key=lambda x: x.__name__)
LOGGER.debug('searching %s (api=%s, drivers=[%s])', self.__class__.__name__, api.__name__,
', '.join(map(lambda x: x.__name__, drivers)))
for handle in handles:
if bus and handle.bus != bus:
continue
if address and handle.address != address:
continue
if usb_port and handle.port != usb_port:
continue
LOGGER.debug('probing drivers for device %s:%s', hex(handle.vendor_id),
hex(handle.product_id))
for drv in drivers: