Expand description
§async-hid
A Rust library for asynchronously interacting with HID devices.
This crate aims to 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.
§Example
use async_hid::{AccessMode, DeviceInfo, HidResult};
use simple_logger::SimpleLogger;
use futures_lite::StreamExt;
#[pollster::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(())
}
§Platform Support
Operating System | Underlying API |
---|---|
Windows | Win32 (Windows.Win32.Devices ) |
Windows | WinRT (Windows.Devices.HumanInterfaceDevice ) |
Linux | hidraw |
MacOs | IOHIDManager |
Under Windows this crate uses either win32
(default) or winrt
feature for backend.
§Async
The amount of asynchronicity that each OS provides varies. The following table gives a rough overview which calls utilize async under the hood.
enumerate | open | read_input_report | write_output_report | |
---|---|---|---|---|
Windows (Win32) | ❌️ | ️️ ❌️ | ✔️ | ✔️ |
Windows (WinRT) | ✔️ | ✔️ | ✔️ | ✔️ |
Linux | ❌ | ❌ | ✔️ | ✔️ |
MacOS | ❌ | ✔️ | ✔️ | ❌ |
Under Linux this crate uses either async-io
(default) or tokio
feature for the async functionality.
§Planned Features
- Reading / Writing feature reports
§License
MIT License
Structs§
- Device
- A HID device that was detected by calling HidBackend::enumerate
- Device
Info - A struct containing basic information about a device
- Device
Reader - A reader than can be used to read input reports from a HID device using AsyncHidRead::read_input_report
- Device
Writer - A writer than can be used to write output reports from a HID device using AsyncHidWrite::write_output_report
- HidBackend
- The main entry point of this library
Enums§
- Backend
Type - All available backends for the current platform
- Device
Event - Device
Id - A platform-specific identifier for a device.
- HidError
- The main error type of this library Currently mostly a wrapper around a platform specific error
Traits§
- Async
HidRead - Provides functionality for reading from HID devices
- Async
HidWrite - Provides functionality for writing to HID devices
Type Aliases§
- Device
Reader Writer - Combination of DeviceReader and DeviceWriter
- HidResult
- Specialized result type used for many functions in this library