This is necessary for cross-compile on Linux. While WinIoCTL.h is the
actual name of the file on Windows, it is apparently not the case on
the Linux cross-compile tools.
This patch is from Ryan Pavlik <abiryan@ryand.net>
Changed to use libusb_handle_events() instead of
libusb_handle_events_timeout() on the read thread. This increases
performance because the read thread now doesn't get woken up for no
reason.
Also, when the read thread exits, signal any waiting threads (which are
waiting in hid_read_timeout() so that they don't block forever if another
thread calls hid_close() or if the device becomes disconnected.
This was all kicked off by some suggestions by Hans Hübner
<hans.huebner@gmail.com>
Multiple users have reported the need to pass
SHARE_MODE_READ|SHARE_MODE_WRITE to CreateFileA(). It seems that some
devices will not open at all if sharing is not requested. This commit
makes it so that CreateFileA() will be tried twice, the first time with
sharing mode OFF (passing 0x0 to the ShareMode parameter of CreateFileA()),
and if that fails, it will try to open the device with share mode ON
(passing the above SHARE_MODE_ flags to the ShareMode parameter of
CreateFileA()). This will have the following effects:
For normal devices:
Devices will open as normal. Only one instance can be opened at a time.
For devices which require share mode to be on:
Devices will now open (they would not open at all before). Multiple
instances can be opened. This is less than desirable, but the
alternative is that these devices don't open at all.
Although the Windows API doesn't provide direct access to interface number,
on child devices representing the interfaces of a composite device, it is
parsable from the device path. An excerpt of a path for interface 1 of a
Razer Hydra device is as follows:
\?\hid#vid_1532&pid_0300&mi_01
See table 4 and related text here:
http://msdn.microsoft.com/en-us/windows/hardware/gg487473
This patch, if a path is available, and further, if &mi_ is found, parses
what it can for a hex value into the interface_number field. If there is
any problem, the invalid value (-1) is used instead.
Patch from Ryan Pavlik <abiryan@ryand.net> with modifications by Alan Ott.
0. VDR`s `Makefile` was taken as a template [1].
1. Separate variables for flags for `CC` and `CXX` were introduced. `-c` is now passed explicitly. Further flags for `CXX` could be added like in VDR’s `Makefile`.
2. Separate variable `INCLUDES` defined which is only used for the libraries(?).
[1] http://git.gekrumbel.de/vdr.git?p=vdr.git;a=blob;f=Makefile;hb=bd61fee1e9328aec470c319494cccb90e53302c2
--
Please note that this is not build tested.
Added the HIDIOCSFEATURE and HIDIOCGFEATURE ioctl macros to hid.c so that it
will compile with older kernel headers. This of course doesn't make it _run_
with older kernels. Some distros ship older kernel headers than the running
kernel.
hid_read_timeout() will execute a blocking read up until a timeout has been
reached or data has been received.
This patch implements it on all platforms and comes from Urs Fleisch.
Commit log message by Alan Ott.
Signed-off-by: Urs Fleisch <urs.fleisch@gmail.com>
Tested-by: Alan Ott <alan@signal11.us>
This fixes the performance issue caused by calling CancelIo() when no data arrives in asynchronous (non-blocking) mode. Reported by Bill Good.
This new design also fixes the race condition causing lost packets that can happen if data comes between the time when the Event was checked (WaitForSingleObject()) and the CancelIo() call. Reported by Hans Van Leemputten.