Crates.io | async-hid |
lib.rs | async-hid |
version | 0.1.0 |
source | src |
created_at | 2023-08-13 20:48:45.896986 |
updated_at | 2023-08-13 20:48:45.896986 |
description | A async library for interacting with HID devices |
homepage | |
repository | https://github.com/sidit77/async-hid |
max_upload_size | |
id | 943580 |
size | 85,215 |
A Rust library for asynchronously interacting with HID devices.
This crate aims the be a replacement for hidapi-rs without the baggage that comes from being a wrapper around a C library.
This crate generally offers a simpler and more streamlined api while also supporting async as best as possible.
use async_hid::{AccessMode, DeviceInfo, HidResult};
use simple_logger::SimpleLogger;
use futures_lite::StreamExt;
#[tokio::main]
async fn main() -> HidResult<()> {
SimpleLogger::new().init().unwrap();
let device = DeviceInfo::enumerate()
.await?
//Steelseries Arctis Nova 7X headset
.find(|info: &DeviceInfo | info.matches(0xFFC0, 0x1, 0x1038, 0x2206))
.await
.expect("Could not find device")
.open(AccessMode::ReadWrite)
.await?;
device.write_output_report(&[0x0, 0xb0]).await?;
let mut buffer = [0u8; 8];
let size = device.read_input_report(&mut buffer).await?;
println!("{:?}", &buffer[..size]);
Ok(())
}
Operating System | Underlying API |
---|---|
Windows | WinRT (Windows.Devices.HumanInterfaceDevice ) |
Linux | hidraw |
MacOs | IOHIDManager |
The amount of asynchronicity that each OS provides varies. The following tables gives a rough overview which calls utilize async under the hood.
enumerate |
open |
read_input_report |
write_output_report |
|
---|---|---|---|---|
Windows | ✔️ | ✔️ | ✔️ | ✔️ |
Linux | ❌ | ❌ | ✔️ | ✔️ |
MacOS | ❌ | ✔️ | ✔️ | ❌ |
Under Linux this crate requires a tokio
runtime while the Window and MacOS backends are runtime agnostic.
MIT License