Commit Graph

55 Commits

Author SHA1 Message Date
Bei Zhang
2e27f98b3e all: Fix license name
"GNU Public License" does not exist. It is called "GNU General Public
License", "GNU GPL" or simply "GPL".
2013-10-06 17:33:44 -04:00
Alan Ott
a88c7244d6 mac: Fix incorrect device list after device removal
On Mac OS X 10.8.x (Mountain Lion), if a device is connected, opened, then
closed, then unplugged, subsequent calls to hid_enumerate() will still
list the device (even though it's been unplugged).  If the device is
plugged in again, a second instance will show up in the list and often it
will be impossible to open either.  Github user TamToucan figured out that
in hid_enumerate() if a call is made to IOHIDManagerSetDeviceMatching()
before the call to IOHIDManagerCopyDevices() that this will clear the
problem.

Thanks to TamToucan for figuring this out.
2013-09-09 09:39:31 -04:00
Alan Ott
f75f6f735d mac: Unregister the proper removal callback in hid_close()
Unregister from IOHIDManager instead of IOHIDDevice.

Thanks to github user tomsor for noticing this.
2013-03-05 18:05:25 -05:00
Ludovic Rousseau
ec24f93100 all: make hid_enumerate() able to match any vendor or any product
Passing product_id=0 will match any product of a given vendor.  This patch
makes it also possible to use vendor_id=0 to match any vendor for a given
product id.

Windows code added to Ludovic's patch by Alan Ott.
2012-11-27 22:12:35 -05:00
Justin R. Cutler
b0e2fb8d35 libusb/mac: gcc -pedantic warning fixes 2012-11-26 20:20:13 -05:00
Justin R. Cutler
69a91a8f6c All: Convert C99 comments (//) into C89 comments (/* */) 2012-11-26 18:49:51 -05:00
Stan Hu
901fbe9e39 mac: Use Location ID in make_path instead of pointers
Using locations makes the path the same for each run of a HIDAPI based
program.  This is useful for opening devices which don't have a serial
number, and where multiple devices of the same type are attached to the
system at once.

This references pull request #78.
2012-11-26 14:31:17 -05:00
Alan Ott
dc6c170672 mac: Fix string handling
There were errors regarding the length of strings in conversion from CFString
to wchar_t.

Thanks to github user nikolajsheller for pointing this out in pull request #80.
2012-11-26 13:59:33 -05:00
Ludovic Rousseau
54d32f6aa3 mac: Use exclusivce device access
Use kIOHIDOptionsTypeSeizeDevice instead of kIOHIDOptionsTypeNone to
avoid interferences with other applications trying to use the HID device
at the same time.
2012-11-26 13:35:12 -05:00
Ludovic Rousseau
8def28f09d Mac, Linux: Remove extra spaces at end of lines 2012-09-21 10:51:26 -04:00
Ludovic Rousseau
5d2b6b8eab Mac: Fix warning: function declaration isn't a prototype
hid.c:386: warning: function declaration isn't a prototype
2012-09-21 10:51:15 -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
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
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
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
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
Alan Ott
240bad3b66 Remove unnecessary setlocale() on Mac 2012-02-27 12:05:23 -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
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
0075338395 Add hid_init() and hid_exit() to Mac. 2011-09-13 02:37:13 +08: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
Alan Ott
781efae694 hid_read_timeout() (Mac)
Add hid_read_timeout() to mac.
2011-08-08 21:01:45 -04:00
Richard Bateman
d94f682c70 Fixed possible mac when unplugging a device during enumeration 2011-06-24 15:21:40 -06: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
Bastaan Veelo
ba51d59a4e hid_device_info with bcdDevice release number. 2011-01-18 18:38:35 -05:00
Bastaan Veelo
b04545e118 Fill in the Usage Page and Usage values on Mac. 2011-01-14 18:54:38 -05:00
Alan Ott
02b5007fc4 Made the Mac implementation robust to disconnects and re-connects while a device has an open handle. 2010-12-21 00:55:04 -05:00
Alan Ott
cc41195b5c Fixed a 64-bit issue. The code in the Apple docs doesn't work for 64-bit. On 64-bit systems long is 64-bits, but on 32-bit systems it's 32-bits. The function get_long_property() was changed to be get_int_property(), and references to long were changed to int32_t.
Thanks to Ulf Soderberg and Ludovic Rossuau for pointing out this problem.
2010-12-08 13:32:31 -07:00
Alan Ott
ec376aea5e Make sure the string properties are null-terminated. 2010-11-07 16:17:33 -05:00
Ludovic Rousseau
e08ae577ca Failsafe clean rule
If the files to remove are not present the clean rule should not fail.
The clean rule is now idempotent.

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-13 17:01:08 -04:00
Ludovic Rousseau
93affcd658 Also remove $(CPPOBJS) in the clean rule
Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-13 16:52:28 -04:00
Ludovic Rousseau
0dcd42f957 Fix warning: no previous prototype for ‘hid_report_callback’
Local functions should be declared as static

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-13 16:51:44 -04:00
Ludovic Rousseau
a377ee4b1b Fix function declaration isn’t a prototype
Functions with no arguments should use void

hid.c:51: warning: function declaration isn’t a prototype
hid.c:210: warning: function declaration isn’t a prototype

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-13 16:51:13 -04:00
Ludovic Rousseau
306f3f7978 Do not overwrite CFLAGS
The user should be able to add options to CFLAGS

Signed-off-by: Alan Ott <alan@signal11.us>
2010-10-13 16:50:29 -04:00
Alan Ott
09cb41aada Additional licenses. HIDAPI is now GPLv3, BSD, or the original license,
at the discretion of the user. This should provide maximum flexibility and
freedom.
2010-09-13 11:15:24 -04:00
Alan Ott
c5993b749e Fixed Warnings. 2010-08-21 13:26:57 -04:00
Alan Ott
17c4c9251c Changed hid_error() to return const. 2010-08-21 13:22:03 -04:00
Alan Ott
f53f5fb0f8 Changed hid_get_feature_report() to return the number of bytes actually read on Windows. This involved changing the implementation to use DeviceIoControl() rather than HidD_GetFeature().
Changed it on Mac as well to return the same. The Linux implementation already did this.
2010-08-14 14:12:43 -04:00
Alan Ott
65331407a7 Made the hid_error() return wchar_t* so we can get translated error messages. 2010-08-10 14:58:59 -04:00
Alan Ott
3c19a45952 Implemented the following for Mac OS X:
hid_get_manufacturer_string()
	hid_get_product_string()
	hid_get_serial_number_string()
2010-07-28 21:30:09 -04:00
Alan Ott
d2c01f9000 Updated .gitignore to include generated files on Unix. 2010-07-28 20:57:46 -04:00
Alan Ott
228ec0cc25 Merge branch 'master' of github.com:signal11/hidapi 2010-07-28 20:54:01 -04:00