From 16700e55f4aee52201ded416f508963cf6b45c5e Mon Sep 17 00:00:00 2001 From: Luke Jones Date: Tue, 4 Feb 2025 17:48:52 +1300 Subject: [PATCH] ROGCC: refactor many more parts of the PPT settings --- asusd/src/asus_armoury.rs | 2 +- asusd/src/ctrl_platform.rs | 107 ++++++++++----------- rog-aura/src/aura_detection.rs | 2 +- rog-control-center/src/ui/setup_system.rs | 5 +- rog-control-center/ui/pages/system.slint | 8 ++ rog-control-center/ui/widgets/common.slint | 4 + 6 files changed, 69 insertions(+), 59 deletions(-) diff --git a/asusd/src/asus_armoury.rs b/asusd/src/asus_armoury.rs index b0ef4f6f..80d2af0d 100644 --- a/asusd/src/asus_armoury.rs +++ b/asusd/src/asus_armoury.rs @@ -417,7 +417,7 @@ pub async fn set_config_or_default( <&str>::from(name), i ); - config.write(); + // config.write(); } } } diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index 249c53c6..c38e4a6d 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -350,27 +350,17 @@ impl CtrlPlatform { } #[zbus(property)] - async fn set_platform_profile(&mut self, policy: PlatformProfile) -> Result<(), FdoErr> { + async fn set_platform_profile( + &mut self, + #[zbus(signal_context)] ctxt: SignalEmitter<'_>, + policy: PlatformProfile + ) -> Result<(), FdoErr> { // TODO: watch for external changes if self.platform.has_platform_profile() { let change_epp = self.config.lock().await.platform_profile_linked_epp; let epp = self.get_config_epp_for_throttle(policy).await; self.check_and_set_epp(epp, change_epp); - let power_plugged = self - .power - .get_online() - .map_err(|e| { - error!("Could not get power status: {e:?}"); - e - }) - .unwrap_or_default(); - self.config - .lock() - .await - .select_tunings(power_plugged == 1, policy) - .enabled = false; - self.config.lock().await.write(); // TODO: Need to get supported profiles here and ensure we translate to one self.platform @@ -378,7 +368,9 @@ impl CtrlPlatform { .map_err(|err| { warn!("platform_profile {}", err); FdoErr::Failed(format!("RogPlatform: platform_profile: {err}")) - }) + })?; + self.enable_ppt_group_changed(&ctxt).await?; + Ok(()) } else { Err(FdoErr::NotSupported( "RogPlatform: platform_profile not supported".to_owned() @@ -406,10 +398,11 @@ impl CtrlPlatform { #[zbus(property)] async fn set_platform_profile_on_battery( &mut self, + #[zbus(signal_context)] ctxt: SignalEmitter<'_>, policy: PlatformProfile ) -> Result<(), FdoErr> { self.config.lock().await.platform_profile_on_battery = policy; - self.set_platform_profile(policy).await?; + self.set_platform_profile(ctxt, policy).await?; self.config.lock().await.write(); Ok(()) } @@ -432,9 +425,13 @@ impl CtrlPlatform { } #[zbus(property)] - async fn set_platform_profile_on_ac(&mut self, policy: PlatformProfile) -> Result<(), FdoErr> { + async fn set_platform_profile_on_ac( + &mut self, + #[zbus(signal_context)] ctxt: SignalEmitter<'_>, + policy: PlatformProfile + ) -> Result<(), FdoErr> { self.config.lock().await.platform_profile_on_ac = policy; - self.set_platform_profile(policy).await?; + self.set_platform_profile(ctxt, policy).await?; self.config.lock().await.write(); Ok(()) } @@ -533,45 +530,41 @@ impl CtrlPlatform { .unwrap_or_default(); let profile: PlatformProfile = self.platform.get_platform_profile()?.into(); - // Clone to reduce blocking - let tuning = self - .config - .lock() - .await - .select_tunings(power_plugged == 1, profile) - .clone(); + if enable { + // Clone to reduce blocking + let tuning = self + .config + .lock() + .await + .select_tunings(power_plugged == 1, profile) + .clone(); - for attr in self.attributes.attributes() { - let name: FirmwareAttribute = attr.name().into(); - if name.is_ppt() { - // reset stored value - if let Some(tune) = self - .config - .lock() - .await - .select_tunings(power_plugged == 1, profile) - .group - .get_mut(&name) - { - let value = if !enable { - attr.default_value().clone() - } else { - tuning + for attr in self.attributes.attributes() { + let name: FirmwareAttribute = attr.name().into(); + if name.is_ppt() { + // reset stored value + if let Some(tune) = self + .config + .lock() + .await + .select_tunings(power_plugged == 1, profile) + .group + .get_mut(&name) + { + let value = tuning .group .get(&name) .map(|v| AttrValue::Integer(*v)) - .unwrap_or_else(|| attr.default_value().clone()) - }; - // restore default - attr.set_current_value(&value)?; - if let AttrValue::Integer(i) = value { - *tune = i + .unwrap_or_else(|| attr.default_value().clone()); + // restore default + attr.set_current_value(&value)?; + if let AttrValue::Integer(i) = value { + *tune = i + } } } } - } - - if !enable { + } else { // finally, reapply the profile to ensure acpi does the thingy self.platform.set_platform_profile(profile.into())?; } @@ -683,6 +676,7 @@ impl CtrlTask for CtrlPlatform { let platform1 = self.clone(); let platform2 = self.clone(); let platform3 = self.clone(); + let signal_ctxt_copy = signal_ctxt.clone(); self.create_sys_event_tasks( move |sleeping| { let platform1 = platform1.clone(); @@ -750,6 +744,7 @@ impl CtrlTask for CtrlPlatform { }, move |power_plugged| { let platform3 = platform3.clone(); + let signal_ctxt_copy = signal_ctxt.clone(); // power change async move { if platform3.platform.has_platform_profile() { @@ -781,6 +776,10 @@ impl CtrlTask for CtrlPlatform { profile ) .await; + platform3 + .enable_ppt_group_changed(&signal_ctxt_copy) + .await + .ok(); } } } @@ -789,7 +788,7 @@ impl CtrlTask for CtrlPlatform { // This spawns a new task for every item. // TODO: find a better way to manage this - self.watch_charge_control_end_threshold(signal_ctxt.clone()) + self.watch_charge_control_end_threshold(signal_ctxt_copy.clone()) .await?; let watch_platform_profile = self.platform.monitor_platform_profile()?; @@ -816,8 +815,8 @@ impl CtrlTask for CtrlPlatform { let change_epp = ctrl.config.lock().await.platform_profile_linked_epp; let epp = ctrl.get_config_epp_for_throttle(profile).await; ctrl.check_and_set_epp(epp, change_epp); - ctrl.platform_profile_changed(&signal_ctxt).await.ok(); - ctrl.enable_ppt_group_changed(&signal_ctxt).await.ok(); + ctrl.platform_profile_changed(&signal_ctxt_copy).await.ok(); + ctrl.enable_ppt_group_changed(&signal_ctxt_copy).await.ok(); let power_plugged = ctrl .power .get_online() diff --git a/rog-aura/src/aura_detection.rs b/rog-aura/src/aura_detection.rs index 6d088691..25648dc7 100644 --- a/rog-aura/src/aura_detection.rs +++ b/rog-aura/src/aura_detection.rs @@ -91,7 +91,7 @@ impl LedSupportFile { /// to ensure we match to *whole names* first before doing a glob match fn match_device(&self, device_name: &str, product_id: &str) -> LedSupportData { for config in self.0.iter().rev() { - if device_name.contains(&config.device_name) { + if device_name.eq_ignore_ascii_case(&config.device_name) { info!("Matched to {}", config.device_name); if !config.product_id.is_empty() { info!("Checking product ID"); diff --git a/rog-control-center/src/ui/setup_system.rs b/rog-control-center/src/ui/setup_system.rs index 41a6fe32..0529e751 100644 --- a/rog-control-center/src/ui/setup_system.rs +++ b/rog-control-center/src/ui/setup_system.rs @@ -21,7 +21,7 @@ const MINMAX: AttrMinMax = AttrMinMax { pub fn setup_system_page(ui: &MainWindow, _config: Arc>) { let conn = zbus::blocking::Connection::system().unwrap(); - let platform = PlatformProxyBlocking::new(&conn).unwrap(); + let platform = PlatformProxyBlocking::builder(&conn).build().unwrap(); // let armoury_attrs = // find_iface::("xyz.ljones.AsusArmoury").unwrap(); @@ -191,7 +191,6 @@ macro_rules! setup_value_watch { let mut tmp: AttrMinMax = handle.global::().getter(); tmp.$value_type = out $($conv)*; - dbg!(tmp.$value_type); concat_idents!(setter = set_, $property { handle.global::().setter(tmp); }); @@ -260,7 +259,7 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc>) tokio::spawn(async move { // Create the connections/proxies here to prevent future delays in process let conn = zbus::Connection::system().await.unwrap(); - let platform = PlatformProxy::new(&conn).await.unwrap(); + let platform = PlatformProxy::builder(&conn).build().await.unwrap(); set_ui_props_async!( handle, diff --git a/rog-control-center/ui/pages/system.slint b/rog-control-center/ui/pages/system.slint index 5f2a91c2..1c218d21 100644 --- a/rog-control-center/ui/pages/system.slint +++ b/rog-control-center/ui/pages/system.slint @@ -265,6 +265,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.ppt_pl1_spl.min; maximum: SystemPageData.ppt_pl1_spl.max; value: SystemPageData.ppt_pl1_spl.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_ppt_pl1_spl(); @@ -282,6 +283,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.ppt_pl2_sppt.min; maximum: SystemPageData.ppt_pl2_sppt.max; value: SystemPageData.ppt_pl2_sppt.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_ppt_pl2_sppt(); @@ -299,6 +301,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.ppt_pl3_fppt.min; maximum: SystemPageData.ppt_pl3_fppt.max; value: SystemPageData.ppt_pl3_fppt.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_ppt_pl3_fppt(); @@ -315,6 +318,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.ppt_fppt.min; maximum: SystemPageData.ppt_fppt.max; value: SystemPageData.ppt_fppt.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_ppt_fppt(); @@ -332,6 +336,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.ppt_apu_sppt.min; maximum: SystemPageData.ppt_apu_sppt.max; value: SystemPageData.ppt_apu_sppt.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_ppt_apu_sppt(); @@ -349,6 +354,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.ppt_platform_sppt.min; maximum: SystemPageData.ppt_platform_sppt.max; value: SystemPageData.ppt_platform_sppt.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_ppt_platform_sppt(); @@ -366,6 +372,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.nv_dynamic_boost.min; maximum: SystemPageData.nv_dynamic_boost.max; value: SystemPageData.nv_dynamic_boost.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_nv_dynamic_boost(); @@ -383,6 +390,7 @@ export component PageSystem inherits Rectangle { minimum: SystemPageData.nv_temp_target.min; maximum: SystemPageData.nv_temp_target.max; value: SystemPageData.nv_temp_target.current; + enabled <=> SystemPageData.enable_ppt_group; has_reset: true; cb_do_reset => { SystemPageData.cb_default_nv_temp_target(); diff --git a/rog-control-center/ui/widgets/common.slint b/rog-control-center/ui/widgets/common.slint index 5ec70af4..88b2b951 100644 --- a/rog-control-center/ui/widgets/common.slint +++ b/rog-control-center/ui/widgets/common.slint @@ -12,6 +12,7 @@ export component RogItem inherits Rectangle { export component SystemSlider inherits RogItem { in property title; in property text; + in-out property enabled; in-out property value; in-out property minimum; in-out property maximum; @@ -27,6 +28,7 @@ export component SystemSlider inherits RogItem { alignment: LayoutAlignment.stretch; padding-left: 10px; TouchArea { + enabled <=> root.enabled; clicked => { slider.value += 1; if slider.value > slider.maximum { @@ -57,6 +59,7 @@ export component SystemSlider inherits RogItem { // alignment: LayoutAlignment.end; padding-right: 20px; slider := Slider { + enabled <=> root.enabled; maximum: root.maximum; minimum: root.minimum; value <=> root.value; @@ -150,6 +153,7 @@ export component SystemSlider inherits RogItem { reset := HorizontalBox { if (has_reset): StandardButton { kind: StandardButtonKind.reset; + enabled <=> root.enabled; clicked => { reset_popup.show(); }