How to use the hidapi.enumerate function in hidapi

To help you get started, we’ve selected a few hidapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pwr-Solaar / Solaar / lib / hidapi / hidconsole.py View on Github external
def _open(args):
	device = args.device
	if args.hidpp and not device:
		for d in _hid.enumerate(vendor_id=0x046d):
			if d.driver == 'logitech-djreceiver':
				device = d.path
				break
		if not device:
			sys.exit("!! No HID++ receiver found.")
	if not device:
		sys.exit("!! Device path required.")

	print (".. Opening device", device)
	handle = _hid.open_path(device)
	if not handle:
		sys.exit("!! Failed to open %s, aborting." % device)

	print (".. Opened handle %r, vendor %r product %r serial %r." % (
					handle,
					_hid.get_manufacturer(handle),
github lonetech / LookingGlass / lgeeprom.py View on Github external
page = len(json)//64
        l = min(64, jsonlen-64*page)
        json[64*page:] = rp(dev, page, l)
        #print json
    return json[4:]


def read_eeprom(devinfo):
    dev = hidapi.Device(devinfo)
    cfg = json.loads(loadconfig(dev).decode('ascii'))
    pprint(cfg)
    # TODO: Use calibration data. Sample code in lgdisplaytest.py
    return (dev, cfg)


for dev in hidapi.enumerate(vendor_id=0x04d8, product_id=0xef7e):
    if dev.product_string == u'HoloPlay':
        hiddev, cfg = read_eeprom(dev)
        while True:
            # Keep reading the button bitmask
            r = hiddev.read(1)
            if r:
                byte = r[0]
                # Python 2 compatibility
                if isinstance(byte, str):
                    byte = ord(byte)
                print('{:04b}'.format(byte))
github cyanogen / uchroma / uchroma / server / device_manager.py View on Github external
Iterates over all connected HID devices with RAZER_VENDOR_ID
        and checks the product ID against the Hardware descriptor.

        Interface endpoint restrictions are currently hard-coded. In
        the future this should be done by checking the HID report
        descriptor of the endpoint, however this functionality in
        HIDAPI is broken (report_descriptor returns garbage) on
        Linux in the current release.

        Discovery is automatically performed when the object is
        constructed, so this should only need to be called if the
        list of devices changes (monitoring for changes is beyond
        the scope of this API).
        """
        devinfos = sorted(list(hidapi.enumerate(vendor_id=RAZER_VENDOR_ID)), key=lambda x: x.path)

        for devinfo in devinfos:
            parent = self._get_parent(devinfo.product_id)
            if parent is None:
                continue

            if self._key_for_path(parent.sys_path) is not None:
                continue

            hardware = Hardware.get_device(devinfo.product_id)
            if hardware is None:
                continue

            if hardware.type == Hardware.Type.HEADSET:
                if devinfo.interface_number != 3:
                    continue
github pwr-Solaar / Solaar / lib / logitech_receiver / base.py View on Github external
def receivers():
	"""List all the Linux devices exposed by the UR attached to the machine."""
	for receiver_usb_id in _RECEIVER_USB_IDS:
		for d in _hid.enumerate(*receiver_usb_id):
			yield d