Shift init actions up a few calls to prevent over-eager init

This commit is contained in:
Luke D. Jones
2024-03-23 23:27:26 +13:00
parent 4b34ab83fb
commit 637360095c
7 changed files with 43 additions and 51 deletions

View File

@@ -22,7 +22,7 @@ pub struct HidRaw {
}
impl HidRaw {
pub fn new(id_product: &str) -> Result<(Self, Device)> {
pub fn new(id_product: &str) -> Result<Self> {
let mut enumerator = udev::Enumerator::new().map_err(|err| {
warn!("{}", err);
PlatformError::Udev("enumerator failed".into(), err)
@@ -47,17 +47,12 @@ impl HidRaw {
if parent_id == id_product {
if let Some(dev_node) = endpoint.devnode() {
info!("Using device at: {:?} for hidraw control", dev_node);
return Ok((
Self {
file: RefCell::new(
OpenOptions::new().write(true).open(dev_node)?,
),
devfs_path: dev_node.to_owned(),
prod_id: id_product.to_string(),
syspath: endpoint.syspath().into(),
},
usb_device,
));
return Ok(Self {
file: RefCell::new(OpenOptions::new().write(true).open(dev_node)?),
devfs_path: dev_node.to_owned(),
prod_id: id_product.to_string(),
syspath: endpoint.syspath().into(),
});
}
}
}
@@ -70,15 +65,12 @@ impl HidRaw {
"Using device at: {:?} for <TODO: label control> control",
dev_node
);
return Ok((
Self {
file: RefCell::new(OpenOptions::new().write(true).open(dev_node)?),
devfs_path: dev_node.to_owned(),
prod_id: id_product.to_string(),
syspath: endpoint.syspath().into(),
},
endpoint,
));
return Ok(Self {
file: RefCell::new(OpenOptions::new().write(true).open(dev_node)?),
devfs_path: dev_node.to_owned(),
prod_id: id_product.to_string(),
syspath: endpoint.syspath().into(),
});
}
}
}