99 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
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
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
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
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
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
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
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
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
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
c41e806042 Add empty hid_init() and hid_exit to linux/hid.c 2011-09-10 17:47:08 -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
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
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
Camille Moncelier
03c407ee89 Fixed a leak where hid_open weren't freeing a device_path 2011-08-08 21:32:54 -04: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
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
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
Alan Ott
3290860713 Change interface field to interface_number in hid_device_info struct.
Change field named interface to interface_number because Visual Studio uses
interface as a keyword for managed C++.
2011-01-18 23:00:59 -05:00
Alan Ott
a93cdfbeac Add the interface number to hid_device_info on Linux/libusb implementation.
The interface number is added to the hid_device_info struct. Since the
Linux/libusb implementation can't put the Usage and Usage Page in the
hid_device_info struct because it requires detaching the kernel driver, the
interface number is added instead so that users with composite HID devices
can differentiate between the interfaces on the device.
2011-01-18 22:52:06 -05:00
Alan Ott
a0f8bec509 Remove the Usage and Usage Page code from the libusb/Linux implementation.
This is removed because it requres detaching the kernel driver for the
device.  This is too invasive to be done on a call to hid_enumerate().
2011-01-18 22:46:54 -05:00
Bastaan Veelo
ba51d59a4e hid_device_info with bcdDevice release number. 2011-01-18 18:38:35 -05:00
Alan Ott
1cd43e9d30 Fixed a bug I introduced when cleaning up. 2011-01-15 01:26:40 -05:00
Alan Ott
993919fa8d Initial stab at support for composite devices. To do this, 3 tings
had to happen:
1. Create a hid_device_info struct for each interface which
   reports to be HID, rather than one for each device.
2. Parse and report the Usage Page and Usage for each.
2011-01-14 18:51:54 -05:00
Alan Ott
c3c0c9062a Took out register_error() to prevent warning, but marked it with TODO. 2011-01-07 10:23:40 -05:00
Ludovic Rousseau
49122c26d5 Append instead of overwrite CFLAGS
The user may have a custom CFLAGS with debug flags like -Wextra. These
flags should be used instead of overwritten
2011-01-07 10:17:39 -05:00
Ludovic Rousseau
02c55187a7 Use explicit file names
*.o does not match ../hidtest/hidtest.o so we must use an explicit list
of .o file names
2011-01-07 10:17:30 -05:00
Ludovic Rousseau
81382f21d8 Make "make clean" idempotent
Do not fail if the files to remove do not exist
2011-01-07 10:17:24 -05:00
Alan Ott
5e594ebc95 Ensure that -1 is returned on Linux after a device has been disconnected (unplugged). 2010-12-28 11:23:08 -05:00
Alan Ott
486fe65d94 skip is defaulted to 1. There is no need to re-set it to 1. 2010-12-22 00:08:39 -05:00
Alan Ott
ec07bca7a9 When devices are unplugged, libusb devices will fail (and return failure).
More of these cases are now checked for.
2010-12-22 00:04:35 -05:00
Alan Ott
afc41b7b1d Moved the cleanup of libusb transfer objects to hid_close(), and out of the
read_thread().  This way the sequence of disconnecting the device and then
calling hid_close() will not cause a crash.
2010-12-21 13:24:26 -05:00