123 Commits

Author SHA1 Message Date
nastys
f42423643e Add Sixaxis init for Monterey 2025-05-23 03:08:36 +02:00
Ihor Dutchak
0ab6c14264 Add missing sanity checks (#727)
Based on #696

- Add missing checks for zero/null arguments;
- Better management of error strings in case of failures;

---------

Co-authored-by: Megamouse <studienricky89@googlemail.com>
2025-03-13 13:11:20 +02:00
Ihor Dutchak
95e6b98ce9 Add hid_read_error (#721)
hid_read_error is a separate error function, that returns error status of hid_read/hid_read_timeout.
hid_read/hid_read_timeout is no longer changes internal buffer used by hid_error and it makes it safe to use hid_read/hid_read_timeout from a separa thread, concurently with other device functions.
2025-03-11 19:26:36 +02:00
Ihor Dutchak
2446b2a8ef macOS: add option to mimic 1.0.0 compatibility version (#709)
As it used to be with autotools.

Fixes: #622
2025-03-01 22:32:53 +02:00
Ihor Dutchak
b26f057996 Ensure last_error_str released on macOS (#714)
Found by Coverity
2025-01-14 23:20:52 +02:00
Ihor Dutchak
d101e5c7e4 macOS: fix hid_send_output_report implementation
- fix name of the function on macOS
- add compile-time check by the CI

Fixes: #683
2024-08-02 16:48:23 +03:00
mbcinergy
4578ea2461 Add hid_send_output_report() (#677)
`hid_send_output_report` sends report over control pipe, unlike existing `hid_write` which would send the data on the first interrupt OUT endpoint, if one exists and only falls back to control pipe.
2024-06-12 19:40:09 +03:00
Ihor Dutchak
76462bd767 Avoid CMake backward compatibility warning (#663)
Avoid a message:
```
Compatibility with CMake < 3.5 will be removed from a future version of CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
```

Fixes: #642
2024-03-05 13:26:01 +02:00
Ihor Dutchak
7011fa98af pthread_barrier_wait: properly check the wait condition (#644)
- minor code-style fixes;
2023-11-22 12:26:16 +02:00
Ryan C. Gordon
eea8cac079 Don't try to memcpy() to a NULL destination. (#637)
This function is called with a literal NULL for that pointer later in
the file.
2023-11-12 18:26:05 +02:00
Brendan Shanks
4009466d59 macOS: Check for macOS 10.10 using kCFCoreFoundationVersionNumber instead of AppKit (#611)
Effectivelty removes the dependency on AppKit for HIDAPI.

Fixes: #587
2023-08-27 17:28:01 +03:00
luzpaz
849c8a9099 Fix various typo (#597)
Found via `codespell -q 3 -L childs,fo,xwindows`
Encountered in downstream https://github.com/libsdl-org/SDL
2023-07-03 17:18:54 +03:00
Sam Lantinga
c6c4dd0243 macOS: fix crash when IOHIDDevice property is not a string (#573)
- fixed crash on macOS when AirPods are connected (reported to happen with some AirPods on some macOS version);
2023-06-07 11:53:05 +03:00
Vitaly Samoylik
6e3dd5774a Return from hid_open_path early in case if hid_init fails to avoid crash (#555)
Fixes: #547
2023-05-15 13:25:22 +03:00
Ihor Dutchak
b516e97048 macOS: fallback to parent entry kUSBInterfaceNumber prop
In macOS 13.3 the kUSBInterfaceNumber is no longer one of the properties
of the IOHIDDevice (even if its transport is USB).

In case if kUSBInterfaceNumber property (for USB Interface number)
is not available as an IOHIDDevice property - find the value for that property
in one of the Parent IORegistry Entries.
2023-05-05 12:11:18 +03:00
Ihor Dutchak
80a206aee5 macos: (try) get USB interface only if bus_type is USB 2023-05-05 12:11:18 +03:00
Oleh Yudin
8588168980 Fix API definitions for clang/gcc flag -Wstrict-prototypes (#533) 2023-04-26 18:28:51 +03:00
Rafał Duszyński
c1b9d2ad98 Properly handle the close of run loop on macOS (#522)
- as per documentation `kCFRunLoopRunStopped` should be handled once the runloop is closed via `CFRunLoopStop`;
- if it is not handled - a race condition/crash may happen on the latest macOS when a device gets disconnected while being open;
2023-04-09 20:01:34 +03:00
Ihor Dutchak
26b5bb0ccf RFC: add hid_get_report_descriptor API function (#451)
- native implementations for hidraw/libusb/macOS;
- HID Report Descriptor reconstruction from HIDP_PREPARSED_DATA on Windows;
- unit-tests for some known devices for `hid_winapi_descriptor_reconstruct_pp_data`;
- support for ASAN builds (mainly to check the `hid_winapi_descriptor_reconstruct_pp_data`/its unit-tests;
2023-03-12 14:45:30 +02:00
Ozkan Sezer
88a0f029b7 mac: replace sprintf uses with snprintf (#511)
Reference issue: https://github.com/libusb/hidapi/pull/509
2023-02-22 17:16:03 +02:00
Ihor Dutchak
eecbe74bb1 macOS: silence sprintf deprecation (#509) 2023-02-19 17:38:04 +02:00
Steven Michalske
f2e2b5b4d4 macOS: Error reporting/hid_error implementation (#314) 2022-10-14 13:25:42 +03:00
Ihor Dutchak
4e63d6dfc3 Introduce HID_API_MAX_REPORT_DESCRIPTOR_SIZE (#452)
- first step is to use HID_API_MAX_REPORT_DESCRIPTOR_SIZE internally;
- port a few improvements from get-descriptor branch early;

Resolves: #384
2022-09-15 13:05:56 +03:00
Dimitriy Ryazantcev
0f2cf886e5 RFC: Add HID bus type in hid_device_info (#308) 2022-09-10 19:18:09 +03:00
Julian Waller
5c9f147a07 Add hid_get_device_info (#432)
- new API function: `struct hid_device_info * hid_get_device_info(hid_device *dev);` to get `hid_device_info` after the device already opened;
- reused existing implementation on Windows and macOS from enumeration routines to have the implementation;
- refactored libusb implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;
- refactored hidraw implementation to have a shared routine for `hid_enumerate` and `hid_get_device_info`;

Resolves: #431
Closes: #164
Closes: #163
2022-08-13 19:01:57 +03:00
Ihor Dutchak
52c728acf4 Use propper type for mach_port_t default param
- enable compilation warnings as errors for CI to catch such issues in the future;
- fix Mingw strict compilation warnings;
2022-05-05 14:53:17 +03:00
Ihor Dutchak
2aeb0688fa Don't use deprecated kIOMasterPortDefault (#406)
`kIOMasterPortDefault` is deprecated since macOS 12.0.
One alternative is to use named constant `kIOMainPortDefault` which is not available before macOS 12.0.

Both named constants are just an alias for `NULL`, so it is simpler to use it directly instead.

Fixes: #377
2022-05-02 14:48:12 +03:00
Ihor Dutchak
bca404520f Fire v0.12.0 (#398)
- add convenient macros to check HIDAPI version in runtime;
- mark in which version all recent HIAPI API functions where added;
2022-04-23 15:50:41 +03:00
Ihor Dutchak
05f0588220 darwin: add option to open device in non-exclusive mode (#397)
Resolves: #27
Resolves: #344
2022-04-23 14:16:42 +03:00
Frederik Seiffert
1ce31c3594 macos: Add Mac-specific API to get device Location ID (#378) 2022-02-25 10:54:28 +02:00
Frederik Seiffert
e08ddcee5f macOS: Fix build warnings (#374) 2022-02-05 17:24:20 +02:00
Ihor Dutchak
6f37897bef Remove stale Windows/macOS example/test 2022-01-29 18:33:15 +02:00
Ihor Dutchak
69dcdc1ff0 Update copyright strings 2022-01-29 18:33:15 +02:00
Ihor Dutchak
4d63a5085a macOS: use IORegistryEntryGetRegistryEntryID to resolve paths (#322)
With some device connection configurations,
the device paths become over 512 bytes (io_string_t max length)
which makes them unusable with current implementation.

Rather than using ServiceRegistry string path, use its ID,
which is uint64_t and easily serializable/deserializable into a string.

Implementation idea by felix.schwarz@iospirit.com
8d251c3854

Fixes: #127, #236.
2021-08-23 20:58:13 +03:00
Ihor Dutchak
f2bb972e7f add CMake build system 2021-07-03 20:38:58 +03:00
Ihor Dutchak
42fa21fff1 drop support of macOS 10.5 and earlier (#121)
- IOHIDDeviceGetService is available since macOS 10.6
2021-06-14 13:30:35 +03:00
Erik OShaughnessy
7620bc7faa Guard against zero length buffers in hid_write (#279) 2021-06-14 04:09:13 +03:00
Jonas Malaco
ce606fac8f macOS: check if IOHIDManagerCopyDevices returned a NULL (#209)
Removes a possible cause for a segmentation fault observed in `CFSetGetCount`.

Related: #208 ("Segmentation fault on Mac OS Catalina").
Signed-off-by: Jonas Malaco <jonas@protocubo.io>
2020-11-23 21:03:03 +02:00
Ihor Dutchak
a731aae2a3 macOS: fix -Wall -Wextra -pedantic compilation warnings 2020-10-16 13:06:50 +03:00
Ihor Dutchak
8f72236099 add hid_version/hid_version_str API (#192)
- API functions to get runtime version of the library;
- macros to get static/compile-time version of the library;
- VERSION file;
2020-10-14 18:41:08 +03:00
Ihor Dutchak
fd53f39f25 macOS: enumerate device with primary usage/usage_page first (#193)
It improves backward compatibility with versions of hidapi, where
usage/usage_pairs didn't emit seaprate hid_devices_info.
2020-10-14 18:37:27 +03:00
Ihor Dutchak
cdc473dfe4 Don't leak device handle in macOS 10.10 or newer (#186)
In one of the early versions of macOS, when you try to close the device
with IOHIDDeviceClose() that is being physically disconnected.
Starting with some version of macOS, this crash bug was fixed,
and starting with macSO 10.15 the opposite effect took place:
in some environments crash happens if IOHIDDeviceClose() is _not_ called.

This patch is to keep a workaround for old versions of macOS,
and don't have a leak in new/tested environments.

Fixes: #144.
2020-09-29 14:01:30 +03:00
Pavel Hübner
24a822c80f Fix compilation warning in pedantic mode on macOS
The compiler provided the following warning message:
```
hid.c:830:29: warning: format specifies type 'void *' but the argument has type 'IOHIDDeviceRef' (aka 'struct __IOHIDDevice *') [-Wformat-pedantic]
                sprintf(str, "HIDAPI_%p", dev->device_handle);
                                     ~~   ^~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/secure/_stdio.h:47:56: note: expanded from macro 'sprintf'
  __builtin___sprintf_chk (str, 0, __darwin_obsz(str), __VA_ARGS__)
```
2020-03-20 01:43:44 +02:00
Luca Weiss
51bdec7844 Fix manual Makefiles and add CI for them (#131) 2020-01-12 04:09:48 +02:00
0xDP
65d22a9c31 macOS: correct IOKit framework location (#120) 2019-12-07 18:54:07 +02:00
Tod E. Kurt
ca1a2d6efa macOS support for multiple usage/usage-pages (#125)
* macOS support for multiple usage/usage-pages
Update of @fengji2006 PR#65, second try

* apply requested changes and test

* handle possible nullptr
2019-12-05 10:53:44 -08:00
Daniel Van Noord
083223e779 Added support for Get Input Report (#59)
- Get Input Report supported on linux/libusb, mac and windows;
- linux/hidraw doesn't support it on kernel level;
2019-11-15 13:55:51 +02:00
Ludovic Rousseau
3cea631d43 macOS: fix Makefile-manual to build hidtest 2019-11-05 14:00:44 +01:00
Ihor Dutchak
d64f6c6a16 macOS: send report id conditionally for hid_get_feature_report (#70)
same as in hid_send_feature_report, and Windows/Linux
2019-09-24 13:34:59 +03:00
Josh Junon
d8b6588d09 mac: prevent memory leak in hid_open_path() if hid_init() fails 2019-09-24 13:25:23 +03:00