Commit Graph

267 Commits

Author SHA1 Message Date
Alan Ott edf1183114 cleanup previous commit 2012-01-26 11:12:22 +08:00
Alan Ott fd64a9f36b Windows: Don't let device disappear from hid_enumerate() when open
Mess with the open flags hoping that two things can be achieved:
1. Devices can still be opened in exclusive mode,
2. Devices which must be opened in shared mode can still be opened.
3. Opened devices (even with exclusive opens) still show in
hid_enumerate()
2012-01-25 11:27:59 +08:00
Vitali Lovich c26a0c13f2 Don't copy too many bytes from hid_read() in Windows.
Make sure that too many bytes aren't copied to the user if they pass in a
short buffer to hid_read_*().

From: Vitali Lovich <vlovich@gmail.com>
2011-12-31 03:00:01 +08:00
Vitali Lovich ee4ecc02ae Fix output report length bug
On Windows, data shorter than the output report length must be padded.
This is because in the case of multiple reports, Windows expects the number
of bytes which are in the _longest_ report to be given to WriteFile() even
if the user is sending a report which has fewer bytes.

This allocates a temporary buffer in the case that the user passes in too
few bytes.

From: Vitali Lovich <vlovich@gmail.com>
Modified-by: Alan Ott <alan@signal11.us>
2011-12-31 02:59:43 +08:00
Alan Ott e44064cf6d Added comments to udev/99-hid.rules
Comment includes info from Alan Stern regarding older kernels.
2011-10-26 17:39:00 -04:00
Alan Ott edf1899837 Updated Mac binary hidapi-0.7.0 2011-10-25 20:58:17 -04:00
Alan Ott 81dd9bf36a Added sample Udev files for Linux systems. 2011-10-25 12:56:08 -04:00
Alan Ott 0c7d531a4a Linux/libusb: include wchar.h and define _GNU_SOURCE.
This needed for older systems (pre Glibc 2.10).

This patch is from Brendan Shanks (github user mrpippy).
2011-10-20 17:28:27 -04:00
Alan Ott 7a8194b03b Disconnection fixes on Mac. 2011-10-04 17:03:50 -04:00
Alan Ott be40902624 Fix for hid_read*() hanging after device disconenct on Mac.
Send a pthread_cond_broadcast() when a device gets disconnected and
wake up any waiting threads.
2011-10-04 15:54:13 -04:00
Alan Ott 51c18081bf Switch mac/hid.c to use threads.
The previous mac/hid.c implementation was kind of problematic. It worked
fine on 10.5, but on 10.7 I have gotten reports of really weird stuff
happening, such as the report callback being called with invalid context
data.

The problem was, the callback's don't get removed from the callback list
when you call IOHIDDeviceClose() in 10.7 like they used to.  This means that
the report callback must be unregistered at hid_close() time.  Further the
unregister will not work unless you pass _exactly_ the same parameters into
IOHIDDeviceRegisterInputReportCallback() that were passed in the first time
(with the exception of the function being NULL).  Thanks Apple for your
stellar documentation and commitment to backwards compatibility.

Further, with the previous implementation, the OS only seemed to buffer
up 4 reports in between calls to CFRunLoopRun*(), causing the potential
for reports to get lost. The new method, being on a separate thread,
will now buffer up to a configurable 30 reports.
2011-10-04 11:04:27 -04:00
Alan Ott 4419c3bdf4 Change windows/hid.cpp to windows/hid.c
The changes to make it compile with just C (not C++) are already in.
2011-09-22 18:59:33 -04:00
Alan Ott 6a44b8772c Return 0 on success to lookup_functions (Windows)
There was no return value before. I guess I missed the warning.
2011-09-22 18:47:26 -04:00
Alan Ott db5cb875d3 Merge branch 'master' of github.com:signal11/hidapi 2011-09-21 17:27:54 -04:00
Alan Ott 2a599c2387 Fixed simple logic error.
Emailed to me by Frode Austvik <edorfaus@xepher.net>
2011-09-15 14:12:22 -04:00
Frode Austvik 686acc0507 Implemented the USB interface number for Linux/hidraw implementation.
Initial code by Frode Austvik <edorfaus@xepher.net>
Some modification and documentation by Alan Ott <alan@signal11.us>
2011-09-15 09:15:46 -04:00
Alan Ott b521a4878c Merge branch 'master' of github.com:signal11/hidapi 2011-09-13 09:33:38 -04:00
Alan Ott 3001983083 Update of README.txt. 2011-09-13 11:33:05 +08:00
Alan Ott e02edb2909 Fixed the formatting of README.txt 2011-09-13 11:06:04 +08:00
Alan Ott bab22b7ac1 Convert to Cocoa for event handling on the Test GUI on Mac
Carbon is no good on 10.5 and later on 64-bit. Github user
dportabella found a workaround in Cocoa[1], and I added code
to make it handle the events from the dock, like the carbon
version did.

[1] https://github.com/signal11/hidapi/issues/14
2011-09-13 10:48:39 +08:00
Alan Ott 15c81e080e Merge branch 'master' of github.com:signal11/hidapi
Conflicts:
	hidtest/hidtest.cpp
2011-09-12 15:06:33 -04:00
Alan Ott 1cebcb9df9 Merge branch 'master' of github.com:signal11/hidapi
Conflicts:
	hidtest/hidtest.cpp
2011-09-12 15:01:07 -04:00
Alan Ott 9d50cf35d0 Add hid_close() and hid_exit() to test gui at exit time. 2011-09-13 02:42:16 +08:00
Alan Ott 6a8ed4797d Add hid_exit() to example program. 2011-09-13 02:39:08 +08:00
Alan Ott 0075338395 Add hid_init() and hid_exit() to Mac. 2011-09-13 02:37:13 +08:00
Alan Ott 2b7d08f6c6 Add hid_init() and hid_exit to Windows. 2011-09-13 02:19:47 +08:00
Alan Ott 816deccbd4 Add empty hid_init() and hid_exit to linux/hid.c 2011-09-13 02:19:47 +08:00
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