aura debugging

This commit is contained in:
Luke D. Jones
2024-03-24 10:55:20 +13:00
parent 637360095c
commit 739a0ffa63

View File

@@ -54,6 +54,7 @@ impl AuraManager {
// detect all plugged in aura devices (eventually) // detect all plugged in aura devices (eventually)
let interfaces = Arc::new(Mutex::new(interfaces)); let interfaces = Arc::new(Mutex::new(interfaces));
let mut count = 0;
tokio::spawn(async move { tokio::spawn(async move {
let mut monitor = MonitorBuilder::new()?.match_subsystem("hidraw")?.listen()?; let mut monitor = MonitorBuilder::new()?.match_subsystem("hidraw")?.listen()?;
let mut poll = Poll::new()?; let mut poll = Poll::new()?;
@@ -65,10 +66,20 @@ impl AuraManager {
if poll.poll(&mut events, None).is_err() { if poll.poll(&mut events, None).is_err() {
continue; continue;
} }
// collect and sort so remove events are first
// let mut events: Vec<udev::Event> = monitor.iter().filter(|e|
// &*e.action().unwrap_or_default() == "remove").collect();
// let mut adds: Vec<udev::Event> = monitor.iter().filter(|e|
// &*e.action().unwrap_or_default() == "add").collect();
// events.append(&mut adds);
dbg!("LOOPED", count);
count += 1;
for event in monitor.iter() { for event in monitor.iter() {
if event.parent_with_subsystem("hidraw").is_err() { if event.parent_with_subsystem("hidraw").is_err() {
continue; continue;
} }
if let Some(parent) = if let Some(parent) =
event.parent_with_subsystem_devtype("usb", "usb_device")? event.parent_with_subsystem_devtype("usb", "usb_device")?
{ {
@@ -78,20 +89,33 @@ impl AuraManager {
continue; continue;
}; };
let id_product =
if let Some(id_product) = parent.attribute_value("idProduct") {
id_product.to_string_lossy()
} else {
continue;
};
let aura_device = AuraDevice::from(&*id_product);
if aura_device == AuraDevice::Unknown {
warn!("idProduct:{id_product:?} is unknown, not using");
continue;
}
let path = if let Some(path) = dbus_path_for_dev(&parent) { let path = if let Some(path) = dbus_path_for_dev(&parent) {
path path
} else { } else {
continue; continue;
}; };
dbg!(action, &aura_device, &path);
if action == "remove" { if action == "remove" {
if let Some(_) = parent.attribute_value("idProduct") {
info!("AuraManager removing: {path:?}"); info!("AuraManager removing: {path:?}");
let conn_copy = conn_copy.clone(); let conn_copy = conn_copy.clone();
let interfaces_copy = interfaces.clone(); let interfaces_copy = interfaces.clone();
tokio::spawn(async move { tokio::spawn(async move {
let mut interfaces = interfaces_copy.lock().await; // hold until completed let mut interfaces = interfaces_copy.lock().await; // hold until completed
interfaces.remove(&path); dbg!(&interfaces);
if interfaces.remove(&path) {
let res = conn_copy let res = conn_copy
.object_server() .object_server()
.remove::<CtrlAuraZbus, _>(&path) .remove::<CtrlAuraZbus, _>(&path)
@@ -101,21 +125,16 @@ impl AuraManager {
e e
})?; })?;
info!("AuraManager removed: {path:?}, {res}"); info!("AuraManager removed: {path:?}, {res}");
debug!("Removed {path:?}"); }
dbg!(&interfaces);
Ok::<(), RogError>(()) Ok::<(), RogError>(())
}); });
}
} else if action == "add" { } else if action == "add" {
let id_product =
if let Some(id_product) = parent.attribute_value("idProduct") {
id_product.to_string_lossy().to_string()
} else {
continue;
};
if let Some(p2) = event.parent() { if let Some(p2) = event.parent() {
if let Some(driver) = p2.driver() { if let Some(driver) = p2.driver() {
// There is a tree of devices added so filter by driver // There is a tree of devices added so filter by driver
if driver != "asus" { if driver != "asus" {
debug!("{id_product:?} driver was not asus, skipping");
continue; continue;
} }
} else { } else {
@@ -123,9 +142,6 @@ impl AuraManager {
} }
} }
// try conversion to known idProduct
let aura_device = AuraDevice::from(id_product.as_str());
if aura_device != AuraDevice::Unknown {
let path = if let Some(path) = dbus_path_for_dev(&parent) { let path = if let Some(path) = dbus_path_for_dev(&parent) {
path path
} else { } else {
@@ -148,6 +164,7 @@ impl AuraManager {
// //
tokio::spawn(async move { tokio::spawn(async move {
let mut interfaces = interfaces_copy.lock().await; let mut interfaces = interfaces_copy.lock().await;
dbg!(&interfaces);
if interfaces.contains(&path) { if interfaces.contains(&path) {
debug!("Already a ctrl at {path:?}"); debug!("Already a ctrl at {path:?}");
return Ok(()); return Ok(());
@@ -156,10 +173,8 @@ impl AuraManager {
CtrlKbdLed::from_hidraw(raw, path.clone(), &data_clone) CtrlKbdLed::from_hidraw(raw, path.clone(), &data_clone)
{ {
info!( info!(
"AuraManager found device at: {dev_node:?}, \ "AuraManager found device at: {dev_node:?}, {path:?}"
{path:?}"
); );
debug!("Starting Aura at {path}"); debug!("Starting Aura at {path}");
interfaces.insert(path.clone()); interfaces.insert(path.clone());
let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?; let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?;
@@ -168,16 +183,13 @@ impl AuraManager {
let zbus = CtrlAuraZbus::new(ctrl, sig_ctx); let zbus = CtrlAuraZbus::new(ctrl, sig_ctx);
// Now add it to device list // Now add it to device list
let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?; let sig_ctx = CtrlAuraZbus::signal_context(&conn_copy)?;
start_tasks(zbus, &mut conn_copy, sig_ctx, &path) start_tasks(zbus, &mut conn_copy, sig_ctx, &path).await?;
.await?;
} }
dbg!(&interfaces);
Ok::<(), RogError>(()) Ok::<(), RogError>(())
}); // Can't get result from here due to }); // Can't get result from here due to
// MonitorSocket // MonitorSocket
} }
} else {
warn!("idProduct:{id_product:?} is unknown, not using")
}
} }
} }
} }