Run cargo fmt
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use anyhow::{Result, anyhow};
|
||||
use anyhow::{anyhow, Result};
|
||||
use plain::Plain;
|
||||
use smallvec::SmallVec;
|
||||
use std::convert::TryInto;
|
||||
@@ -9,7 +9,7 @@ pub enum HidClassType {
|
||||
#[default]
|
||||
HID = 0x21,
|
||||
Report,
|
||||
Physical
|
||||
Physical,
|
||||
}
|
||||
|
||||
#[repr(C, packed)]
|
||||
@@ -48,41 +48,45 @@ impl HidDescriptor {
|
||||
if (kind != HidClassType::HID as u8) {
|
||||
return Err(anyhow!("This is not a hid descriptor"));
|
||||
}
|
||||
|
||||
|
||||
let num_descriptors = bytes[5];
|
||||
|
||||
if (length != Self::HID_DESC_FIXED_SIZE + num_descriptors * Self::HID_CLASS_DESC_SIZE) {
|
||||
return Err(anyhow!("Len doesn't match the given number of descriptors ({num_descriptors})"));
|
||||
return Err(anyhow!(
|
||||
"Len doesn't match the given number of descriptors ({num_descriptors})"
|
||||
));
|
||||
}
|
||||
|
||||
let mut descriptors = SmallVec::<[HidClassDescriptor; 1]>::with_capacity(num_descriptors as usize);
|
||||
|
||||
|
||||
let mut descriptors =
|
||||
SmallVec::<[HidClassDescriptor; 1]>::with_capacity(num_descriptors as usize);
|
||||
|
||||
for i in 0..num_descriptors {
|
||||
match HidClassDescriptor::from_bytes(&bytes[(Self::HID_DESC_FIXED_SIZE + i*Self::HID_CLASS_DESC_SIZE) as usize..(Self::HID_DESC_FIXED_SIZE + (i+1)*Self::HID_CLASS_DESC_SIZE) as usize]) {
|
||||
match HidClassDescriptor::from_bytes(
|
||||
&bytes[(Self::HID_DESC_FIXED_SIZE + i * Self::HID_CLASS_DESC_SIZE) as usize
|
||||
..(Self::HID_DESC_FIXED_SIZE + (i + 1) * Self::HID_CLASS_DESC_SIZE) as usize],
|
||||
) {
|
||||
Ok(desc) => descriptors.push(*desc),
|
||||
Err(e) => return Err(anyhow!("{e:?}")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(Self {
|
||||
length,
|
||||
kind,
|
||||
hid_spec_release: u16::from_ne_bytes(bytes[2..4].try_into()?),
|
||||
country_code: bytes[4],
|
||||
num_descriptors,
|
||||
descriptors
|
||||
descriptors,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
pub fn get_report_desc(&self) -> Result<HidClassDescriptor> {
|
||||
for desc in self.descriptors.iter() {
|
||||
match desc.desc_type {
|
||||
HidClassType::Report => return Ok(*desc),
|
||||
_ => ()
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
return Err(anyhow!("No Report descriptor found"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ use xhcid_interface::{
|
||||
|
||||
use crate::descs::HidDescriptor;
|
||||
|
||||
mod reqs;
|
||||
mod descs;
|
||||
mod reqs;
|
||||
|
||||
fn send_key_event(display: &mut ProducerHandle, usage_page: u16, usage: u16, pressed: bool) {
|
||||
let scancode = match usage_page {
|
||||
|
||||
Reference in New Issue
Block a user