diff --git a/asusd/src/asus_armoury.rs b/asusd/src/asus_armoury.rs index b673fe83..2766f60d 100644 --- a/asusd/src/asus_armoury.rs +++ b/asusd/src/asus_armoury.rs @@ -210,19 +210,7 @@ impl AsusArmouryAttribute { e })?; - if matches!( - self.name(), - FirmwareAttribute::PptPl1Spl - | FirmwareAttribute::PptPl2Sppt - | FirmwareAttribute::PptPl3Fppt - | FirmwareAttribute::PptFppt - | FirmwareAttribute::PptApuSppt - | FirmwareAttribute::PptPlatformSppt - | FirmwareAttribute::NvDynamicBoost - | FirmwareAttribute::NvTempTarget - | FirmwareAttribute::DgpuBaseTgp - | FirmwareAttribute::DgpuTgp - ) { + if self.name().is_ppt() { let profile: ThrottlePolicy = ThrottlePolicy::from_str(self.platform.get_platform_profile()?.as_str())?; diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 36250b87..72c0bb28 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use config_traits::StdConfig; use log::{debug, error, info, warn}; +use rog_platform::asus_armoury::{AttrValue, FirmwareAttribute, FirmwareAttributes}; use rog_platform::cpu::{CPUControl, CPUGovernor, CPUEPP}; use rog_platform::platform::{Properties, RogPlatform, ThrottlePolicy}; use rog_platform::power::AsusPower; @@ -43,14 +44,14 @@ pub struct CtrlPlatform { power: AsusPower, platform: RogPlatform, cpu_control: Option, - config: Arc> + config: Arc>, } impl CtrlPlatform { pub fn new( config: Arc>, config_path: &Path, - signal_context: SignalEmitter<'static> + signal_context: SignalEmitter<'static>, ) -> Result { let platform = RogPlatform::new()?; let power = AsusPower::new()?; @@ -63,7 +64,7 @@ impl CtrlPlatform { config, cpu_control: CPUControl::new() .map_err(|e| error!("Couldn't get CPU control sysfs: {e}")) - .ok() + .ok(), }; let mut inotify_self = ret_self.clone(); @@ -82,7 +83,7 @@ impl CtrlPlatform { inotify::WatchMask::MODIFY | inotify::WatchMask::CLOSE_WRITE | inotify::WatchMask::ATTRIB - | inotify::WatchMask::CREATE + | inotify::WatchMask::CREATE, ) .inspect_err(|e| { if e.kind() == std::io::ErrorKind::NotFound { @@ -124,7 +125,7 @@ impl CtrlPlatform { if limit > 0 && std::mem::replace( &mut self.config.lock().await.charge_control_end_threshold, - limit + limit, ) != limit { self.power @@ -206,7 +207,7 @@ impl CtrlPlatform { match throttle { ThrottlePolicy::Balanced => self.config.lock().await.throttle_balanced_epp, ThrottlePolicy::Performance => self.config.lock().await.throttle_performance_epp, - ThrottlePolicy::Quiet => self.config.lock().await.throttle_quiet_epp + ThrottlePolicy::Quiet => self.config.lock().await.throttle_quiet_epp, } } @@ -303,7 +304,7 @@ impl CtrlPlatform { async fn one_shot_full_charge(&self) -> Result<(), FdoErr> { let base_limit = std::mem::replace( &mut self.config.lock().await.charge_control_end_threshold, - 100 + 100, ); if base_limit != 100 { self.power.set_charge_control_end_threshold(100)?; @@ -317,7 +318,7 @@ impl CtrlPlatform { /// If fan-curves are supported will also activate a fan curve for profile. async fn next_throttle_thermal_policy( &mut self, - #[zbus(signal_context)] ctxt: SignalEmitter<'_> + #[zbus(signal_context)] ctxt: SignalEmitter<'_>, ) -> Result<(), FdoErr> { let policy: ThrottlePolicy = platform_get_value!(self, throttle_thermal_policy, "throttle_thermal_policy") @@ -337,7 +338,7 @@ impl CtrlPlatform { Ok(self.throttle_thermal_policy_changed(&ctxt).await?) } else { Err(FdoErr::NotSupported( - "RogPlatform: throttle_thermal_policy not supported".to_owned() + "RogPlatform: throttle_thermal_policy not supported".to_owned(), )) } } @@ -364,7 +365,7 @@ impl CtrlPlatform { }) } else { Err(FdoErr::NotSupported( - "RogPlatform: throttle_thermal_policy not supported".to_owned() + "RogPlatform: throttle_thermal_policy not supported".to_owned(), )) } } @@ -389,7 +390,7 @@ impl CtrlPlatform { #[zbus(property)] async fn set_throttle_policy_on_battery( &mut self, - policy: ThrottlePolicy + policy: ThrottlePolicy, ) -> Result<(), FdoErr> { self.config.lock().await.throttle_policy_on_battery = policy; self.set_throttle_thermal_policy(policy).await?; @@ -496,7 +497,7 @@ impl ReloadAndNotify for CtrlPlatform { async fn reload_and_notify( &mut self, signal_context: &SignalEmitter<'static>, - data: Self::Data + data: Self::Data, ) -> Result<(), RogError> { let mut config = self.config.lock().await; if *config != data { @@ -526,7 +527,7 @@ impl ReloadAndNotify for CtrlPlatform { let epp = match profile { ThrottlePolicy::Balanced => data.throttle_balanced_epp, ThrottlePolicy::Performance => data.throttle_performance_epp, - ThrottlePolicy::Quiet => data.throttle_quiet_epp + ThrottlePolicy::Quiet => data.throttle_quiet_epp, }; warn!("setting epp to {epp:?}"); self.check_and_set_epp(epp, true); @@ -597,7 +598,7 @@ impl CtrlTask for CtrlPlatform { platform1 .power .set_charge_control_end_threshold( - platform1.config.lock().await.charge_control_end_threshold + platform1.config.lock().await.charge_control_end_threshold, ) .ok(); } @@ -631,7 +632,7 @@ impl CtrlTask for CtrlPlatform { platform2 .power .set_charge_control_end_threshold( - lock.base_charge_control_end_threshold + lock.base_charge_control_end_threshold, ) .map_err(|err| { warn!("CtrlCharge: charge_control_end_threshold {}", err); @@ -661,7 +662,7 @@ impl CtrlTask for CtrlPlatform { platform3.restore_charge_limit().await; } } - } + }, ) .await; @@ -673,6 +674,9 @@ impl CtrlTask for CtrlPlatform { let watch_throttle_thermal_policy = self.platform.monitor_throttle_thermal_policy()?; let ctrl = self.clone(); + // Need a copy here, not ideal. But first use in asus_armoury.rs is + // moved to zbus + let attrs = FirmwareAttributes::new(); tokio::spawn(async move { use futures_lite::StreamExt; let mut buffer = [0; 32]; @@ -691,6 +695,38 @@ impl CtrlTask for CtrlPlatform { let change_epp = ctrl.config.lock().await.throttle_policy_linked_epp; let epp = ctrl.get_config_epp_for_throttle(profile).await; ctrl.check_and_set_epp(epp, change_epp); + ctrl.throttle_thermal_policy_changed(&signal_ctxt) + .await + .ok(); + for attr in attrs.attributes().iter() { + let name: FirmwareAttribute = attr.name().into(); + if name.is_ppt() { + let mut do_default = false; + if let Some(tunings) = + ctrl.config.lock().await.profile_tunings.get(&profile) + { + if let Some(tune) = tunings.get(&name) { + attr.set_current_value(AttrValue::Integer(*tune)) + .map_err(|e| { + error!("Failed to set {}: {e}", <&str>::from(name)); + }) + .ok(); + } else { + do_default = true; + } + } else { + do_default = true; + } + if do_default { + let default = attr.default_value().clone(); + attr.set_current_value(default) + .map_err(|e| { + error!("Failed to set {}: {e}", <&str>::from(name)); + }) + .ok(); + } + } + } } } } diff --git a/rog-control-center/src/ui/setup_system.rs b/rog-control-center/src/ui/setup_system.rs index c9990f31..45f60a77 100644 --- a/rog-control-center/src/ui/setup_system.rs +++ b/rog-control-center/src/ui/setup_system.rs @@ -16,7 +16,7 @@ use crate::{set_ui_callbacks, set_ui_props_async, AttrMinMax, MainWindow, System const MINMAX: AttrMinMax = AttrMinMax { min: 0, max: 0, - val: -1.0, + val: -1.0 }; pub fn setup_system_page(ui: &MainWindow, _config: Arc>) { diff --git a/rog-platform/src/asus_armoury.rs b/rog-platform/src/asus_armoury.rs index 61ab3203..82e9c131 100644 --- a/rog-platform/src/asus_armoury.rs +++ b/rog-platform/src/asus_armoury.rs @@ -292,6 +292,24 @@ pub enum FirmwareAttribute { None = 24 } +impl FirmwareAttribute { + pub fn is_ppt(&self) -> bool { + matches!( + self, + FirmwareAttribute::PptPl1Spl + | FirmwareAttribute::PptPl2Sppt + | FirmwareAttribute::PptPl3Fppt + | FirmwareAttribute::PptFppt + | FirmwareAttribute::PptApuSppt + | FirmwareAttribute::PptPlatformSppt + | FirmwareAttribute::NvDynamicBoost + | FirmwareAttribute::NvTempTarget + | FirmwareAttribute::DgpuBaseTgp + | FirmwareAttribute::DgpuTgp + ) + } +} + impl From<&str> for FirmwareAttribute { fn from(s: &str) -> Self { match s {