Commit Graph

40 Commits

Author SHA1 Message Date
bsupnik
67135a512c 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:48:53 +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
Alan Ott
306e3a6058 Updated to the new API. 2010-07-28 20:53:21 -04:00
Alan Ott
da1ab35011 Fixed up the header comments. 2010-07-28 20:32:41 -04:00
Alan Ott
ca717d8553 Made hid_read() thread-safe on Mac. 2010-07-07 21:01:46 -04:00
Alan Ott
044ddb1295 Added support for Feature Reports to OSX version. 2010-07-05 23:26:18 -04:00
Alan Ott
fc29fa93c9 Initial cut at a Mac OS X version. Not fully complete, but functional for read/write open and close. 2010-07-05 22:48:23 -04:00