From 414d610bd242d97d9a0d1e36a02624bab3f29206 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sat, 27 Aug 2022 11:18:15 +1200 Subject: [PATCH] Test battery search --- rog-platform/src/power.rs | 40 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/rog-platform/src/power.rs b/rog-platform/src/power.rs index aa0ca66c..d74633ff 100644 --- a/rog-platform/src/power.rs +++ b/rog-platform/src/power.rs @@ -47,30 +47,22 @@ impl AsusPower { PlatformError::Udev("scan_devices failed".into(), err) })? { if let Some(attr) = device.attribute_value("type") { - match attr.to_os_string().as_os_str().to_str() { - Some("Mains") => { + info!("Power: Checking {:?}", device.syspath()); + match attr.to_string_lossy().to_ascii_lowercase().trim() { + "mains" => { info!("Found mains power at {:?}", device.sysname()); mains = device.syspath().to_path_buf(); } - Some("Battery") => { + "battery" => { // Priortised list of checks + info!("Found a battery"); if battery.is_none() { - // This check required due to an instance where another "not" - // battery can be found - if let Some(m) = device.attribute_value("manufacturer") { - // Should always be ASUSTeK, but match on a lowercase part to be sure - if m.to_string_lossy().to_lowercase().contains("asus") { - info!( - "Found battery power at {:?}, matched manufacturer", - device.sysname() - ); - battery = Some(device.syspath().to_path_buf()); - } - } else if device + info!("Checking battery attributes"); + if device .attribute_value("charge_control_end_threshold") .is_some() { - info!("Found battery power at {:?}, matched charge_control_end_threshold and energy_full_design", device.sysname()); + info!("Found battery power at {:?}, matched charge_control_end_threshold", device.sysname()); battery = Some(device.syspath().to_path_buf()); } else if device.sysname().to_string_lossy().starts_with("BAT") { info!( @@ -78,18 +70,16 @@ impl AsusPower { device.sysname() ); battery = Some(device.syspath().to_path_buf()); - } else if let Some(m) = device.attribute_value("type") { - if m.to_string_lossy().to_lowercase().contains("battery") { - info!( - "Last resort: Found battery power at {:?}", - device.sysname() - ); - battery = Some(device.syspath().to_path_buf()); - } + } else { + info!( + "Last resort: Found battery power at {:?} using type = Battery", + device.sysname() + ); + battery = Some(device.syspath().to_path_buf()); } } } - Some("USB") => { + "usb" => { info!("Found USB-C power at {:?}", device.sysname()); usb = Some(device.syspath().to_path_buf()); }