mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
@@ -23,9 +23,14 @@ pub struct AsusPower {
|
||||
}
|
||||
|
||||
impl AsusPower {
|
||||
/// When checking for battery this will look in order:
|
||||
/// - if attr `manufacturer` contains `asus`
|
||||
/// - if attr `charge_control_end_threshold` exists and `energy_full_design` >= 50 watt
|
||||
/// - if syspath end conatins `BAT`
|
||||
/// - if attr `type` is `battery` (last resort)
|
||||
pub fn new() -> Result<Self> {
|
||||
let mut mains = PathBuf::new();
|
||||
let mut battery = PathBuf::new();
|
||||
let mut battery = None;
|
||||
let mut usb = None;
|
||||
|
||||
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
||||
@@ -48,13 +53,45 @@ impl AsusPower {
|
||||
mains = device.syspath().to_path_buf();
|
||||
}
|
||||
Some("Battery") => {
|
||||
// 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 {:?}", device.sysname());
|
||||
battery = device.syspath().to_path_buf();
|
||||
// Priortised list of checks
|
||||
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
|
||||
.attribute_value("charge_control_end_threshold")
|
||||
.is_some()
|
||||
{
|
||||
if let Some(m) = device.attribute_value("energy_full_design") {
|
||||
if let Ok(num) = m.to_string_lossy().parse::<u32>() {
|
||||
if num >= 50_000_000 {
|
||||
info!("Found battery power at {:?}, matched charge_control_end_threshold and energy_full_design", device.sysname());
|
||||
battery = Some(device.syspath().to_path_buf());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if device.sysname().to_string_lossy().contains("BAT") {
|
||||
info!(
|
||||
"Found battery power at {:?}, sysfs path ended with BAT<n>",
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,11 +104,17 @@ impl AsusPower {
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
mains,
|
||||
battery,
|
||||
usb,
|
||||
})
|
||||
if let Some(battery) = battery {
|
||||
return Ok(Self {
|
||||
mains,
|
||||
battery,
|
||||
usb,
|
||||
});
|
||||
}
|
||||
|
||||
Err(PlatformError::MissingFunction(
|
||||
"Did not find a battery".to_owned(),
|
||||
))
|
||||
}
|
||||
|
||||
attr_u8!("charge_control_end_threshold", battery);
|
||||
|
||||
Reference in New Issue
Block a user