-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: WIP: Add ability to register device connection/disconnection callback #299
Conversation
There is some things to do:
|
Lets make it for the feature branch: https://github.com/libusb/hidapi/tree/connection-callback |
This is linked to hotplug support: #238 |
785c8ab
to
69fb610
Compare
The function names may need some discussion. Maybe hid_device_callback can be named as hid_device_hotplug_callback. And hid_register_callback can be named as hid_register_hotplug_callback. |
142a6a4
to
2ee430b
Compare
@mcuee I did some renames:
|
81fcc79
to
e006c76
Compare
I have added dynamic load of |
First test seems to be positive. With hotplug of my Microchip PICkit 2 programmer (single HID device as seen by HIDAPI) and Logitech USB Receiver (6 HID devices as seen by HIDAPI) click for full run log
|
Then I tested with a Bluetooth Mouse (Logitech M557 Mouse) and it seems to work fine as well. It will show up as 6 HID devices as well by hidapi. click to expand
|
@DJm00n This seems to work pretty well under Windows. Just wondering if you can add for other backend as well (eg: Linux hidraw, libusb or macOS). I have the systems to test for these platforms (Windows laptop, Raspberry Pi 400 Linux and Mac Mini M1 macOS). |
83feedb
to
e91f905
Compare
Related libusb issue: libusb/libusb#86 |
This is a large (even though important) change. |
@andyvorld thank you for your work. I have manually rebased my changes under current I've done this to avoid unnecessary noise in the git history. |
650dfc6
to
cd0a4c9
Compare
@DJm00n could you explicitly merge |
github action for macos-cmake and ubuntu-cmake failed due to compiler warning treated as error. Interestingly macos-automake passed. |
Run log under Windows. I run hidtest.exe. Then I unplug the Logitech USB Receiver and then plug it back in. @DJm00n
|
BTW, the above is talking about the lack of hotplug feature for libusb Windows backend. Since we only use libusb under Linux and BSDs but not Windows, the above libusb issue does not really matter. |
I think there is a flag on |
Thanks. Yes this is the one.
|
Yeah, it is not only a compiler - we explicitly set "more warnings and warnings-as-errors" only for CMake builds for our CI. |
Yup. /** Arm the callback and fire it for all matching currently attached devices. */
HID_API_HOTPLUG_ENUMERATE = (1 << 0) |
Happy to see progress on this 😍 What's remaining before the merge to feature branch? |
@mini-ninja-64 its missing some mutex protection of the callback list on register/unregister/notify |
As promised - merged into dev branch, so the community may work on the implementation for other backends. I've opened a separate ticket for the "mutex problem". |
…back (libusb#299) - initial API; - Windows backend implementation;
…back (libusb#299) - initial API; - Windows backend implementation;
I have implemented two new methods:
These could be used to receive notification about HID device connection or disconnection.
I did implement it only for Windows via CM_Register_Notification that is available since Windows 8. Not sure about other platforms.
Any comments/objections are welcomed.