Expand description
Parse USB HID report descriptors and pretty print them.
§Example
use hid_report::{parse, pretty_print};
let bytes = [
0x05, 0x0C, 0x09, 0x01, 0xA1, 0x01, 0x85, 0x02, 0x19,
0x00, 0x2A, 0x3C, 0x02, 0x15, 0x00, 0x26, 0x3C, 0x02,
0x95, 0x01, 0x75, 0x10, 0x81, 0x00, 0xC0,
];
let mut items = parse(bytes);
assert_eq!(items.next().unwrap().to_string(), "Usage Page (Consumer)");
assert_eq!(items.next().unwrap().to_string(), "Usage (Consumer Control)");
assert_eq!(items.next().unwrap().to_string(), "Collection (Application)");
assert_eq!(items.next().unwrap().to_string(), "Report ID (2)");
assert_eq!(items.next().unwrap().to_string(), "Usage Minimum (Undefined)");
assert_eq!(items.next().unwrap().to_string(), "Usage Maximum (AC Format)");
assert_eq!(items.next().unwrap().to_string(), "Logical Minimum (0)");
assert_eq!(items.next().unwrap().to_string(), "Logical Maximum (572)");
assert_eq!(items.next().unwrap().to_string(), "Report Count (1)");
assert_eq!(items.next().unwrap().to_string(), "Report Size (16)");
assert_eq!(
items.next().unwrap().to_string(),
"Input (Data, Array, Absolute, No Wrap, Linear, Preferred State, No Null Position)"
);
assert_eq!(items.next().unwrap().to_string(), "End Collection");
assert_eq!(items.next(), None);
let items = parse(bytes).collect::<Vec<_>>();
const EXPECTED: &str = indoc::indoc! {"
0x05, 0x0C // Usage Page (Consumer)
0x09, 0x01 // Usage (Consumer Control)
0xA1, 0x01 // Collection (Application)
0x85, 0x02 // Report ID (2)
0x19, 0x00 // Usage Minimum (Undefined)
0x2A, 0x3C, 0x02 // Usage Maximum (AC Format)
0x15, 0x00 // Logical Minimum (0)
0x26, 0x3C, 0x02 // Logical Maximum (572)
0x95, 0x01 // Report Count (1)
0x75, 0x10 // Report Size (16)
0x81, 0x00 // Input (Data, Array, Absolute, No Wrap, Linear, Preferred State, No Null Position)
0xC0 // End Collection"
};
assert_eq!(pretty_print(&items), EXPECTED);
Structs§
- Collection
- A meaningful grouping of Input, Output, and Feature items.
- Delimiter
- Defines the beginning or end of a set of local items (1 = open set, 0 = close set).
- Designator
Index - Determines the body part used for a control. Index points to a designator in the Physical descriptor.
- Designator
Maximum - Defines the index of the ending designator associated with an array or bitmap.
- Designator
Minimum - Defines the index of the starting designator associated with an array or bitmap.
- EndCollection
- A terminating item used to specify the end of a collection of items.
- Feature
- Describes device input and output not intended for consumption by the end user.
- Input
- Refers to the data from one or more similar controls on a device.
- Logical
Maximum - Extent value in logical units. This is the maximum value that a variable or array item will report.
- Logical
Minimum - Extent value in logical units. This is the minimum value that a variable or array item will report.
- Output
- Refers to the data to one or more similar controls on a device such as setting the position of a single axis or a group of levers (variable data). Or, it can represent data to one or more LEDs (array data).
- Physical
Maximum - Maximum value for the physical extent of a variable item. This represents the Logical Maximum with units applied to it.
- Physical
Minimum - Minimum value for the physical extent of a variable item. This represents the Logical Minimum with units applied to it.
- Pop
- Replaces the item state table with the top structure from the stack.
- Push
- Places a copy of the global item state table on the stack.
- Report
Count - Unsigned integer specifying the number of data fields for the item; determines how many fields are included in the report for this particular item (and consequently how many bits are added to the report).
- Report
Id - Unsigned value that specifies the Report ID.
- Report
Size - Unsigned integer specifying the size of the report fields in bits.
- Reserved
- Items that are reserved for future use.
- String
Index - String index for a String descriptor; allows a string to be associated with a particular item or control.
- String
Maximum - Specifies the last string index when assigning a group of sequential strings to controls in an array or bitmap.
- String
Minimum - Specifies the first string index when assigning a group of sequential strings to controls in an array or bitmap.
- Unit
- Unit values.
- Unit
Exponent - Value of the unit exponent in base 10.
- Usage
- Usage index for an item usage; represents a suggested usage for the item or collection.
- Usage
Maximum - Defines the ending usage associated with an array or bitmap.
- Usage
Minimum - Defines the starting usage associated with an array or bitmap.
- Usage
Page - Unsigned integer specifying the current Usage Page.
Enums§
- HidError
- Error type.
- Report
Item - Report items enumeration.
Functions§
- dump
- Dump items into a byte stream.
- parse
- Parse a byte stream into a report item iterator.
- parse_
strict - Parse a byte stream into a report item iterator in strict mode.
- pretty_
print - Print items to string in a pretty way.