Cleanup sys config

This commit is contained in:
Luke D. Jones
2024-05-10 10:02:22 +12:00
parent 1b1d10c461
commit e62e7e8eca
6 changed files with 34 additions and 104 deletions

View File

@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Better more robust error handling in ROGCC - Better more robust error handling in ROGCC
- Try to better handle pre-2021 laptops with lightbar - Try to better handle pre-2021 laptops with lightbar
- Add more logging to try and trace the charge_control_end_threshold issue
## [v6.0.4] ## [v6.0.4]

View File

@@ -1,4 +1,4 @@
use config_traits::{StdConfig, StdConfigLoad3}; use config_traits::{StdConfig, StdConfigLoad1};
use rog_platform::cpu::CPUEPP; use rog_platform::cpu::CPUEPP;
use rog_platform::platform::ThrottlePolicy; use rog_platform::platform::ThrottlePolicy;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
@@ -106,7 +106,7 @@ impl StdConfig for Config {
} }
} }
impl StdConfigLoad3<Config472, Config506, Config507> for Config {} impl StdConfigLoad1<Config507> for Config {}
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub struct Config507 { pub struct Config507 {
@@ -157,79 +157,3 @@ impl From<Config507> for Config {
} }
} }
} }
#[derive(Deserialize, Serialize)]
pub struct Config506 {
/// Save charge limit for restoring on boot
pub charge_control_end_threshold: u8,
pub panel_od: bool,
pub mini_led_mode: bool,
pub disable_nvidia_powerd_on_battery: bool,
pub ac_command: String,
pub bat_command: String,
/// Restored on boot as well as when power is plugged
#[serde(skip)]
pub platform_policy_to_restore: ThrottlePolicy,
pub platform_policy_on_battery: ThrottlePolicy,
pub platform_policy_on_ac: ThrottlePolicy,
//
pub ppt_pl1_spl: Option<u8>,
pub ppt_pl2_sppt: Option<u8>,
pub ppt_fppt: Option<u8>,
pub ppt_apu_sppt: Option<u8>,
pub ppt_platform_sppt: Option<u8>,
pub nv_dynamic_boost: Option<u8>,
pub nv_temp_target: Option<u8>,
}
impl From<Config506> for Config {
fn from(c: Config506) -> Self {
Self {
charge_control_end_threshold: c.charge_control_end_threshold,
panel_od: c.panel_od,
boot_sound: false,
disable_nvidia_powerd_on_battery: c.disable_nvidia_powerd_on_battery,
ac_command: c.ac_command,
bat_command: c.bat_command,
mini_led_mode: c.mini_led_mode,
throttle_policy_linked_epp: true,
throttle_policy_on_battery: c.platform_policy_on_battery,
throttle_policy_on_ac: c.platform_policy_on_ac,
throttle_quiet_epp: CPUEPP::Power,
throttle_balanced_epp: CPUEPP::BalancePower,
throttle_performance_epp: CPUEPP::Performance,
ppt_pl1_spl: c.ppt_pl1_spl,
ppt_pl2_sppt: c.ppt_pl2_sppt,
ppt_fppt: c.ppt_fppt,
ppt_apu_sppt: c.ppt_apu_sppt,
ppt_platform_sppt: c.ppt_platform_sppt,
nv_dynamic_boost: c.nv_dynamic_boost,
nv_temp_target: c.nv_temp_target,
last_power_plugged: 0,
}
}
}
#[derive(Deserialize, Serialize)]
pub struct Config472 {
/// Save charge limit for restoring on boot
pub bat_charge_limit: u8,
pub panel_od: bool,
pub mini_led_mode: bool,
pub disable_nvidia_powerd_on_battery: bool,
pub ac_command: String,
pub bat_command: String,
}
impl From<Config472> for Config {
fn from(c: Config472) -> Self {
Self {
charge_control_end_threshold: c.bat_charge_limit,
panel_od: c.panel_od,
disable_nvidia_powerd_on_battery: true,
ac_command: c.ac_command,
bat_command: c.bat_command,
..Default::default()
}
}
}

View File

@@ -731,8 +731,9 @@ impl ReloadAndNotify for CtrlPlatform {
info!("asusd.ron updated externally, reloading and updating internal copy"); info!("asusd.ron updated externally, reloading and updating internal copy");
if self.power.has_charge_control_end_threshold() { if self.power.has_charge_control_end_threshold() {
self.power let limit = data.charge_control_end_threshold;
.set_charge_control_end_threshold(data.charge_control_end_threshold)?; warn!("setting charge_control_end_threshold to {limit}");
self.power.set_charge_control_end_threshold(limit)?;
self.charge_control_end_threshold_changed(signal_context) self.charge_control_end_threshold_changed(signal_context)
.await?; .await?;
} }
@@ -827,9 +828,9 @@ impl crate::Reloadable for CtrlPlatform {
ppt_reload!(nv_temp_target, "nv_temp_target"); ppt_reload!(nv_temp_target, "nv_temp_target");
if self.power.has_charge_control_end_threshold() { if self.power.has_charge_control_end_threshold() {
self.power.set_charge_control_end_threshold( let limit = self.config.lock().await.charge_control_end_threshold;
self.config.lock().await.charge_control_end_threshold, info!("reloading charge_control_end_threshold to {limit}");
)?; self.power.set_charge_control_end_threshold(limit)?;
} }
if let Ok(power_plugged) = self.power.get_online() { if let Ok(power_plugged) = self.power.get_online() {
@@ -847,11 +848,11 @@ impl crate::Reloadable for CtrlPlatform {
} }
impl CtrlPlatform { impl CtrlPlatform {
task_watch_item!(panel_od platform); task_watch_item!(panel_od "panel_od" platform);
task_watch_item!(mini_led_mode platform); task_watch_item!(mini_led_mode "mini_led_mode" platform);
task_watch_item!(charge_control_end_threshold power); task_watch_item!(charge_control_end_threshold "charge_control_end_threshold" power);
task_watch_item_notify!(boot_sound platform); task_watch_item_notify!(boot_sound platform);
@@ -901,12 +902,14 @@ impl CtrlTask for CtrlPlatform {
}) })
.ok(); .ok();
} }
if sleeping && platform1.power.has_charge_control_end_threshold() { // Don't store it on suspend, assume that the current config setting is desired
platform1.config.lock().await.charge_control_end_threshold = platform1 // if sleeping && platform1.power.has_charge_control_end_threshold() {
.power // platform1.config.lock().await.charge_control_end_threshold = platform1
.get_charge_control_end_threshold() // .power
.unwrap_or(100); // .get_charge_control_end_threshold()
} else if !sleeping && platform1.power.has_charge_control_end_threshold() { // .unwrap_or(100);
// } else
if !sleeping && platform1.power.has_charge_control_end_threshold() {
platform1 platform1
.power .power
.set_charge_control_end_threshold( .set_charge_control_end_threshold(

View File

@@ -13,7 +13,7 @@ use asusd::ctrl_platform::CtrlPlatform;
use asusd::ctrl_slash::trait_impls::CtrlSlashZbus; use asusd::ctrl_slash::trait_impls::CtrlSlashZbus;
use asusd::ctrl_slash::CtrlSlash; use asusd::ctrl_slash::CtrlSlash;
use asusd::{print_board_info, start_tasks, CtrlTask, DBUS_NAME}; use asusd::{print_board_info, start_tasks, CtrlTask, DBUS_NAME};
use config_traits::{StdConfig, StdConfigLoad3}; use config_traits::{StdConfig, StdConfigLoad1};
use log::{error, info}; use log::{error, info};
use zbus::fdo::ObjectManager; use zbus::fdo::ObjectManager;

View File

@@ -56,7 +56,7 @@ pub static DBUS_IFACE: &str = "org.asuslinux.Daemon";
/// // TODO: this is kind of useless if it can't trigger some action /// // TODO: this is kind of useless if it can't trigger some action
#[macro_export] #[macro_export]
macro_rules! task_watch_item { macro_rules! task_watch_item {
($name:ident $self_inner:ident) => { ($name:ident $name_str:literal $self_inner:ident) => {
concat_idents::concat_idents!(fn_name = watch_, $name { concat_idents::concat_idents!(fn_name = watch_, $name {
async fn fn_name( async fn fn_name(
&self, &self,
@@ -72,12 +72,15 @@ macro_rules! task_watch_item {
let mut buffer = [0; 32]; let mut buffer = [0; 32];
watch.into_event_stream(&mut buffer).unwrap().for_each(|_| async { watch.into_event_stream(&mut buffer).unwrap().for_each(|_| async {
if let Ok(value) = ctrl.$name() { // get new value from zbus method if let Ok(value) = ctrl.$name() { // get new value from zbus method
concat_idents::concat_idents!(notif_fn = $name, _changed { if ctrl.config.lock().await.$name != value {
ctrl.notif_fn(&signal_ctxt).await.ok(); log::debug!("{} was changed to {} externally", $name_str, value);
}); concat_idents::concat_idents!(notif_fn = $name, _changed {
let mut lock = ctrl.config.lock().await; ctrl.notif_fn(&signal_ctxt).await.ok();
lock.$name = value; });
lock.write(); let mut lock = ctrl.config.lock().await;
lock.$name = value;
lock.write();
}
} }
}).await; }).await;
}); });

View File

@@ -60,13 +60,12 @@ impl AsusPower {
info!("Found a battery"); info!("Found a battery");
if battery.is_none() { if battery.is_none() {
info!("Checking battery attributes"); info!("Checking battery attributes");
if device if let Some(current) =
.attribute_value("charge_control_end_threshold") device.attribute_value("charge_control_end_threshold")
.is_some()
{ {
info!( info!(
"Found battery power at {:?}, matched \ "Found battery power at {:?}, matched \
charge_control_end_threshold", charge_control_end_threshold. Current level: {current:?}",
device.sysname() device.sysname()
); );
battery = Some(device.syspath().to_path_buf()); battery = Some(device.syspath().to_path_buf());