Commit Graph

302 Commits

Author SHA1 Message Date
Alan Ott
6d50f8fa0f Add Autotools build system (automake, autconf)
This adds the familiar autotools build system and associated documentation
for Linux, FreeBSD, Mac, MinGW, and Cygwin.  The old Makefiles have been
kept, and where appropriate have been renamed Makefile-manual.

Thanks to Peter Stuge, Ludovic Rousseau, Xiaofan Chen, Alex Dupre, and
Segher Boessenkool for providing testing, review, and suggestions, and to
Ludovic Rousseau for providing patches which contributed to this commit.
2012-07-16 00:43:04 -04:00
Alan Ott
567304bf2d Add a .gitattributes giving autoconf files LF line endings 2012-07-16 00:43:04 -04:00
Alan Ott
4fec187ca2 Add .pc files for pkg-config 2012-07-16 00:43:04 -04:00
Alan Ott
38a7bf75f0 Renamed manual makefiles so they're out of the way of autotools
Files named Makefile which will conflict with autotools have been renamed to
Makefile-manual.
2012-07-16 00:43:04 -04:00
Alan Ott
d370700973 Exclude ax_pthread.m4 from .gitignore 2012-07-16 00:43:04 -04:00
Alan Ott
9fb2477f68 Add ax_pthread.m4 in preparation for autotools build system
from http://www.gnu.org/software/autoconf-archive/ax_pthread.html
2012-07-16 00:43:04 -04:00
Alan Ott
f33cba0492 Exclude pkg.m4 from .gitignore 2012-07-16 00:43:04 -04:00
Alan Ott
d60d5f278b Add pkg.m4 in preparation for autotools
from https://gnunet.org/svn/Extractor/m4/pkg.m4
2012-07-16 00:43:04 -04:00
Alan Ott
b417e9413e Remove MacOS TestGUI Binaries from git 2012-07-16 00:43:04 -04:00
Alan Ott
0a199c36ed Linux: Fix error in Makefile
When the libusb implementation was moved into libusb/, this Makefile didn't
get updated properly.
2012-06-05 16:18:49 -04:00
Sean M. Pappalardo
308ab89a26 Libusb: Prevent bailing out of read_thread() on non-critical errors 2012-05-18 13:12:28 -04:00
Chris Serio
c8e917f018 Windows: Fixed an incorrect return type on HidP_GetCaps()
Addresses an issue with the return type of HidP_GetCaps() which was
returning the wrong status code because of the invalid return type of
BOOLEAN which is a UCHAR. The return code is supposed to be 0x110000
which obviously doesn't fit in a UCHAR so it was being rounded to
0x0. Basically, no return codes were ever making it through that call.
2012-05-17 08:53:30 +08:00
bsupnik
517b3acd71 Mac: Add CFRetain()/CFRelease() pair on the device handle
Adding retain/release to the device since we keep the reference in
our object.
2012-05-17 08:53:29 +08:00
Chris Serio
e4310539ff Windows: Fix compile when using DDK
There are type definitions that allow compilation without requiring the
Windows DDK to be installed for compilation/linking however one of the
types used was wrong and when actually compiled against the DDK, it
would fail.
2012-05-17 08:53:28 +08:00
Alan Ott
bdb87db5b8 Libusb: testgui: Explicitly link to libpthread.
Reported by: Xiaofan Chen <xiaofanc@gmail.com>
2012-05-03 22:25:40 -04:00
Alex Dupre
1fd27eaa25 testgui: Fix signed/unsigned warning 2012-05-02 18:55:37 -04:00
Alex Dupre
498fbb42f9 Libusb: Cleanup
Remove unnecessary initialization in new_hid_device()
Remove unnecessary NULL-termination in usb_get_string()
2012-05-02 18:55:37 -04:00
Alan Ott
74440e2dbb FreeBSD: Add FreeBSD implementation.
This adds a FreeBSD implementation to HIDAPI using the libusb back-end. The
libusb/ folder now contains the libusb implementation and associated
Makefiles for Linux and FreeBSD. All libusb code has been removed from the
linux/ folder, so that the code in libusb/ can be shared by both (and
future) platforms.

This commit renames linux/hid-libusb.c to libusb/hid.c. Make sure to
use git log --follow to see full history of that file.

This code was written by:
 Alex Dupre <ale@FreeBSD.org>
 Alan Ott <alan@signal11.us>
2012-05-02 18:55:28 -04:00
Alan Ott
c30dfd8c97 Linux: add -lrt to link with librt.
This is required for some distributions but not others.
2012-05-02 14:42:26 -04:00
Alan Ott
1bde032170 Linux/libusb: Shutdown thread if it's not possible to submit transfer
This happens if a device gets opened a second time. The call to
libusb_submit_transfer() will fail, indicating that the read thread should
be shut down.
2012-04-23 17:54:58 -04:00
Frode Austvik
992fef24d5 Fixed a typo that made the shared libraries be empty. Added the hidtest-* binaries to the list of files ignored by git. 2012-03-29 18:53:08 -04:00
philip
1186ca26c7 All: Make serial_number parameter to hid_open() const.
This prevents a warning when passing in a literal.
2012-03-28 18:05:49 -04:00
Alan Ott
59b9428199 Linux: Clean up Makefile
Create separate targets for libusb and hidraw implementations.
Build shared libraries in a more standard way.
Add Comments.
2012-03-28 17:58:30 -04:00
Frode Austvik
d0b493183e Linux: Added make targets for building shared libraries. 2012-03-28 17:06:48 -04:00
Nikolaj Løbner Sheller
a22320f76d Mac: Fix return value for string functions
get_serial_number()
	get_manufacturer_string()
	get_product_string()

This is to match the documentation in the header file, returning 0 on
success and -1 on error.
2012-02-28 11:26:28 -05:00
Vadim Zaliva
8717b87398 Linux/hidraw: Fix return value string functions
get_serial_number()
	get_manufacturer_string()
	get_product_string()

This matches the documentation in header file to return 0 on success and -1
on error.
2012-02-28 11:26:22 -05:00
Alan Ott
7f6b496374 Linux: Took out one more setlocale() 2012-02-27 21:13:25 -05:00
Alan Ott
b57e8f6dac Linux: Don't set locale if it's already been set
Adapted from a patch received from Axel Rohde <axel.rohde@gmail.com>
2012-02-27 12:10:29 -05:00
Alan Ott
240bad3b66 Remove unnecessary setlocale() on Mac 2012-02-27 12:05:23 -05:00
Alan Ott
991c48d70b Merge branch 'master' of github.com:signal11/hidapi 2012-01-26 11:21:08 +08:00
Alan Ott
e3ab121099 Windows: Don't let device disappear from hid_enumerate() when open
Change the CreateFileA() flags to support the following:
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()

Thanks to github user vanweric for suggesting these flags and to Brendan
Shanks for discussion and testing.
2012-01-26 11:14:04 +08:00
Mario Kleiner
e8c3e8db61 Use private libusb_context for linux/libusb implementation.
Use a private libusb_context to avoid conflicts between
multiple libusb instances inside a single application
process. Many 3rd party libraries use libusb as backend,
so there is a good chance of collisions if the default NULL
context is used.

Modified by Alan Ott to also remove the initialized
variable since it's no longer needed (since we can use
the context instead), to make the style consistent, and
to remove unnecessary checks for initialized before calling
hid_init().

Signed-off-by: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
Signed-off-by: Alan Ott <alan@signal11.us>
2012-01-12 17:24:04 -05:00
Alan Ott
011208de6a README.txt: Clarification of what the sample program does. 2012-01-12 17:17:44 -05:00
Alan Ott
4a229e26c0 Fix hid_enumerate() crash on Mac OS X
Fix the problem where hid_enumerate() will crash if any of the HID devices
attached to the system are opened in exclusive mode (using
kIOHIDOptionsTypeSeizeDevice from IOHIDManagerOpen()). According to reports,
some Logitech devices have software which opens devices in exclusive mode,
causing HIDAPI-based programs to crash on systems where these Logitech
devices (and their accompanying software) are installed.

The fix is simple enough. IOHIDManagerOpen() does not need to be called from
HIDAPI, contrary to the examples in Apple's Technical Note TN2187.  From
examining the IOHIDManager source[1], it appears that "opening" the
IOHIDManager (not the IOHIDDevice) causes IOHIDManager to try to open all
matching devices connected to the system, failing if even one device cannot
be opened.  (Calling IOHIDManagerOpen() does indeed call IOHIDDeviceOpen()
for every matching connected device and for every future matching connected
device as well).  HIDAPI of course tries to match all devices (by passing
NULL to IOHIDManagerSetDeviceMatching()), hence the issue.

Empirical evidence first suggested that IOHIDManagerOpen() did not actually
need to be called, and examination of the source[1] seems to confirm that it
only gets in the way.

Many thanks to Brendan Shanks, Bill Good, Github user darthrake, and Vitali
Lovich for pointing this out and participating in the information gathering,
debugging, and discussion.

[1] http://opensource.apple.com/source/IOKitUser/IOKitUser-502/hid.subproj/IOHIDManager.c

Signed-off-by: Alan Ott <alan@signal11.us>
2012-01-11 16:22:54 -05:00
Alan Ott
d019a9ba4f Remove the extraneous call to IOHIDDeviceClose() in the read_thread()
The call is also made in hid_close(). Thanks to Vitali Lovich for pointing this out.
2011-12-30 17:10:19 -05:00
Vitali Lovich
c43255b4b3 Fix hidapi enumeration bug on OSX
Surrounding application may not be using a run loop (or may not have
given it a chance to run).  Process any outstanding events (this does
imply that hid_enumerate will take about at least 1ms to process).
2011-12-30 15:30:12 -05:00
Vitali Lovich
f4e138ac7a Fix string copy logic in Mac backend
This makes sure that a valid range is given to the string copy & that
the returned string always has a valid null-terminator.
2011-12-30 15:21:53 -05: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