Unset battery charge limit properly, fix #127

This commit is contained in:
NGnius (Graham) 2023-10-09 11:19:29 -04:00
parent ebfebb6ea7
commit 46659a474d
3 changed files with 19 additions and 1 deletions

View file

@ -174,7 +174,7 @@ impl Default for Base {
super::DeveloperMessage {
id: 1,
title: "Welcome".to_owned(),
body: "Thanks for installing PowerTools! For more information, please check the wiki. For bugs and requests, please create an issue on GitHub.".to_owned(),
body: "Thanks for installing PowerTools! For more information, please check the wiki. For bugs and requests, please create an issue.".to_owned(),
url: Some("https://git.ngni.us/NG-SD-Plugins/PowerTools/wiki".to_owned()),
}
],

View file

@ -586,6 +586,7 @@ impl OnPowerEvent for Battery {
.unwrap_or_else(|mut e| errors.append(&mut e));
let attr_exists = MAX_BATTERY_CHARGE_LEVEL_ATTR.exists(&*self.sysfs_hwmon);
log::info!("Does battery limit attribute (max_battery_charge_level) exist? {}", attr_exists);
let mut charge_limit_set_now = false;
for ev in &mut self.events {
if attr_exists {
if let EventTrigger::BatteryAbove(level) = ev.trigger {
@ -597,12 +598,27 @@ impl OnPowerEvent for Battery {
setting: crate::settings::SettingVariant::Battery,
}
));
self.state.charge_limit_set = true;
charge_limit_set_now = true;
}
}
}
ev.on_power_event(new_mode)
.unwrap_or_else(|mut e| errors.append(&mut e));
}
if self.state.charge_limit_set != charge_limit_set_now {
// only true when charge_limit_set is false and self.state.charge_limit_set is true
self.state.charge_limit_set = false;
if attr_exists {
self.sysfs_hwmon.set(MAX_BATTERY_CHARGE_LEVEL_ATTR, 100)
.unwrap_or_else(|e| errors.push(
SettingError {
msg: format!("Failed to reset (write to) {:?}: {}", MAX_BATTERY_CHARGE_LEVEL_ATTR, e),
setting: crate::settings::SettingVariant::Battery,
}
));
}
}
if errors.is_empty() {
Ok(())
} else {

View file

@ -3,6 +3,7 @@ pub struct Battery {
pub charge_rate_set: bool,
pub charge_mode_set: bool,
pub charger_state: ChargeState,
pub charge_limit_set: bool,
}
impl std::default::Default for Battery {
@ -11,6 +12,7 @@ impl std::default::Default for Battery {
charge_rate_set: true,
charge_mode_set: true,
charger_state: ChargeState::Unknown,
charge_limit_set: true,
}
}
}