pub struct ArrayField {
pub bits: Range<usize>,
pub report_count: ReportCount,
pub logical_minimum: LogicalMinimum,
pub logical_maximum: LogicalMaximum,
pub physical_minimum: Option<PhysicalMinimum>,
pub physical_maximum: Option<PhysicalMaximum>,
pub unit: Option<Unit>,
pub unit_exponent: Option<UnitExponent>,
pub collections: Vec<Collection>,
/* private fields */
}Expand description
An ArrayField represents a group of physical controls, see section 6.2.2.5.
An array provides an alternate means for describing the data returned from a group of buttons. Arrays are more efficient, if less flexible than variable items. Rather than returning a single bit for each button in the group, an array returns an index in each field that corresponds to the pressed button
Fields§
§bits: Range<usize>§report_count: ReportCount§logical_minimum: LogicalMinimum§logical_maximum: LogicalMaximum§physical_minimum: Option<PhysicalMinimum>§physical_maximum: Option<PhysicalMaximum>§unit: Option<Unit>§unit_exponent: Option<UnitExponent>§collections: Vec<Collection>Implementations§
Source§impl ArrayField
impl ArrayField
Sourcepub fn usages(&self) -> &[Usage]
pub fn usages(&self) -> &[Usage]
Returns the set of usages for this field. This is the
inclusive range of UsageMinimum..=UsageMaximum
as defined for this field.
In most cases it’s better to use usage_range() instead.
Sourcepub fn usage_range(&self) -> UsageRange
pub fn usage_range(&self) -> UsageRange
Returns the UsageRange for this field.
Sourcepub fn is_signed(&self) -> bool
pub fn is_signed(&self) -> bool
Returns true if this field contains signed values,. i.e. the LogicalMinimum is less than zero.
Sourcepub fn extract(&self, bytes: &[u8]) -> Result<Vec<FieldValue>, ParserError>
pub fn extract(&self, bytes: &[u8]) -> Result<Vec<FieldValue>, ParserError>
Extract this field’s value as FieldValue from a report’s bytes. The value is extracted as its correct bit size, the returned FieldValue can then be casted in to a u32, i32, etc. via the From trait.
if field.is_signed() {
println!("Signed values: {:?}", field
.extract(bytes)
.unwrap()
.iter()
.map(i32::from)
.collect::<Vec<i32>>());
} else {
println!("Unsigned values: {:?}", field
.extract(bytes)
.unwrap()
.iter()
.map(u32::from)
.collect::<Vec<u32>>());
}
Sourcepub fn extract_one(
&self,
bytes: &[u8],
idx: usize,
) -> Result<FieldValue, ParserError>
pub fn extract_one( &self, bytes: &[u8], idx: usize, ) -> Result<FieldValue, ParserError>
Extract a single value from this array. See ArrayField::extract.
The index must be less than Self::report_count.
Trait Implementations§
Source§impl Clone for ArrayField
impl Clone for ArrayField
Source§fn clone(&self) -> ArrayField
fn clone(&self) -> ArrayField
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more