Skip to content

Commit bca4045

Browse files
authored
Fire v0.12.0 (signal11#398)
- add convenient macros to check HIDAPI version in runtime; - mark in which version all recent HIAPI API functions where added;
1 parent 05f0588 commit bca4045

File tree

8 files changed

+67
-5
lines changed

8 files changed

+67
-5
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.11.2
1+
0.12.0

hidapi/hidapi.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,40 @@
4848
4949
@ingroup API
5050
*/
51-
#define HID_API_VERSION_MINOR 11
51+
#define HID_API_VERSION_MINOR 12
5252
/** @brief Static/compile-time patch version of the library.
5353
5454
@ingroup API
5555
*/
56-
#define HID_API_VERSION_PATCH 2
56+
#define HID_API_VERSION_PATCH 0
5757

5858
/* Helper macros */
5959
#define HID_API_AS_STR_IMPL(x) #x
6060
#define HID_API_AS_STR(x) HID_API_AS_STR_IMPL(x)
6161
#define HID_API_TO_VERSION_STR(v1, v2, v3) HID_API_AS_STR(v1.v2.v3)
6262

63+
/** @brief Coverts a version as Major/Minor/Patch into a number:
64+
<8 bit major><16 bit minor><8 bit patch>.
65+
66+
This macro was added in version 0.12.0.
67+
68+
Convenient function to be used for compile-time checks, like:
69+
#if HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
70+
71+
@ingroup API
72+
*/
73+
#define HID_API_MAKE_VERSION(mj, mn, p) (((mj) << 24) | ((mn) << 8) | (p))
74+
75+
/** @brief Static/compile-time version of the library.
76+
77+
This macro was added in version 0.12.0.
78+
79+
@see @ref HID_API_MAKE_VERSION.
80+
81+
@ingroup API
82+
*/
83+
#define HID_API_VERSION HID_API_MAKE_VERSION(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH)
84+
6385
/** @brief Static/compile-time string version of the library.
6486
6587
@ingroup API
@@ -369,6 +391,8 @@ extern "C" {
369391

370392
/** @brief Get a input report from a HID device.
371393
394+
Since version 0.10.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 10, 0)
395+
372396
Set the first byte of @p data[] to the Report ID of the
373397
report to be read. Make sure to allow space for this
374398
extra byte in @p data[]. Upon return, the first byte will

hidtest/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ hidtest_SOURCES = test.c
1818
hidtest_LDADD = $(top_builddir)/$(backend)/libhidapi.la
1919

2020
endif
21+
22+
if OS_DARWIN
23+
AM_CPPFLAGS += -I$(top_srcdir)/mac/
24+
endif

hidtest/test.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
#include <unistd.h>
2929
#endif
3030

31+
// Fallback/example
32+
#ifndef HID_API_MAKE_VERSION
33+
#define HID_API_MAKE_VERSION(mj, mn, p) (((mj) << 24) | ((mn) << 8) | (p))
34+
#endif
35+
#ifndef HID_API_VERSION
36+
#define HID_API_VERSION HID_API_MAKE_VERSION(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH)
37+
#endif
38+
39+
#if defined(__APPLE__) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
40+
#include <hidapi_darwin.h>
41+
#endif
42+
3143
int main(int argc, char* argv[])
3244
{
3345
(void)argc;
@@ -43,7 +55,7 @@ int main(int argc, char* argv[])
4355
struct hid_device_info *devs, *cur_dev;
4456

4557
printf("hidapi test/example tool. Compiled with hidapi version %s, runtime version %s.\n", HID_API_VERSION_STR, hid_version_str());
46-
if (hid_version()->major == HID_API_VERSION_MAJOR && hid_version()->minor == HID_API_VERSION_MINOR && hid_version()->patch == HID_API_VERSION_PATCH) {
58+
if (HID_API_VERSION == HID_API_MAKE_VERSION(hid_version()->major, hid_version()->minor, hid_version()->patch)) {
4759
printf("Compile-time version matches runtime version of hidapi.\n\n");
4860
}
4961
else {
@@ -53,6 +65,12 @@ int main(int argc, char* argv[])
5365
if (hid_init())
5466
return -1;
5567

68+
#if defined(__APPLE__) && HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
69+
// To work properly needs to be called before hid_open/hid_open_path after hid_init.
70+
// Best/recommended option - call it right after hid_init.
71+
hid_darwin_set_open_exclusive(0);
72+
#endif
73+
5674
devs = hid_enumerate(0x0, 0x0);
5775
cur_dev = devs;
5876
while (cur_dev) {

libusb/hidapi_libusb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
/** @file
2121
* @defgroup API hidapi API
22+
23+
* Since version 0.11.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 11, 0).
2224
*/
2325

2426
#ifndef HIDAPI_LIBUSB_H__

mac/Makefile-manual

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ all: hidtest
1111
CC=gcc
1212
COBJS=hid.o ../hidtest/test.o
1313
OBJS=$(COBJS)
14-
CFLAGS+=-I../hidapi -Wall -g -c
14+
CFLAGS+=-I../hidapi -I. -Wall -g -c
1515
LIBS=-framework IOKit -framework CoreFoundation -framework AppKit
1616

1717

mac/hidapi_darwin.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
/** @file
2121
* @defgroup API hidapi API
22+
23+
* Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
2224
*/
2325

2426
#ifndef HIDAPI_DARWIN_H__
@@ -34,6 +36,8 @@ extern "C" {
3436

3537
/** @brief Get the location ID for a HID device.
3638
39+
Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
40+
3741
@ingroup API
3842
@param dev A device handle returned from hid_open().
3943
@param location_id The device's location ID on return.
@@ -49,6 +53,8 @@ extern "C" {
4953
By default on Darwin platform all devices opened by HIDAPI with @ref hid_open or @ref hid_open_path
5054
are opened in exclusive mode (see kIOHIDOptionsTypeSeizeDevice).
5155
56+
Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
57+
5258
@ingroup API
5359
@param open_exclusive When set to 0 - all further devices will be opened
5460
in non-exclusive mode. Otherwise - all further devices will be opened
@@ -63,6 +69,8 @@ extern "C" {
6369

6470
/** @brief Getter for option set by @ref hid_darwin_set_open_exclusive.
6571
72+
Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
73+
6674
@ingroup API
6775
@return 1 if all further devices will be opened in exclusive mode.
6876
@@ -73,6 +81,8 @@ extern "C" {
7381

7482
/** @brief Check how the device was opened.
7583
84+
Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
85+
7686
@ingroup API
7787
@param dev A device to get property from.
7888

windows/hidapi_winapi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
/** @file
2121
* @defgroup API hidapi API
22+
*
23+
* Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
2224
*/
2325

2426
#ifndef HIDAPI_WINAPI_H__
@@ -34,6 +36,8 @@ extern "C" {
3436

3537
/** @brief Get the container ID for a HID device.
3638
39+
Since version 0.12.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 12, 0)
40+
3741
This function returns the `DEVPKEY_Device_ContainerId` property of
3842
the given device. This can be used to correlate different
3943
interfaces/ports on the same hardware device.

0 commit comments

Comments
 (0)