Get vendorId & productId from hid_device or path #431
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi#431
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I maintain a couple of nodejs libraries (such as elgato-stream-deck) which use this library via node-hid.
In those I expose a method which takes in a path to the device and opens it (such as
function openStreamDeck(devicePath: string): StreamDeck), returning a class to interact with the device.But to do this, I need to check the productId of the hid device to determine the model being opened. In this streamdeck library there are 6 models of compatible device, each with a slightly different protocol.
My current method for this is to do a hid_enumerate before opening the device to find the productId, but this is horribly inefficient.
Ideally there would be a method to get the
hid_device_infofor a specific path, or be able to get the productId and vendorId from ahid_deviceI might be able to achieve the same with
hid_get_manufacturer_stringandhid_get_product_string, but I suspect that two of the models will report the same name, even though their protocol is completely different.I can try and implement one of these, but would like to discuss what the api should look like first.
It looks like for windows there is already a
hid_device_infostored insidehid_device.macos has the
create_device_info_with_usagefunction that could be used to create and store ahid_device_info, and at the same time thehid_get_manufacturer_stringand related methods could be updated to copy off that struct like windows is doing.linux looks like it will take a bit of work to refactor parts of
hid_enumerateto be reusable, but it doesnt look like there is anything stopping it from being done. As another bonus,get_device_stringcould be removed.libusb also looks like it will need a bit of refactoring to be compatible.
So as windows already has a
hid_device_infostored insidehid_device, I think it makes sense to replicate this for all backends.Then one of these methods could be added to access some more of the information it stores:
int HID_API_EXPORT HID_API_CALL hid_get_device_ids(hid_device *dev, unsigned short *vendor_id, unsinged short *product_id);struct hid_device_info HID_API_EXPORT HID_API_CALL hid_get_device_info(hid_device *dev);Thanks for the analysis.
I think this would be the way to go - way more flexible in a long term.
That should be almost trivial. libusb has all the API for it.
That I agree. Right now linux/hidraw backend uses
udevto gather all the information about the device, and I believe that long-term that is not a good approach.hidrawis a kernel API, so we better use kernel API to gather the information on the device, i.e.sysfs. The most difficulty is the variety of protocols (USB/Bluetooth/I2C/etc.) that needs to be tested withsysfs, and personally I only have USB HID devices that I can reliebly test.