ruabmbua / hidapi-rs

Rust bindings for the hidapi C library
MIT License
172 stars 81 forks source link

Use hidraw instead of libusb backend on Linux #13

Closed drola closed 6 years ago

drola commented 6 years ago

While testing hidapi-rs on Ubuntu I found that:

After a bit of research I found that libusb implementation of hidapi disconnects kernel's hidraw driver when opening a HID device. Additionally it is not possible to access HID devices connected through Bluetooth. Switching to hidraw backend for hidapi fixes issues mentioned above.

ruabmbua commented 6 years ago

@drola you can always add a rule to /etc/udev/rules.d , which changes access permissions to your HID device. I added a group for my keyboard backlight, which has access to the device.

Edit: Also you should probably not just switch the linux build to hidraw. You can for example add config flags / feature sets to cargo, and let the library user choose the backend implementation.

drola commented 6 years ago

My use case requires using hidraw driver because I am implementing advanced functionality on Logitech G203 gaming mouse. I want the kernel to normally handle mouse pointer while simultaneously setting and getting some vendor-specific reports from the device.

Letting the end user choose implementation would be the best option but unfortunately I lack the knowledge to implement it that way. It looks like specifying features in Cargo.toml is the way to go? I could look into this tomorrow and update this PR.

ruabmbua commented 6 years ago

Yes features are the correct way. When you add some #[cfg(...)] magic in your build.rs you can even turn on hidraw by default on linux, and let it override with a feature flag.

drola commented 6 years ago

I updated the pull request.

By default it will use libusb-1.0 backend on Linux to preserver current behaviour. Optionally a feature called linux-hidraw can be enabled to switch to hidraw backend. I added Cargo.toml example to the Usage section in README.md.

ruabmbua commented 6 years ago

Closed in favor of #12 .