Crate hidreport

Source
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§

hid
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.
types
A collection of standalone HID types that exist for type safety only. These are all simple wrappers around their underlying integer data type.

Structs§

ArrayField
An ArrayField represents a group of physical controls, see section 6.2.2.5.
Collection
Collections group Fields together into logical or physical groups.
CollectionId
A unique (within this report descriptor) identifier for a collection.
ConstantField
A ConstantField is one that represents a hid::MainItem with Constant data, see Section 6.2.2.4.
FieldId
A unique (within this report descriptor) identifier for a Field.
FieldValue
A wrapper around the value of a Field inside a HID Report’s byte array. This value may be signed, depending on the Field.
ReportDescriptor
A ReportDescriptor is the static set of Items that define how data from the device should be interpreted.
Usage
The usage of a Field defines the interpretation of a data value. See the hut crate for a list of known Usages.
UsageRange
Wrapper around the commonly used UsageMinimum and UsageMaximum.
VariableField
A VariableField represents a single physical control.

Enums§

Field
A single field inside a Report.
ParserError

Traits§

Report
A HID Input, Output or Feature Report.