Commit Graph

340 Commits

Author SHA1 Message Date
Alan Ott a0e77a9627 Added some info to the comments. 2011-09-13 02:19:46 +08:00
Ludovic Rousseau 62cd9d2999 Add hid_init() and hid_exit()
The really missing function was hid_exit() to free ressources allocated
by the HIDAPI and libusb libraries.
2011-09-13 02:19:46 +08:00
Alan Ott fe4f75b0ff Updated README.txt, removed testgui/README.txt
README.txt is now current and contains the info which was in
testgui/README.txt. testgui/README.txt has been removed as obsolete.
2011-09-13 02:19:46 +08:00
Alan Ott be33ec11a3 Call hid_close() at the end of testgui.cpp. 2011-09-13 02:19:46 +08:00
Alan Ott e85acbed71 Add hid_init() and hid_exit to Windows. 2011-09-12 14:09:03 -04:00
Alan Ott a6a9484649 Add empty hid_init() and hid_exit to linux/hid.c 2011-09-10 17:51:11 -04:00
Alan Ott 29d168c2fa Added some info to the comments. 2011-09-10 17:51:11 -04:00
Ludovic Rousseau bf6c3a2930 Add hid_init() and hid_exit()
The really missing function was hid_exit() to free ressources allocated
by the HIDAPI and libusb libraries.
2011-09-10 17:51:11 -04:00
Alan Ott 35dfe2a012 Updated README.txt, removed testgui/README.txt
README.txt is now current and contains the info which was in
testgui/README.txt. testgui/README.txt has been removed as obsolete.
2011-09-10 17:51:10 -04:00
Alan Ott 6bc4484358 Call hid_close() at the end of testgui.cpp. 2011-09-10 17:51:10 -04:00
Alan Ott c41e806042 Add empty hid_init() and hid_exit to linux/hid.c 2011-09-10 17:47:08 -04:00
Alan Ott 27a0ad59e9 Added some info to the comments. 2011-09-10 17:40:31 -04:00
Ludovic Rousseau 529fc51487 Add hid_init() and hid_exit()
The really missing function was hid_exit() to free ressources allocated
by the HIDAPI and libusb libraries.
2011-09-10 17:33:35 -04:00
Alan Ott a8768da46f Updated README.txt, removed testgui/README.txt
README.txt is now current and contains the info which was in
testgui/README.txt. testgui/README.txt has been removed as obsolete.
2011-09-10 17:33:35 -04:00
Alan Ott 3f369eb81f Call hid_close() at the end of testgui.cpp. 2011-09-10 17:33:35 -04:00
Alan Ott 169bc1b8d9 Change the WinIoCTL.h include in windows/hid.cpp to lower case winioctl.h
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>
2011-09-10 16:13:01 -04:00
Ryan Pavlik 2089519798 Add NTSTATUS typedef if needed 2011-09-10 16:06:42 -04:00
Alan Ott c491f95935 Make windows/test.cpp compile in either C or C++. 2011-09-10 16:01:48 -04:00
Alan Ott 3fdfa78563 Support cancellation in hid_read_timeout().
hid_read_timeout() will now properly free the mutex in the case when
pthread_cancel() is called on a thread waiting in hid_read_timeout().
2011-09-07 16:02:09 -04:00
Alan Ott 193d92ff2d Linux/libusb: Make the read thread fully blocking and signal on shutdown.
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>
2011-09-03 14:47:36 -04:00
Alan Ott c7f35c3a46 Try opening with sharing mode enabled on Windows if normal open fails.
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.
2011-08-31 12:39:02 -04:00
Ryan Pavlik 36c309f521 Parse the interface number out of the path on Windows where possible.
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.
2011-08-30 16:55:59 -04:00
Alan Ott abd82e6037 Fix memory leaks in linux/hidraw implementation.
Zbigniew Czapiga noticed that some of the udev objects in linux/hid.c weren't
being freed properly.
2011-08-29 11:20:09 -04:00
Paul Menzel 75bfadb04e linux/Makefile: Add spaces and lines for better readability 2011-08-26 18:08:45 -04:00
Paul Menzel 9b31061613 linux/Makefile: Add support for cross compilation
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.
2011-08-26 18:08:45 -04:00
Paul Menzel 359138c8b6 linux/Makefile: Add $(LDFLAGS) to the linker calls
Some cross compiling frame works like OpenEmbedded [1] pass this variable along.

[1] http://www.openembedded.org/
2011-08-26 18:08:45 -04:00
Paul Menzel ab3ba2e2a6 linux/Makefile: Do not override predefined CC or CXX
This is especially important for cross compilation.
2011-08-26 18:08:45 -04:00
Paul Menzel ceb858109a linux/Makefile: Use $(CXX) instead of g++ 2011-08-26 18:08:45 -04:00
Alan Ott 8a5d92ef0b Merge branch 'master' of github.com:signal11/hidapi 2011-08-08 21:43:38 -04:00
signal11 4f284dc2ec Check for NULL device on enumeration on Mac.
On Mac, hid_enumerate can crash if the device is unplugged during enumeration.

From: Richard Bateman (Taxilian) <taxilian@gmail.com>
2011-08-08 21:42:04 -04:00
signal11 0351bb1abb Merge pull request #10 from taxilian/master
Check for NULL device on enumeration on Mac.

On Mac, hid_enumerate can crash if the device is unplugged during enumeration.
2011-08-08 18:37:38 -07:00
Alan Ott 0bef94e27b Merge branch 'master' of github.com:signal11/hidapi 2011-08-08 21:33:34 -04:00
Camille Moncelier 03c407ee89 Fixed a leak where hid_open weren't freeing a device_path 2011-08-08 21:32:54 -04:00
signal11 30ef96513d Merge pull request #12 from pix/fixes/fix-hid_open-leak
Fixed a memory leak in hid_open_path()

On some failures, dev_path would not get freed.
2011-08-08 18:30:19 -07:00
Alan Ott 8066251aa8 Add ioctl definitions
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.
2011-08-08 21:16:09 -04:00
Alan Ott 781efae694 hid_read_timeout() (Mac)
Add hid_read_timeout() to mac.
2011-08-08 21:01:45 -04:00
Alan Ott e62dba691d hid_read_timeout() (Linux and Windows).
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>
2011-08-08 21:01:37 -04:00
Alan Ott 7e93a4e068 Logic error fix.
Fixed Logic error from the last commit where the wrong data was checked.
2011-07-25 23:42:05 -04:00
Alan Ott 9448fd8fcb Re-design of hid_read().
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.
2011-07-25 17:53:12 -04:00
Camille Moncelier 110de52c40 Fixed a leak where hid_open weren't freeing a device_path 2011-07-19 11:08:48 +02:00
Richard Bateman d94f682c70 Fixed possible mac when unplugging a device during enumeration 2011-06-24 15:21:40 -06:00
Alan Ott 687a8385a1 Fix memory leak on Windows.
The EVENT object in hid_read() was not getting closed when in blocking mode. Fix from John Hu.
2011-06-19 22:11:09 -04:00
Alan Ott 6ad666c5b5 Updated Binary. hidapi-0.6.0 2011-04-08 20:05:11 -04:00
Alan Ott d7f5f2cca5 Binary on Mac OS X 2011-04-08 19:39:54 -04:00
Alan Ott 3f341d2468 Merge branch 'master' of github.com:signal11/hidapi 2011-04-08 19:35:31 -04:00
Alan Ott f61cea6e69 Makefiles for MinGW 2011-04-08 18:48:12 -04:00
Alan Ott c54aba0897 Merge branch 'master' of github.com:signal11/hidapi 2011-02-09 08:43:02 -05:00
Alan Ott 0123bb91b7 Merge branch 'master' of github.com:signal11/hidapi 2011-02-09 08:37:34 -05:00
Alan Ott 265cefb1d3 Print error when hid_read() fails. 2011-02-09 08:37:11 -05:00
Ludovic Rousseau f808275822 Detach from the kernel only if needed
We first check that the HID device is managed by the kernel before
calling libusb_detach_kernel_driver(). This will avoid side effects of
libusb_detach_kernel_driver() like also doing a
libusb_release_interface()

Ludovic's original patch modified by Alan Ott <alan@signal11.us>
2011-02-08 09:38:46 -05:00