-
Notifications
You must be signed in to change notification settings - Fork 399
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
Linux Hotplug: connection-callback implementation for libusb backend #645
Linux Hotplug: connection-callback implementation for libusb backend #645
Conversation
12beacc
to
74f61b3
Compare
Before looking into this - lets finish with #646 - probably some comments are applicable here as well |
Agreed. Going to squash all the commits into one so it's a little less messy, then will try to check for similar macro check related issues. |
e46ca78
to
d6aa1ec
Compare
For now, my biggest concern is the |
25014be
to
b3937ab
Compare
Attempted to adjust the code-style to the current style of the library, it only ended up messing some other locations where indentation is done with both tabs AND spaces :( |
b3937ab
to
bcefdc2
Compare
Added some changes to list management during device removal. |
Ubuntu-cmake and Arch Linux github action build are still failing. |
1 similar comment
Ubuntu-cmake and Arch Linux github action build are still failing. |
Interesting. I will see to it right away. |
Addressed the issue, should be fine now |
Not so sure how to re-run the github actions as there were build error previously. |
I will test this under Linux later. |
This may be a bit tricky to test under Linux as we need to detach the kernel HID driver in order to use hidapi-libusb. BTW, libusb currently only supports hotplug under Linux and macOS. There is a PR for Windows. FreeBSD has its own libusb implementation and it supports hotplug. I will also test this PR under FreeBSD. |
16326c2
to
46f6784
Compare
I just rebased this onto the updated |
@k1-801
I have tried to detached kernel usbhid driver (same results if I do not detach the kernel driver).
|
Okay, thank you for the info, I'll see what I can do. Keeping as a draft until I have tested it myself. |
Thanks. FYI: libusb hotplug works fine.
|
It took me some time to track the issue, but I found it. In turn, calling |
I managed to get the events going (there is some debug output in the printout below that will not be present in the real tests), BUT, the device info is always empty. So far, it's definitely an impovement. I don't know why the fields are empty or how to fix them, Maybe it is related to the fact that I used a second libusb context, but the documentation states they should not interfere with one another, and the processing code never mentions the context at all. UPD: every call to UPD2: libusb/libusb#408 - it is impossible to retrieve any strings while in the libusb's hotplug callback. Will think of a workaround, but this is really becoming complicated. I can imagine it running two threads, one for libusb running it's event processing, in which the events would be put on a queue. The other would be actually processing the queue and calling the callbacks registered in hidapi.
Handle 1: New device is connected: 3-3:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)
Handle 1: New device is connected: 3-3:1.1. Handle 1: New device is connected: 3-3:1.2. libusb callback fired! Event: out Handle 1: Device was disconnected: 3-3:1.1. Handle 1: Device was disconnected: 3-3:1.2. libusb callback fired! Event: in Handle 1: New device is connected: 3-3:1.1. Handle 1: New device is connected: 3-3:1.2. libusb callback fired! Event: out Handle 1: Device was disconnected: 3-3:1.1. Handle 1: Device was disconnected: 3-3:1.2. libusb callback fired! Event: in Handle 1: New device is connected: 3-2:1.1. Handle 1: New device is connected: 3-2:1.2. |
Implemented a two-thread queue processing. Will push in a moment, needs some indentation cleanup.
Handle 1: New device is connected: 3-2:1.0.
type: 04d9 fc38
serial_number: (null)
Manufacturer: (null)
Product: USB Gaming Mouse
Release: 110
Interface: 0
Usage (page): 0x0 (0x0)
Handle 1: New device is connected: 3-2:1.1. Handle 1: New device is connected: 3-2:1.2. Handle 1: Device was disconnected: 3-2:1.0. Handle 1: Device was disconnected: 3-2:1.1. Handle 1: Device was disconnected: 3-2:1.2. Handle 1: New device is connected: 3-2:1.0. Handle 1: New device is connected: 3-2:1.1. Handle 1: New device is connected: 3-2:1.2. |
@mcuee this monstrocity is now more or less ready to be tested, reviewed |
Forgot a call to trigger the pthread_condition... |
Now this works fine. Thanks. And yes it is not requird to detach kernel driver for event. Tested under Ubuntu Linux 20.04. Unplug and plug of Platronics USB headset
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed some formatting concerns of mine, but still don't have enough time to go thru all of the code.
But I trust the community to review it properly and fix if anything needs to be fixed.
That said, I will not block the PR from getting into a feature branch.
No description provided.