[libhid-discuss] Correct Library?

Charles Lepple clepple at ghz.cc
Fri May 23 14:52:01 UTC 2008


On May 23, 2008, at 9:34 AM, Adrian Parker wrote:

>>> I'm wondering if libhid is the library for me.  I need to allow the
>>> user to press a button which will be used as a Press to Talk button
>>> in a project I'm working on.  The catch of course is that I don't
>>> know which USB device the user will press the button on (although
>>> I'll most likely limit users to joypads and headsets with buttons).
>>
>> From this description I would suggest that you simply use the kernel
>> input event layer.
>>
>
> That would not be portable though right?  I'm developing this for  
> Windows
> and Linux.

Correct.

I don't believe this is an issue on Windows, but on Linux, you will  
most likely have to adjust permissions on every USB device that you  
want to open - even if you only want to open it to see if it is  
indeed a HID device. The Linux kernel has a usbhid driver that  
identifies USB HID devices on its own, but it has only recently  
become useful for general HID events (beyond just keyboard, mouse and  
joystick) and it does not provide any mappings to the generic USB  
devices that libusb and libhid enumerate.

Ideally this would work like this:

* application asks libhid for a list of HID devices
** libhid asks [ libusb | Windows HID API ] for a list of HID devices

Right now, this is roughly how it works:

* application asks libhid to open a HID device that matches some  
parameters
** libhid asks libusb for a list of USB devices
*** libhid checks each USB device to see if it has permission to open it
**** if not, skip it
**** if so, try to retrieve the HID descriptor

Iterating over the HID elements is not as difficult - it is just a  
limitation in the public libhid API. Feel free to dive under the  
hood. You may have noticed that the libhid architecture is currently  
geared towards polling rather than event-driven reporting, however.

Also, there was some discussion on the libusb-win32 list about making  
libhid compile under Windows. I don't have a working Windows  
development environment where I can test this, but I understand that  
there was a bit of global search-and-replace in libhid to get things  
to compile. I haven't had the time to find the minimal set of changes  
necessary, though.

-- 
Charles Lepple



More information about the libhid-discuss mailing list