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§

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§

Enums§

Traits§

  • A HID Input, Output or Feature Report.