Discussion:
[libhid-discuss] libhid-discuss Digest, Vol 21, Issue 6
Adrian Parker
2008-05-23 13:34:19 UTC
Permalink
On Fri, May 23, 2008 at 8:03 AM, <
Message: 1
Date: Thu, 22 May 2008 14:39:47 -0400
From: "Adrian Parker" <adrian.l.parker at gmail.com>
Subject: [libhid-discuss] Correct Library?
To: libhid-discuss at lists.alioth.debian.org
<7da71e910805221139r4d09a114yb601784a36a704e at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
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).
libhid seems designed around knowing in advance which particular device you
want to access. I don't see any functions that allow me to iterate through
the list of enumerated HID devices (have I overlooked something?).
I expected to find structures that represent various Report tpes, but I
don't see those either.
Does anyone happen to have example code of monitoring a device category
(say
Joystick), where the exact make/model is not known previous to run time?
I see hid_dump_tree mentioned, but that might write to a file by the looks
of the header?
--
Adrian Parker
------------------------------
Message: 2
Date: Thu, 22 May 2008 22:35:45 +0200
From: Peter Stuge <stuge-libhid at cdy.org>
Subject: Re: [libhid-discuss] Correct Library?
To: libhid-discuss at lists.alioth.debian.org
Message-ID: <20080522203545.25077.qmail at cdy.org>
Content-Type: text/plain; charset=us-ascii
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.


Adrian
Charles Lepple
2008-05-23 14:52:01 UTC
Permalink
Post by Adrian Parker
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
Adrian Parker
2008-05-23 15:36:48 UTC
Permalink
I'm wondering if libhid is the library for me. I need to allow the
Post by Adrian Parker
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
In this case I can run the program setuid root. Perhaps not the best fix,
but I have that freedom.
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.
Robert V Krakora has sent me libhid code that works under Windows.


Adrian
Peter Stuge
2008-05-24 12:19:57 UTC
Permalink
Post by Adrian Parker
Robert V Krakora has sent me libhid code that works under Windows.
Can you make a patch against the current libhid source?


//Peter
Charles Lepple
2008-05-26 23:59:03 UTC
Permalink
Post by Peter Stuge
Post by Adrian Parker
Robert V Krakora has sent me libhid code that works under Windows.
Can you make a patch against the current libhid source?
Because of the global search-and-replace that I mentioned earlier,
it's going to be a huge patch.

What we really need is for someone to try and find the minimal set of
diffs required - and yes, knowing the needed changes will help in the
future when someone gets around to writing a native Win32 HID API
backend.
--
Charles Lepple
Xiaofan Chen
2008-05-24 15:12:36 UTC
Permalink
Post by Charles Lepple
* application asks libhid for a list of HID devices
** libhid asks [ libusb | Windows HID API ] for a list of HID devices
I think this is the ideal way and should be the way forward.
Actually libusb-win32 1.0 will add HID backend and WinUSB
backedn so that it wraps native HID API and WinUSB API
to libusb-win32 API. However it is not working yet and the
svn version has not been updated for quite some time (9 months).
http://libusb-win32.svn.sourceforge.net/viewvc/libusb-win32/trunk/libusb1/
Post by Charles Lepple
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.
Rob Krakora has a version of libhid for Win32 using libusb-win32.
I think it can only serve as a temporary solution. It is much better
to use native HID API under Windows (or Mac OS X) for libhid.

Xiaofan
Loading...