the Fiddler's picture

How to retrieve HID vendor/product name from id?

Given a HID vendor/product id, does anyone know how to retrieve the relevant names? For instance, 045e:0029 translates to Microsoft IntelliMouse Optical.

My solution involves searching the database on http://www.linux-usb.org/usb-ids.html but I refuse to believe that the operating system doesn't provide a way to do this automatically.

OpenTK needs this functionality to provide human-readable input device names.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
yiannis's picture

Actually, as far as I 'm aware of, every utility that displays device names (e.g. lspci) uses a text file for looking up vendor and product IDs.
All Linux distributions I know of have this file as part of the relevant package (e.g. pciutils).
You can find the file usually as /usr/share/pci.ids (same for usb.ids) or, for debian, in /usr/share/misc/pci.ids.
Some RedHat-based distros that use kudzu also have this file in /usr/share/kudzu/pcitable.

What you could do is embed this file as a resource in OpenTK and look up the information in that. If you can't find a product ID because it's very new, return "Vendor: unknown product" and if you can't even find the vendor, return "Unknown device". Updating this file for every OpenTK release would keep it mostly in-sync except for the newest hardware...

HTH,
Yiannis.

Inertia's picture

Are you sure this list is correct? That list claims my gamepad to be MaxFire Blaze2 (left), but it's actually Ultron Black Fire 2 (right). I admit they're both gamepads, but what I can tell from looking at the design, the ultron pad has 1 additional button, but from a look at the specs they should be somewhat feature identical (same axes, buttons and vibration).
Under the Device Manager, Win 7 calls the ultron gamepad "USB Joystick" though. What happened to the code I sent you that reads name strings from windows registry? epic fail?


the Fiddler's picture
yiannis wrote:

Actually, as far as I 'm aware of, every utility that displays device names (e.g. lspci) uses a text file for looking up vendor and product IDs.

That's my impression, too. I'm quite surprised, however - shouldn't this be handled at the OS level?

I really wish to avoid bundling a huge text file that will affect startup times and increase the dll size (or require a decompressor). Maybe OpenTK should expose the vendor/device ids directly and leave the translation to a higher-level utility. I'll have to think about this.

Inertia wrote:

Are you sure this list is correct? That list claims my gamepad to be MaxFire Blaze2 (left), but it's actually Ultron Black Fire 2 (right). I admit they're both gamepads, but what I can tell from looking at the design, the ultron pad has 1 additional button, but from a look at the specs they should be somewhat feature identical (same axes, buttons and vibration).

The list is maintained by users so it may not be 100% accurate. If you send an email to the users list (sourceforge) they should be able to sort it out. (Edit: the list looks dead, however).

Inertia wrote:

Under the Device Manager, Win 7 calls the ultron gamepad "USB Joystick" though. What happened to the code I sent you that reads name strings from windows registry? epic fail?

Nope, I've borrowed a Mac OS X machine and I'm on a coding spree to clean up that port. It's looking much better now, but I still need to fix the threading model and an ugly GameWindow-related crash (which brings the whole runtime down).

"USB Joystick" is not very informative, though. We don't even need to expose this string, as it's already implied in Joystick.GetState(0), GetState(1) etc.

Inertia's picture
the Fiddler wrote:

"USB Joystick" is not very informative, though. We don't even need to expose this string, as it's already implied in Joystick.GetState(0), GetState(1) etc.

My code was based on the assumption that I bought a 10€ gamepad and got no more than a 10€ gamepad. It neither got a "Certified for use with Windows XXX" sticker on it, nor a WHQL signed driver. Properly supported devices may report more than "USB Joystick", but idk without some device to test that. To me it makes sense that a noname gamepad gets a generic name.

Doing research did not yield any uncomplicated solution, yet. There seems to be a solution to retrieve that information from windows runtime itself by P/Invoke setupapi.dll and hid.dll, get a list of all plugged in USB devices and look for the vendor and product ID. i.e. this link, but there's some more regarding this topic on codeproject.
I don't really like to add 2 dll dependencies to OpenTK just to get a clean joystick name, give me some more time to come up with a better solution. IIRC the dlls are Windows 2000 and up.

Edit: DirectInput8 returns "USB Joystick" as product name, XInput has no concept of names at all. Both results using SlimDX.

Inertia's picture

Any other ideas besides

  • Maintain our own database
  • Read strings from registry
  • P/Invoke setupapi.dll and hid.dll
  • DirectInput8

?

the Fiddler's picture

#2, #3 and #4 would work, but they are not cross-platform (and I haven't been able to find anything similar on other platforms). #1 would also work, but I don't wish to maintain this feature inside OpenTK. It would be nice (hey look, a kitchen sink!) but it's not worth the effort (why does it say Foo Bar when my joystick is Foo Baz?)

How about this?

int GetVendorId();
int GetProductId();

and applications can look those up in the device database if they wish. (The latter part can be abstracted into a simple .cs file and made available as an add-on quite easily).

Inertia's picture

[Maintain database]
I think this would work best paired together with an GL/AL Extension database, essentially a program you run on an arbitrary computer and it collects hardware infos for an online database. I do agree, nice to have but should not be our scope.

[Registry]
I have not tested that code on anything else but Win7 and that one gamepad. It'll certainly take alot of time until maturity. The amount of testing that will be required so it returns solid results will be somehwat similar to creating the beforementioned database solution....

[Dllimport hid.dll]
The solution will only work for USB devices and requires at very least Windows 2000. I believe this to be the worst one.

[DirectInput8]
I kinda like this one best, there's quite alot of racing wheels, flight sticks with pedals etc. out there (those oldschool 15-pin joysticks) besides USB devices. Even xbox gamepads will work, although 2 buttons cannot be used properly and no force feedback. For 10€ you get a similar-looking gamepad that will work properly though.
Still have to assess whether MDX or dllimporting the C++ API is the way to go, but it looks most promising from all options to me.