Skip to content

Commit af6468b

Browse files
authored
Merge branch 'master' into libusb-error
2 parents c2ed2ca + 657b9fa commit af6468b

23 files changed

+455
-149
lines changed

.github/workflows/builds.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ jobs:
367367
with:
368368
path: hidapisrc
369369
- name: Install dependencies
370-
run: sudo dnf install -y autoconf automake libtool mingw64-gcc cmake ninja-build make
370+
run: sudo dnf install -y autoconf automake libtool gawk mingw64-gcc cmake ninja-build make
371371
- name: Configure CMake
372372
run: |
373373
rm -rf build install
@@ -439,7 +439,7 @@ jobs:
439439
- name: Install dependencies
440440
run: |
441441
pacman -Sy
442-
pacman -S --noconfirm glibc lib32-glibc gcc pkg-config autoconf automake libtool libusb libudev0 cmake make
442+
pacman -S --noconfirm glibc lib32-glibc gcc pkg-config autoconf automake libtool libusb cmake make
443443
- name: Configure CMake
444444
run: |
445445
rm -rf build install
@@ -485,7 +485,7 @@ jobs:
485485
cmake \
486486
-B build/shared_test \
487487
-S hidapisrc/hidtest \
488-
-Dhidapi_ROOT=install/shared-cmake \
488+
-Dhidapi_ROOT=$(pwd)/install/shared-cmake \
489489
-DCMAKE_INSTALL_PREFIX=install/shared_test \
490490
"-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}"
491491
cd build/shared_test
@@ -495,7 +495,7 @@ jobs:
495495
cmake \
496496
-B build/static_test \
497497
-S hidapisrc/hidtest \
498-
-Dhidapi_ROOT=install/static-cmake \
498+
-Dhidapi_ROOT=$(pwd)/install/static-cmake \
499499
-DCMAKE_INSTALL_PREFIX=install/static_test \
500500
"-DCMAKE_C_FLAGS=${GNU_COMPILE_FLAGS}"
501501
cd build/static_test
@@ -562,7 +562,7 @@ jobs:
562562
-GNinja \
563563
-B build/shared_test \
564564
-S hidapisrc/hidtest \
565-
-Dhidapi_ROOT=install/shared-cmake \
565+
-Dhidapi_ROOT=$(pwd)/install/shared-cmake \
566566
-DCMAKE_INSTALL_PREFIX=install/shared_test \
567567
"-DCMAKE_C_FLAGS=${ALPINE_COMPILE_FLAGS}"
568568
cd build/shared_test
@@ -573,7 +573,7 @@ jobs:
573573
-GNinja \
574574
-B build/static_test \
575575
-S hidapisrc/hidtest \
576-
-Dhidapi_ROOT=install/static-cmake \
576+
-Dhidapi_ROOT=$(pwd)/install/static-cmake \
577577
-DCMAKE_INSTALL_PREFIX=install/static_test \
578578
"-DCMAKE_C_FLAGS=${ALPINE_COMPILE_FLAGS}"
579579
cd build/static_test

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171

7272

7373
coverity-macos:
74-
runs-on: macos-13
74+
runs-on: macos-15-intel
7575
needs: [coverity-windows]
7676

7777
steps:

.github/workflows/docs.yaml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,12 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-24.04
1212
steps:
13+
- name: Install Doxygen
14+
run: sudo apt satisfy "doxygen (>= 1.9.6)"
1315

14-
- name: Install Doxygen static libclang deps
15-
run: sudo apt-get install libclang1-12 libclang-cpp12
16-
17-
- name: Install Doxygen from SF binary archives
18-
env:
19-
DOXYGEN_VERSION: '1.9.6'
20-
run: |
21-
mkdir .doxygen && cd .doxygen
22-
curl -L https://sourceforge.net/projects/doxygen/files/rel-$DOXYGEN_VERSION/doxygen-$DOXYGEN_VERSION.linux.bin.tar.gz > doxygen.tar.gz
23-
gunzip doxygen.tar.gz
24-
tar xf doxygen.tar
25-
cd doxygen-$DOXYGEN_VERSION
26-
sudo make install
27-
28-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
2917

3018
- run: doxygen
3119
working-directory: doxygen
@@ -37,7 +25,7 @@ jobs:
3725
path: ${{ github.workspace }}/doxygen/html
3826

3927
deploy-docs:
40-
runs-on: ubuntu-latest
28+
runs-on: ubuntu-24.04
4129
needs: [build]
4230
if: github.ref_type == 'branch' && github.ref_name == 'master'
4331
concurrency:
@@ -51,7 +39,7 @@ jobs:
5139
path: docs
5240

5341
- name: upload to github pages
54-
uses: peaceiris/actions-gh-pages@v3
42+
uses: peaceiris/actions-gh-pages@v4
5543
with:
5644
github_token: ${{ secrets.GITHUB_TOKEN }}
5745
publish_dir: ./docs

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ CMakeLists.txt.user
3030

3131
# doxgen output
3232
doxygen/html/
33+
34+
# Visual Studio Code + CMake
35+
.vscode/
36+
build/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| `Linux/macOS/Windows (master)` | [![GitHub Builds](https://github.com/libusb/hidapi/actions/workflows/builds.yml/badge.svg?branch=master)](https://github.com/libusb/hidapi/actions/workflows/builds.yml?query=branch%3Amaster) |
66
| `Windows (master)` | [![Build status](https://ci.appveyor.com/api/projects/status/xfmr5fo8w0re8ded/branch/master?svg=true)](https://ci.appveyor.com/project/libusb/hidapi/branch/master) |
77
| `BSD, last build (branch/PR)` | [![builds.sr.ht status](https://builds.sr.ht/~z3ntu/hidapi.svg)](https://builds.sr.ht/~z3ntu/hidapi) |
8-
| `Coverity Scan (last)` | ![Coverity Scan](https://scan.coverity.com/projects/583/badge.svg) |
8+
| `Coverity Scan (last)` | [![Coverity Scan](https://scan.coverity.com/projects/583/badge.svg)](https://scan.coverity.com/projects/hidapi) |
99

1010
HIDAPI is a multi-platform library which allows an application to interface
1111
with USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and macOS.

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.15.0
1+
0.16.0

hidapi/hidapi.h

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
5353
@ingroup API
5454
*/
55-
#define HID_API_VERSION_MINOR 15
55+
#define HID_API_VERSION_MINOR 16
5656
/** @brief Static/compile-time patch version of the library.
5757
5858
@ingroup API
@@ -144,6 +144,13 @@ extern "C" {
144144
Specifications:
145145
https://www.microsoft.com/download/details.aspx?id=103325 */
146146
HID_API_BUS_SPI = 0x04,
147+
148+
/** Virtual device
149+
E.g.: https://elixir.bootlin.com/linux/v4.0/source/include/uapi/linux/input.h#L955
150+
151+
Since version 0.16.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 16, 0)
152+
*/
153+
HID_API_BUS_VIRTUAL = 0x05,
147154
} hid_bus_type;
148155

149156
/** hidapi info structure */
@@ -341,9 +348,11 @@ extern "C" {
341348
@returns
342349
This function returns the actual number of bytes read and
343350
-1 on error.
344-
Call hid_error(dev) to get the failure reason.
351+
Call hid_read_error(dev) to get the failure reason.
345352
If no packet was available to be read within
346353
the timeout period, this function returns 0.
354+
355+
@note This function doesn't change the buffer returned by the hid_error(dev).
347356
*/
348357
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
349358

@@ -363,12 +372,36 @@ extern "C" {
363372
@returns
364373
This function returns the actual number of bytes read and
365374
-1 on error.
366-
Call hid_error(dev) to get the failure reason.
375+
Call hid_read_error(dev) to get the failure reason.
367376
If no packet was available to be read and
368377
the handle is in non-blocking mode, this function returns 0.
378+
379+
@note This function doesn't change the buffer returned by the hid_error(dev).
369380
*/
370381
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *dev, unsigned char *data, size_t length);
371382

383+
/** @brief Get a string describing the last error which occurred during hid_read/hid_read_timeout.
384+
385+
Since version 0.15.0, @ref HID_API_VERSION >= HID_API_MAKE_VERSION(0, 15, 0)
386+
387+
This function is intended for logging/debugging purposes.
388+
389+
This function guarantees to never return NULL for a valid @ref dev.
390+
If there was no error in the last call to hid_read/hid_read_error -
391+
the returned string clearly indicates that.
392+
393+
Strings returned from hid_read_error() must not be freed by the user,
394+
i.e. owned by HIDAPI library.
395+
Device-specific error string may remain allocated at most until hid_close() is called.
396+
397+
@ingroup API
398+
@param dev A device handle. Shall never be NULL.
399+
400+
@returns
401+
A string describing the hid_read/hid_read_timeout error (if any).
402+
*/
403+
HID_API_EXPORT const wchar_t* HID_API_CALL hid_read_error(hid_device *dev);
404+
372405
/** @brief Set the device handle to be non-blocking.
373406
374407
In non-blocking mode calls to hid_read() will return

hidtest/test.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ int main(int argc, char* argv[])
245245
// Try to read from the device. There should be no
246246
// data here, but execution should not block.
247247
res = hid_read(handle, buf, 17);
248+
if (res < 0) {
249+
#if HID_API_VERSION >= HID_API_MAKE_VERSION(0, 15, 0)
250+
printf("Unable to read from device: %ls\n", hid_read_error(handle));
251+
#else
252+
printf("Unable to read from device: %ls\n", hid_error(handle));
253+
#endif
254+
}
248255

249256
// Send a Feature Report to the device
250257
buf[0] = 0x2;
@@ -254,7 +261,7 @@ int main(int argc, char* argv[])
254261
buf[4] = 0x00;
255262
res = hid_send_feature_report(handle, buf, 17);
256263
if (res < 0) {
257-
printf("Unable to send a feature report.\n");
264+
printf("Unable to send a feature report: %ls\n", hid_error(handle));
258265
}
259266

260267
memset(buf,0,sizeof(buf));

libusb/hid.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length);
153153
static hid_device *new_hid_device(void)
154154
{
155155
hid_device *dev = (hid_device*) calloc(1, sizeof(hid_device));
156+
if (!dev)
157+
return NULL;
158+
156159
dev->blocking = 1;
157160

158161
hidapi_thread_state_init(&dev->thread_state);
@@ -1670,11 +1673,20 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t
16701673
return bytes_read;
16711674
}
16721675

1676+
16731677
int HID_API_EXPORT hid_read(hid_device *dev, unsigned char *data, size_t length)
16741678
{
16751679
return hid_read_timeout(dev, data, length, dev->blocking ? -1 : 0);
16761680
}
16771681

1682+
1683+
HID_API_EXPORT const wchar_t * HID_API_CALL hid_read_error(hid_device *dev)
1684+
{
1685+
(void)dev;
1686+
return L"hid_read_error is not implemented yet";
1687+
}
1688+
1689+
16781690
int HID_API_EXPORT hid_set_nonblocking(hid_device *dev, int nonblock)
16791691
{
16801692
dev->blocking = !nonblock;

0 commit comments

Comments
 (0)