315 Commits

Author SHA1 Message Date
Ludovic Rousseau
6761e3f5ba Linux: Fix warning: no previous prototype
hid.c:190:1: warning: no previous prototype for 'parse_uevent_info' [-Wmissing-prototypes]
2012-09-21 10:48:54 -04:00
Ludovic Rousseau
367fc3f3aa linux: Fix bug on mbstowcs() usage
In case of error mbstowcs() returns (size_t) -1
It is not a negative value since mbstowcs() returns a size_t (unsigned)

Fix compiler warning:
hid.c: In function 'utf8_to_wchar_t':
hid.c:105:3: warning: comparison of unsigned expression < 0 is always false [-Wtype-limits]
2012-09-21 10:48:36 -04:00
Brendan Shanks
ee808f9dfc Mac: Remove 'next' from struct hid_device_
Remove 'next' from struct hid_device_, it's unused since device_list was
removed
2012-09-17 21:25:09 -04:00
Brendan Shanks
471dd9d5ae Mac: Remove device_list and its mutex/code
Remove device_list, which was used to match up IOHIDDeviceRef's and
hid_device's in the device removal callback. This was needed because the
removal callback was attached to the whole IOHIDManager, instead of
individual IOHIDDevices.
Instead attach the removal callback to each IOHIDDevice individually,
and have a pointer to the device's hid_device passed to the callback.
2012-09-17 21:25:08 -04:00
Peter Stuge
399e4fad12 configure.ac: Reduce required autoconf version to 2.63 which also works 2012-08-14 22:34:29 -04:00
Peter Stuge
8cd443954c README: Use $HOST also in the "Build libudev" configure command 2012-08-14 22:34:18 -04:00
Alan Ott
425ef9f86e udev: Insert comment about case-sensitivity
VID/PID (hex) are case sensitive.
2012-07-30 10:51:51 -04:00
Thomas Perl
807afbc35c Linux: Fix return value handling of mbstowcs() 2012-07-17 22:31:05 -04:00
Alan Ott
48352615f0 Linux: Small refactoring of Thomas's previous patch 2012-07-17 22:31:05 -04:00
Thomas Perl
36f7dec134 linux/hid.c: Fix enumeration for Bluetooth devices 2012-07-16 01:09:13 -04:00
Alan Ott
44f9df5ec1 Windows: Make sure a driver is present for enumeration.
Windows will enumerate a device before the driver has been attached to
that device. This is problematic, and causes hangups on Windows 7
(possibly othes) when the device is opened before a driver is attached
and then closed. This patch makes sure that a driver has been attached
to the device before putting it in the enumeration list.
2012-07-16 13:02:32 +08:00
Alex Dupre
645a0c357a FreeBSD: Conditionally remove calls to libusb_detach_kernel_driver()
libusb_detach_kernel_driver() is not needed on FreeBSD.
2012-07-16 00:52:43 -04:00
Alex Dupre
49021efd0f FreeBSD: Add $(LIBS) to libhidapi.so target (Makefile.freebsd) 2012-07-16 00:52:17 -04:00
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