From 192e5ccaa3291428c7b1792a3dcd32a66116b7ba Mon Sep 17 00:00:00 2001 From: Luke Jones Date: Mon, 3 Mar 2025 16:31:43 +1300 Subject: [PATCH] ROGCC: better handling of platform profile --- .cargo-husky/hooks/post-commit | 2 +- CHANGELOG.md | 5 + Cargo.lock | 28 ++--- Cargo.toml | 2 +- asusd/src/config.rs | 4 + asusd/src/ctrl_platform.rs | 24 ++-- rog-control-center/src/types/fan_types.rs | 2 + rog-control-center/src/ui/setup_fans.rs | 1 - rog-control-center/src/ui/setup_system.rs | 116 ++++++++++++++++++-- rog-control-center/ui/pages/system.slint | 7 +- rog-control-center/ui/types/fan_types.slint | 3 +- rog-platform/src/cpu.rs | 1 + rog-platform/src/platform.rs | 9 +- rog-profiles/src/lib.rs | 32 ++++++ 14 files changed, 190 insertions(+), 46 deletions(-) diff --git a/.cargo-husky/hooks/post-commit b/.cargo-husky/hooks/post-commit index 71482a77..b284b344 100755 --- a/.cargo-husky/hooks/post-commit +++ b/.cargo-husky/hooks/post-commit @@ -3,7 +3,7 @@ set -e ROOT_DIR=$(git rev-parse --show-toplevel) AURA_DATA="${ROOT_DIR}/rog-aura/data/aura_support.ron" -SPEC_FILE="${ROOT_DIR}/distro-packaging/fedora/asusctl.spec" +SPEC_FILE="${ROOT_DIR}/distro-packaging/asusctl.spec" TRANSLATION="${ROOT_DIR}/rog-control-center/translations/en/rog-control-center.po" VERSION=$(grep -Pm1 'version = "(\d+.\d+.\d+.*)"' "${ROOT_DIR}/Cargo.toml" | cut -d'"' -f2) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39bdf006..b9fd7499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +## [v6.1.9] + +### Changed +- ROGCC: better handling of platform profiles + ## [v6.1.8] ### Changed diff --git a/Cargo.lock b/Cargo.lock index adda2706..3d4083f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,7 +158,7 @@ checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b" [[package]] name = "asusctl" -version = "6.1.8" +version = "6.1.9" dependencies = [ "dmi_id", "env_logger", @@ -177,7 +177,7 @@ dependencies = [ [[package]] name = "asusd" -version = "6.1.8" +version = "6.1.9" dependencies = [ "cargo-husky", "concat-idents", @@ -204,7 +204,7 @@ dependencies = [ [[package]] name = "asusd-user" -version = "6.1.8" +version = "6.1.9" dependencies = [ "config-traits", "dirs", @@ -918,7 +918,7 @@ dependencies = [ [[package]] name = "config-traits" -version = "6.1.8" +version = "6.1.9" dependencies = [ "log", "ron", @@ -1310,7 +1310,7 @@ dependencies = [ [[package]] name = "dmi_id" -version = "6.1.8" +version = "6.1.9" dependencies = [ "log", "udev 0.8.0", @@ -4542,7 +4542,7 @@ dependencies = [ [[package]] name = "rog-control-center" -version = "6.1.8" +version = "6.1.9" dependencies = [ "asusd", "concat-idents", @@ -4573,7 +4573,7 @@ dependencies = [ [[package]] name = "rog_anime" -version = "6.1.8" +version = "6.1.9" dependencies = [ "dmi_id", "gif 0.12.0", @@ -4587,7 +4587,7 @@ dependencies = [ [[package]] name = "rog_aura" -version = "6.1.8" +version = "6.1.9" dependencies = [ "dmi_id", "log", @@ -4598,7 +4598,7 @@ dependencies = [ [[package]] name = "rog_dbus" -version = "6.1.8" +version = "6.1.9" dependencies = [ "asusd", "rog_anime", @@ -4612,7 +4612,7 @@ dependencies = [ [[package]] name = "rog_platform" -version = "6.1.8" +version = "6.1.9" dependencies = [ "concat-idents", "inotify", @@ -4625,7 +4625,7 @@ dependencies = [ [[package]] name = "rog_profiles" -version = "6.1.8" +version = "6.1.9" dependencies = [ "log", "rog_platform", @@ -4636,7 +4636,7 @@ dependencies = [ [[package]] name = "rog_scsi" -version = "6.1.8" +version = "6.1.9" dependencies = [ "ron", "serde", @@ -4646,7 +4646,7 @@ dependencies = [ [[package]] name = "rog_simulators" -version = "6.1.8" +version = "6.1.9" dependencies = [ "log", "rog_anime", @@ -4656,7 +4656,7 @@ dependencies = [ [[package]] name = "rog_slash" -version = "6.1.8" +version = "6.1.9" dependencies = [ "dmi_id", "serde", diff --git a/Cargo.toml b/Cargo.toml index 13b2f9fa..02b28291 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "6.1.8" +version = "6.1.9" rust-version = "1.82" license = "MPL-2.0" readme = "README.md" diff --git a/asusd/src/config.rs b/asusd/src/config.rs index 5189c57b..3a6b6c0d 100644 --- a/asusd/src/config.rs +++ b/asusd/src/config.rs @@ -43,6 +43,8 @@ pub struct Config { /// The energy_performance_preference for this platform profile pub profile_balanced_epp: CPUEPP, /// The energy_performance_preference for this platform profile + pub profile_custom_epp: CPUEPP, + /// The energy_performance_preference for this platform profile pub profile_performance_epp: CPUEPP, pub ac_profile_tunings: Tunings, pub dc_profile_tunings: Tunings, @@ -79,6 +81,7 @@ impl Default for Config { profile_quiet_epp: CPUEPP::Power, profile_balanced_epp: CPUEPP::BalancePower, profile_performance_epp: CPUEPP::Performance, + profile_custom_epp: CPUEPP::Performance, ac_profile_tunings: HashMap::default(), dc_profile_tunings: HashMap::default(), armoury_settings: HashMap::default(), @@ -167,6 +170,7 @@ impl From for Config { profile_quiet_epp: c.profile_quiet_epp, profile_balanced_epp: c.profile_balanced_epp, profile_performance_epp: c.profile_performance_epp, + profile_custom_epp: c.profile_performance_epp, last_power_plugged: c.last_power_plugged, ac_profile_tunings: HashMap::default(), dc_profile_tunings: HashMap::default(), diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index a1af1f11..3c1b1e1f 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -212,6 +212,7 @@ impl CtrlPlatform { PlatformProfile::Performance => self.config.lock().await.profile_performance_epp, PlatformProfile::Quiet => self.config.lock().await.profile_quiet_epp, PlatformProfile::LowPower => self.config.lock().await.profile_quiet_epp, + PlatformProfile::Custom => self.config.lock().await.profile_custom_epp, } } @@ -354,16 +355,7 @@ impl CtrlPlatform { #[zbus(property)] fn platform_profile(&self) -> Result { - let choices = self.platform.get_platform_profile_choices()?; let policy: PlatformProfile = self.platform.get_platform_profile()?.as_str().into(); - let policy = if policy == PlatformProfile::LowPower - && choices.contains(&PlatformProfile::LowPower) - { - PlatformProfile::Quiet - } else { - policy - }; - Ok(policy) } @@ -382,13 +374,12 @@ impl CtrlPlatform { self.config.lock().await.write(); let choices = self.platform.get_platform_profile_choices()?; - let policy = if policy == PlatformProfile::Quiet - && choices.contains(&PlatformProfile::LowPower) - { - PlatformProfile::LowPower - } else { - policy - }; + if !choices.contains(&PlatformProfile::LowPower) { + return Err(FdoErr::NotSupported(format!( + "RogPlatform: platform_profile: {} not supported", + policy + ))); + } self.platform .set_platform_profile(policy.into()) @@ -651,6 +642,7 @@ impl ReloadAndNotify for CtrlPlatform { PlatformProfile::Performance => data.profile_performance_epp, PlatformProfile::Quiet => data.profile_quiet_epp, PlatformProfile::LowPower => data.profile_quiet_epp, + PlatformProfile::Custom => data.profile_custom_epp, }; warn!("setting epp to {epp:?}"); self.check_and_set_epp(epp, true); diff --git a/rog-control-center/src/types/fan_types.rs b/rog-control-center/src/types/fan_types.rs index 0ec9630e..e286cfac 100644 --- a/rog-control-center/src/types/fan_types.rs +++ b/rog-control-center/src/types/fan_types.rs @@ -10,6 +10,7 @@ impl From for PlatformProfile { Profile::Performance => PlatformProfile::Performance, Profile::Quiet => PlatformProfile::Quiet, Profile::LowPower => PlatformProfile::LowPower, + Profile::Custom => PlatformProfile::Custom, } } } @@ -21,6 +22,7 @@ impl From for Profile { PlatformProfile::Performance => Profile::Performance, PlatformProfile::Quiet => Profile::Quiet, PlatformProfile::LowPower => Profile::LowPower, + PlatformProfile::Custom => Profile::Custom, } } } diff --git a/rog-control-center/src/ui/setup_fans.rs b/rog-control-center/src/ui/setup_fans.rs index 8fcbd922..0b72461b 100644 --- a/rog-control-center/src/ui/setup_fans.rs +++ b/rog-control-center/src/ui/setup_fans.rs @@ -138,7 +138,6 @@ pub fn setup_fan_curve_page(ui: &MainWindow, _config: Arc>) { else { return; }; - dbg!(&quiet); update_fan_data(handle, balanced, perf, quiet); let handle_next1 = handle_copy.clone(); diff --git a/rog-control-center/src/ui/setup_system.rs b/rog-control-center/src/ui/setup_system.rs index f34b1478..b6c0ec06 100644 --- a/rog-control-center/src/ui/setup_system.rs +++ b/rog-control-center/src/ui/setup_system.rs @@ -6,7 +6,7 @@ use rog_dbus::asus_armoury::AsusArmouryProxy; use rog_dbus::zbus_platform::{PlatformProxy, PlatformProxyBlocking}; use rog_platform::asus_armoury::FirmwareAttribute; use rog_platform::platform::Properties; -use slint::ComponentHandle; +use slint::{ComponentHandle, Model, ModelRc, SharedString, VecModel}; use super::show_toast; use crate::config::Config; @@ -297,7 +297,59 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc>) charge_control_end_threshold ); - set_ui_props_async!(handle, platform, SystemPageData, platform_profile); + let platform_copy = platform.clone(); + if let Ok(mut value) = platform.platform_profile_choices().await { + handle + .upgrade_in_event_loop(move |handle| { + value.sort(); + let translate: Vec = handle + .global::() + .get_platform_profile_choices() + .iter() + .collect(); + let mut indexes = Vec::new(); + let strings: Vec = value + .iter() + .filter_map(|p| { + let index = i32::from(*p) as usize; + if index < translate.len() { + indexes.push(index as i32); + Some(translate[index].clone()) + } else { + None + } + }) + .collect(); + let choices = ModelRc::new(VecModel::from(strings)); + handle + .global::() + .set_platform_profile_choices(choices); + handle + .global::() + .set_platform_profile_indexes(ModelRc::from(indexes.as_slice())); + + // Set current only after setting the choices up + let handle = handle.as_weak(); + tokio::spawn(async move { + if let Ok(value) = platform_copy.platform_profile().await { + let profile_value = ::from(value); + handle + .upgrade_in_event_loop(move |handle| { + if let Some(position) = + indexes.iter().position(|&index| index == profile_value) + { + handle + .global::() + .set_platform_profile(position as i32); + } + }) + .ok(); + } + }); + }) + .ok(); + } + set_ui_props_async!( handle, platform, @@ -333,6 +385,54 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc>) handle .upgrade_in_event_loop(move |handle| { debug!("Setting up system page standard callbacks"); + + let handle_copy = handle.as_weak(); + let proxy_copy = platform_copy.clone(); + handle + .global::() + .on_cb_platform_profile(move |value| { + let proxy_copy = proxy_copy.clone(); + let handle_copy = handle_copy.clone(); + tokio::spawn(async move { + show_toast( + format!("Throttle policy set to {}", value).into(), + "Setting Throttle policy failed".into(), + handle_copy, + proxy_copy.set_platform_profile(value.into()).await, + ); + }); + }); + + let handle_copy = handle.as_weak(); + let proxy_copy = platform_copy.clone(); + // spawn required since the while let never exits + tokio::spawn(async move { + let mut x = proxy_copy.receive_platform_profile_changed().await; + use futures_util::StreamExt; + while let Some(e) = x.next().await { + if let Ok(out) = e.get().await { + handle_copy + .upgrade_in_event_loop(move |handle| { + let indexes = handle + .global::() + .get_platform_profile_indexes(); + handle + .global::() + .set_platform_profile(out as i32); + let profile_value = ::from(out); + if let Some(position) = + indexes.iter().position(|index| index == profile_value) + { + handle + .global::() + .set_platform_profile(position as i32); + } + }) + .ok(); + } + } + }); + set_ui_callbacks!(handle, SystemPageData(as bool), platform_copy.enable_ppt_group(as bool), @@ -346,12 +446,12 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc>) "Charge limit successfully set to {}", "Setting Charge limit failed" ); - set_ui_callbacks!(handle, - SystemPageData(as i32), - platform_copy.platform_profile(.into()), - "Throttle policy set to {}", - "Setting Throttle policy failed" - ); + // set_ui_callbacks!(handle, + // SystemPageData(as i32), + // platform_copy.platform_profile(.into()), + // "Throttle policy set to {}", + // "Setting Throttle policy failed" + // ); set_ui_callbacks!(handle, SystemPageData(as i32), platform_copy.profile_balanced_epp(.into()), diff --git a/rog-control-center/ui/pages/system.slint b/rog-control-center/ui/pages/system.slint index 1f831e9d..fa977bc9 100644 --- a/rog-control-center/ui/pages/system.slint +++ b/rog-control-center/ui/pages/system.slint @@ -17,7 +17,10 @@ export global SystemPageData { in-out property charge_control_end_threshold: 30; callback cb_charge_control_end_threshold(/* charge limit */ int); in-out property platform_profile: 0; - in-out property <[string]> platform_profile_choices: [@tr("Balanced"), @tr("Performance"), @tr("Quiet")]; + in-out property <[string]> platform_profile_choices: [@tr("Balanced"), @tr("Performance"), @tr("Quiet"), @tr("LowPower")]; + // The dropdown list index is used to index in to this and find the correct + // value for platform profile + in-out property <[int]> platform_profile_indexes: [0, 1, 2, 3]; callback cb_platform_profile(int); in-out property <[string]> energy_performance_choices: [ @tr("Default"), @@ -169,7 +172,7 @@ export component PageSystem inherits Rectangle { current_value: SystemPageData.platform_profile_choices[SystemPageData.platform_profile]; model <=> SystemPageData.platform_profile_choices; selected => { - SystemPageData.cb_platform_profile(SystemPageData.platform_profile) + SystemPageData.cb_platform_profile(SystemPageData.platform_profile_indexes[SystemPageData.platform_profile]) } } diff --git a/rog-control-center/ui/types/fan_types.slint b/rog-control-center/ui/types/fan_types.slint index a224e1af..5577f3b6 100644 --- a/rog-control-center/ui/types/fan_types.slint +++ b/rog-control-center/ui/types/fan_types.slint @@ -5,13 +5,14 @@ export enum Profile { Performance, Quiet, LowPower, + Custom } export enum FanType { CPU, Middle, GPU, - } +} export global FanPageData { in-out property <[Profile]> available_profiles: [Profile.Balanced, Profile.Performance, Profile.Quiet]; diff --git a/rog-platform/src/cpu.rs b/rog-platform/src/cpu.rs index 46432458..332bf6a4 100644 --- a/rog-platform/src/cpu.rs +++ b/rog-platform/src/cpu.rs @@ -208,6 +208,7 @@ impl From for CPUEPP { PlatformProfile::Performance => CPUEPP::Performance, PlatformProfile::Quiet => CPUEPP::Power, PlatformProfile::LowPower => CPUEPP::Power, + PlatformProfile::Custom => CPUEPP::BalancePower, } } } diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index 07e47668..481c66f6 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -186,6 +186,7 @@ impl Display for GpuMode { Debug, PartialEq, Eq, + Ord, PartialOrd, Hash, Clone, @@ -199,6 +200,7 @@ pub enum PlatformProfile { Performance = 1, Quiet = 2, LowPower = 3, + Custom = 4, } impl PlatformProfile { @@ -212,8 +214,7 @@ impl PlatformProfile { Self::Quiet } } - Self::Quiet => Self::Balanced, - Self::LowPower => Self::Balanced, + Self::Quiet | Self::LowPower | Self::Custom => Self::Balanced, } } } @@ -225,6 +226,7 @@ impl From for PlatformProfile { 1 => Self::Performance, 2 => Self::Quiet, 3 => Self::LowPower, + 4 => Self::Custom, _ => { warn!("Unknown number for PlatformProfile: {}", num); Self::Balanced @@ -246,6 +248,7 @@ impl From<&PlatformProfile> for &str { PlatformProfile::Performance => "performance", PlatformProfile::Quiet => "quiet", PlatformProfile::LowPower => "low-power", + PlatformProfile::Custom => "custom", } } } @@ -277,6 +280,7 @@ impl std::str::FromStr for PlatformProfile { "performance" => Ok(PlatformProfile::Performance), "quiet" => Ok(PlatformProfile::Quiet), "low-power" => Ok(PlatformProfile::LowPower), + "custom" => Ok(PlatformProfile::Custom), _ => Err(PlatformError::NotSupported), } } @@ -289,6 +293,7 @@ impl From<&str> for PlatformProfile { "performance" => PlatformProfile::Performance, "quiet" => PlatformProfile::Quiet, "low-power" => PlatformProfile::LowPower, + "custom" => PlatformProfile::Custom, _ => { warn!("{profile} is unknown, using ThrottlePolicy::Balanced"); PlatformProfile::Balanced diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index 6be5d32c..1000923c 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -113,6 +113,7 @@ pub struct FanCurveProfiles { pub balanced: Vec, pub performance: Vec, pub quiet: Vec, + pub custom: Vec, } impl FanCurveProfiles { @@ -146,6 +147,7 @@ impl FanCurveProfiles { PlatformProfile::Balanced => self.balanced = curves, PlatformProfile::Performance => self.performance = curves, PlatformProfile::Quiet | PlatformProfile::LowPower => self.quiet = curves, + PlatformProfile::Custom => self.custom = curves, } Ok(()) } @@ -182,6 +184,7 @@ impl FanCurveProfiles { PlatformProfile::Balanced => &mut self.balanced, PlatformProfile::Performance => &mut self.performance, PlatformProfile::Quiet | PlatformProfile::LowPower => &mut self.quiet, + PlatformProfile::Custom => &mut self.custom, }; for fan in fans.iter().filter(|f| !f.enabled) { debug!("write_profile_curve_to_platform: writing profile:{profile}, {fan:?}"); @@ -213,6 +216,11 @@ impl FanCurveProfiles { curve.enabled = enabled; } } + PlatformProfile::Custom => { + for curve in self.custom.iter_mut() { + curve.enabled = enabled; + } + } } } @@ -247,6 +255,14 @@ impl FanCurveProfiles { } } } + PlatformProfile::Custom => { + for curve in self.custom.iter_mut() { + if curve.fan == fan { + curve.enabled = enabled; + break; + } + } + } } } @@ -255,6 +271,7 @@ impl FanCurveProfiles { PlatformProfile::Balanced => &self.balanced, PlatformProfile::Performance => &self.performance, PlatformProfile::Quiet | PlatformProfile::LowPower => &self.quiet, + PlatformProfile::Custom => &self.custom, } } @@ -281,6 +298,13 @@ impl FanCurveProfiles { } } } + PlatformProfile::Custom => { + for this_curve in self.custom.iter() { + if this_curve.fan == pu { + return Some(this_curve); + } + } + } } None } @@ -315,6 +339,14 @@ impl FanCurveProfiles { } } } + PlatformProfile::Custom => { + for this_curve in self.custom.iter_mut() { + if this_curve.fan == curve.fan { + *this_curve = curve; + break; + } + } + } } Ok(()) }