Expand description
This crate provides parsing of HID Report Descriptors, including the hid module to inspect
a report descriptor in more detail. Check out the hut
crate for known HID Usages to make
sense of the various HID fields.
Entry point is usually ReportDescriptor::try_from(bytes)
:
let rdesc: ReportDescriptor = ReportDescriptor::try_from(bytes).unwrap();
for r in rdesc.input_reports() {
println!("Input Report with report ID: {:?}", r.report_id());
}
let input_report_bytes = read_from_device();
let report = rdesc.find_input_report(&input_report_bytes).unwrap();
println!("This is an input report for report ID: {:?}", report.report_id());
let field = report.fields().first().unwrap();
match field {
Field::Variable(var) => {
let val: u32 = var.extract(&input_report_bytes).unwrap().into();
println!("Field {:?} is of value {}", field, val);
}
Field::Array(arr) => {
let vals: Vec<u32> = arr.extract(&input_report_bytes).unwrap().iter().map(u32::from).collect();
println!("Field {:?} has values {:?}", field, vals);
}
Field::Constant(_) => {
println!("Field {:?} is <padding data>", field);
}
}
In this document and unless stated otherwise, a reference to “Section a.b.c” refers to the HID Device Class Definition for HID 1.11.
Re-exports§
pub use hid::CollectionItem as CollectionType;
pub use types::*;
Modules§
- A wrapper around the HID Core items. This module handles splitting a report descriptor byte stream into its individual components. Interpretation and/or analysis of the resulting Items is left to the caller.
- A collection of standalone HID types that exist for type safety only. These are all simple wrappers around their underlying integer data type.
Structs§
- An ArrayField represents a group of physical controls, see section 6.2.2.5.
- Collections group Fields together into logical or physical groups.
- A unique (within this report descriptor) identifier for a collection.
- A ConstantField is one that represents a hid::MainItem with Constant data, see Section 6.2.2.4.
- A unique (within this report descriptor) identifier for a Field.
- A ReportDescriptor is the static set of Items that define how data from the device should be interpreted.
- The usage of a Field defines the interpretation of a data value. See the
hut
crate for a list of known Usages. - Wrapper around the commonly used UsageMinimum and UsageMaximum.
- A VariableField represents a single physical control.
Enums§
- A single field inside a Report.
Traits§
- A HID Input, Output or Feature Report.