diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f91cdb..0a3dba62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 - 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] diff --git a/asusd/src/config.rs b/asusd/src/config.rs index d5d98748..e238a419 100644 --- a/asusd/src/config.rs +++ b/asusd/src/config.rs @@ -1,4 +1,4 @@ -use config_traits::{StdConfig, StdConfigLoad3}; +use config_traits::{StdConfig, StdConfigLoad1}; use rog_platform::cpu::CPUEPP; use rog_platform::platform::ThrottlePolicy; use serde_derive::{Deserialize, Serialize}; @@ -106,7 +106,7 @@ impl StdConfig for Config { } } -impl StdConfigLoad3 for Config {} +impl StdConfigLoad1 for Config {} #[derive(Deserialize, Serialize)] pub struct Config507 { @@ -157,79 +157,3 @@ impl From 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, - pub ppt_pl2_sppt: Option, - pub ppt_fppt: Option, - pub ppt_apu_sppt: Option, - pub ppt_platform_sppt: Option, - pub nv_dynamic_boost: Option, - pub nv_temp_target: Option, -} - -impl From 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 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() - } - } -} diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 173e7192..bf160272 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -731,8 +731,9 @@ impl ReloadAndNotify for CtrlPlatform { info!("asusd.ron updated externally, reloading and updating internal copy"); if self.power.has_charge_control_end_threshold() { - self.power - .set_charge_control_end_threshold(data.charge_control_end_threshold)?; + let limit = 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) .await?; } @@ -827,9 +828,9 @@ impl crate::Reloadable for CtrlPlatform { ppt_reload!(nv_temp_target, "nv_temp_target"); if self.power.has_charge_control_end_threshold() { - self.power.set_charge_control_end_threshold( - self.config.lock().await.charge_control_end_threshold, - )?; + let limit = 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() { @@ -847,11 +848,11 @@ impl crate::Reloadable for 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); @@ -901,12 +902,14 @@ impl CtrlTask for CtrlPlatform { }) .ok(); } - if sleeping && platform1.power.has_charge_control_end_threshold() { - platform1.config.lock().await.charge_control_end_threshold = platform1 - .power - .get_charge_control_end_threshold() - .unwrap_or(100); - } else if !sleeping && platform1.power.has_charge_control_end_threshold() { + // Don't store it on suspend, assume that the current config setting is desired + // if sleeping && platform1.power.has_charge_control_end_threshold() { + // platform1.config.lock().await.charge_control_end_threshold = platform1 + // .power + // .get_charge_control_end_threshold() + // .unwrap_or(100); + // } else + if !sleeping && platform1.power.has_charge_control_end_threshold() { platform1 .power .set_charge_control_end_threshold( diff --git a/asusd/src/daemon.rs b/asusd/src/daemon.rs index 973e728e..7571343d 100644 --- a/asusd/src/daemon.rs +++ b/asusd/src/daemon.rs @@ -13,7 +13,7 @@ use asusd::ctrl_platform::CtrlPlatform; use asusd::ctrl_slash::trait_impls::CtrlSlashZbus; use asusd::ctrl_slash::CtrlSlash; 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 zbus::fdo::ObjectManager; diff --git a/asusd/src/lib.rs b/asusd/src/lib.rs index 6c41f6c6..f423d611 100644 --- a/asusd/src/lib.rs +++ b/asusd/src/lib.rs @@ -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 #[macro_export] 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 { async fn fn_name( &self, @@ -72,12 +72,15 @@ macro_rules! task_watch_item { let mut buffer = [0; 32]; watch.into_event_stream(&mut buffer).unwrap().for_each(|_| async { if let Ok(value) = ctrl.$name() { // get new value from zbus method - concat_idents::concat_idents!(notif_fn = $name, _changed { - ctrl.notif_fn(&signal_ctxt).await.ok(); - }); - let mut lock = ctrl.config.lock().await; - lock.$name = value; - lock.write(); + if ctrl.config.lock().await.$name != value { + log::debug!("{} was changed to {} externally", $name_str, value); + concat_idents::concat_idents!(notif_fn = $name, _changed { + ctrl.notif_fn(&signal_ctxt).await.ok(); + }); + let mut lock = ctrl.config.lock().await; + lock.$name = value; + lock.write(); + } } }).await; }); diff --git a/rog-platform/src/power.rs b/rog-platform/src/power.rs index 9c5ef43f..f4f02d0a 100644 --- a/rog-platform/src/power.rs +++ b/rog-platform/src/power.rs @@ -60,13 +60,12 @@ impl AsusPower { info!("Found a battery"); if battery.is_none() { info!("Checking battery attributes"); - if device - .attribute_value("charge_control_end_threshold") - .is_some() + if let Some(current) = + device.attribute_value("charge_control_end_threshold") { info!( "Found battery power at {:?}, matched \ - charge_control_end_threshold", + charge_control_end_threshold. Current level: {current:?}", device.sysname() ); battery = Some(device.syspath().to_path_buf());