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

@@ -68,7 +68,7 @@ impl CtrlAnime {
let node = if usb.is_some() {
unsafe { Node::Usb(usb.unwrap_unchecked()) }
} else if hid.is_some() {
unsafe { Node::Hid(hid.unwrap_unchecked().0) }
unsafe { Node::Hid(hid.unwrap_unchecked()) }
} else {
return Err(RogError::Anime(AnimeError::NoDevice));
};

View File

@@ -366,7 +366,7 @@ mod tests {
};
let mut controller = CtrlKbdLed {
led_prod: AuraDevice::X19b6,
led_node: LEDNode::Rog(KeyboardLed::default(), HidRaw::new("id_product").unwrap().0),
led_node: LEDNode::Rog(KeyboardLed::default(), HidRaw::new("id_product").unwrap()),
supported_data: supported_basic_modes,
per_key_mode_active: false,
config,
@@ -404,7 +404,7 @@ mod tests {
};
let mut controller = CtrlKbdLed {
led_prod: AuraDevice::X19b6,
led_node: LEDNode::Rog(KeyboardLed::default(), HidRaw::new("id_product").unwrap().0),
led_node: LEDNode::Rog(KeyboardLed::default(), HidRaw::new("id_product").unwrap()),
supported_data: supported_basic_modes,
per_key_mode_active: false,
config,

View File

@@ -85,13 +85,13 @@ impl AuraManager {
};
if action == "remove" {
dbg!("REMOVING");
if let Some(_) = parent.attribute_value("idProduct") {
info!("AuraManager removing: {path:?}");
let conn_copy = conn_copy.clone();
let interfaces_copy = interfaces.clone();
tokio::spawn(async move {
let mut interfaces = interfaces_copy.lock().await;
let mut interfaces = interfaces_copy.lock().await; // hold until completed
interfaces.remove(&path);
let res = conn_copy
.object_server()
.remove::<CtrlAuraZbus, _>(&path)
@@ -101,13 +101,11 @@ impl AuraManager {
e
})?;
info!("AuraManager removed: {path:?}, {res}");
interfaces.remove(&path);
debug!("Removed {path:?}");
Ok::<(), RogError>(())
});
}
} else if action == "add" {
dbg!("ADDING");
let id_product =
if let Some(id_product) = parent.attribute_value("idProduct") {
id_product.to_string_lossy().to_string()
@@ -135,7 +133,7 @@ impl AuraManager {
};
let dev_node = if let Some(dev_node) = event.devnode() {
dev_node
dev_node.to_owned()
} else {
continue;
};
@@ -145,21 +143,23 @@ impl AuraManager {
{
// bah... shitty clone TODO: fix
let data_clone = data.clone();
if let Ok(mut ctrl) =
CtrlKbdLed::from_hidraw(raw, path.clone(), &data)
{
info!(
"AuraManager found device at: {dev_node:?}, {path:?}"
);
let mut conn_copy = conn_copy.clone();
let interfaces_copy = interfaces.clone();
//
tokio::spawn(async move {
let mut interfaces = interfaces_copy.lock().await;
if interfaces.contains(&path) {
debug!("Already a ctrl at {path:?}");
return Ok(());
}
let mut conn_copy = conn_copy.clone();
let interfaces_copy = interfaces.clone();
//
tokio::spawn(async move {
let mut interfaces = interfaces_copy.lock().await;
if interfaces.contains(&path) {
debug!("Already a ctrl at {path:?}");
return Ok(());
}
if let Ok(mut ctrl) =
CtrlKbdLed::from_hidraw(raw, path.clone(), &data_clone)
{
info!(
"AuraManager found device at: {dev_node:?}, \
{path:?}"
);
debug!("Starting Aura at {path}");
interfaces.insert(path.clone());
let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?;
@@ -170,10 +170,10 @@ impl AuraManager {
let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?;
start_tasks(zbus, &mut conn_copy, sig_ctx, &path)
.await?;
Ok::<(), RogError>(())
}); // Can't get result from here due to
// MonitorSocket
}
}
Ok::<(), RogError>(())
}); // Can't get result from here due to
// MonitorSocket
}
} else {
warn!("idProduct:{id_product:?} is unknown, not using")

View File

@@ -24,7 +24,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
return Err("RogError::NoAuraKeyboard".into());
}
let node = usb_node.unwrap().0;
let node = usb_node.unwrap();
let mut packet: [u8; 64] = [
0x5a, 0xd1, 0x0d, 0x0e, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

View File

@@ -26,7 +26,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
return Err("RogError::NoAuraKeyboard".into());
}
let node = usb_node.unwrap().0;
let node = usb_node.unwrap();
// node.write_bytes(&[0x5a, 0xd1, 0x0a, 0x01])?; // TODO: need to CHECK
println!("Set mouse mode for 10 seconds");

View File

@@ -24,7 +24,7 @@ pub fn main() -> Result<(), Box<dyn Error>> {
return Err("RogError::NoAuraKeyboard".into());
}
let node = usb_node.unwrap().0;
let node = usb_node.unwrap();
// node.write_bytes(&[0x5a, 0xd1, 0x0a, 0x01])?; // TODO: need to CHECK
println!("Set mouse mode for 10 seconds");

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(),
});
}
}
}