PPT restor defaults (WIP)

This commit is contained in:
Luke D. Jones
2025-01-19 12:02:22 +13:00
parent f9cebf9221
commit 2d6d669c22
9 changed files with 94 additions and 41 deletions

View File

@@ -4,6 +4,7 @@
### Changed ### Changed
- Per-AC/DC, per-profile tunings enabled (Battery vs AC power + platform profile) - Per-AC/DC, per-profile tunings enabled (Battery vs AC power + platform profile)
- Add ability to restore PPT defaults (WIP)
## [v6.1.0-rc4] ## [v6.1.0-rc4]

View File

@@ -96,6 +96,9 @@ pub struct GraphicsCommand {
pub struct ArmouryCommand { pub struct ArmouryCommand {
#[options(help = "print help message")] #[options(help = "print help message")]
pub help: bool, pub help: bool,
#[options(free)] #[options(
free,
help = "append each value name followed by the value to set. `-1` sets to default"
)]
pub free: Vec<String> pub free: Vec<String>
} }

View File

@@ -9,7 +9,7 @@ use aura_cli::{LedPowerCommand1, LedPowerCommand2};
use dmi_id::DMIID; use dmi_id::DMIID;
use fan_curve_cli::FanCurveCommand; use fan_curve_cli::FanCurveCommand;
use gumdrop::{Opt, Options}; use gumdrop::{Opt, Options};
use log::error; use log::{error, info};
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType, Vec2}; use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType, Vec2};
use rog_aura::keyboard::{AuraPowerState, LaptopAuraPower}; use rog_aura::keyboard::{AuraPowerState, LaptopAuraPower};
@@ -1122,7 +1122,12 @@ fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box<dyn std::error
for attr in attr.iter() { for attr in attr.iter() {
let name = attr.name()?; let name = attr.name()?;
if <&str>::from(name) == cmd[0] { if <&str>::from(name) == cmd[0] {
attr.set_current_value(cmd[1].parse()?)?; let mut value: i32 = cmd[1].parse()?;
if value == -1 {
info!("Setting to default");
value = attr.default_value()?;
}
attr.set_current_value(value)?;
print_firmware_attr(attr)?; print_firmware_attr(attr)?;
} }
} }

View File

@@ -118,7 +118,7 @@ impl crate::Reloadable for AsusArmouryAttribute {
if let Some(tunings) = config.get(&profile) { if let Some(tunings) = config.get(&profile) {
if let Some(tune) = tunings.get(&self.name()) { if let Some(tune) = tunings.get(&self.name()) {
self.attr self.attr
.set_current_value(AttrValue::Integer(*tune)) .set_current_value(&AttrValue::Integer(*tune))
.map_err(|e| { .map_err(|e| {
error!("Could not set value: {e:?}"); error!("Could not set value: {e:?}");
e e
@@ -179,6 +179,11 @@ impl AsusArmouryAttribute {
} }
} }
async fn restore_default(&self) -> fdo::Result<()> {
self.attr.restore_default()?;
Ok(())
}
#[zbus(property)] #[zbus(property)]
async fn min_value(&self) -> i32 { async fn min_value(&self) -> i32 {
match self.attr.min_value() { match self.attr.min_value() {
@@ -224,7 +229,7 @@ impl AsusArmouryAttribute {
#[zbus(property)] #[zbus(property)]
async fn set_current_value(&mut self, value: i32) -> fdo::Result<()> { async fn set_current_value(&mut self, value: i32) -> fdo::Result<()> {
self.attr self.attr
.set_current_value(AttrValue::Integer(value)) .set_current_value(&AttrValue::Integer(value))
.map_err(|e| { .map_err(|e| {
error!("Could not set value: {e:?}"); error!("Could not set value: {e:?}");
e e
@@ -319,20 +324,20 @@ pub async fn set_config_or_default(
let tunings = config.select_tunings(power_plugged, profile); let tunings = config.select_tunings(power_plugged, profile);
if let Some(tune) = tunings.get(&name) { if let Some(tune) = tunings.get(&name) {
attr.set_current_value(AttrValue::Integer(*tune)) attr.set_current_value(&AttrValue::Integer(*tune))
.map_err(|e| { .map_err(|e| {
error!("Failed to set {}: {e}", <&str>::from(name)); error!("Failed to set {}: {e}", <&str>::from(name));
}) })
.ok(); .ok();
} else { } else {
let default = attr.default_value().clone(); let default = attr.default_value();
attr.set_current_value(default.clone()) attr.set_current_value(default)
.map_err(|e| { .map_err(|e| {
error!("Failed to set {}: {e}", <&str>::from(name)); error!("Failed to set {}: {e}", <&str>::from(name));
}) })
.ok(); .ok();
if let AttrValue::Integer(i) = default { if let AttrValue::Integer(i) = default {
tunings.insert(name, i); tunings.insert(name, *i);
info!( info!(
"Set default tuning config for {} = {:?}", "Set default tuning config for {} = {:?}",
<&str>::from(name), <&str>::from(name),

View File

@@ -132,6 +132,23 @@ macro_rules! setup_callback {
}; };
} }
// For handling callbacks from UI value changes
macro_rules! setup_callback_restore_default {
($property:ident, $handle:expr, $attr:expr) => {
let proxy_copy = $attr.clone();
concat_idents!(on_callback = on_cb_default_, $property {
$handle
.global::<SystemPageData>()
.on_callback(move || {
let proxy_copy = proxy_copy.clone();
tokio::spawn(async move {
proxy_copy.restore_default().await.ok();
});
});
});
};
}
macro_rules! setup_external { macro_rules! setup_external {
($property:ident, $type:tt, $handle:expr, $attr:expr, $value:expr) => {{ ($property:ident, $type:tt, $handle:expr, $attr:expr, $value:expr) => {{
// EXTERNAL CHANGES // EXTERNAL CHANGES
@@ -358,41 +375,49 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
FirmwareAttribute::PptPl1Spl => { FirmwareAttribute::PptPl1Spl => {
init_minmax_property!(ppt_pl1_spl, handle, attr); init_minmax_property!(ppt_pl1_spl, handle, attr);
setup_callback!(ppt_pl1_spl, handle, attr, i32); setup_callback!(ppt_pl1_spl, handle, attr, i32);
setup_callback_restore_default!(ppt_pl1_spl, handle, attr);
setup_minmax_external!(ppt_pl1_spl, handle, attr, platform); setup_minmax_external!(ppt_pl1_spl, handle, attr, platform);
} }
FirmwareAttribute::PptPl2Sppt => { FirmwareAttribute::PptPl2Sppt => {
init_minmax_property!(ppt_pl2_sppt, handle, attr); init_minmax_property!(ppt_pl2_sppt, handle, attr);
setup_callback!(ppt_pl2_sppt, handle, attr, i32); setup_callback!(ppt_pl2_sppt, handle, attr, i32);
setup_callback_restore_default!(ppt_pl2_sppt, handle, attr);
setup_minmax_external!(ppt_pl2_sppt, handle, attr, platform); setup_minmax_external!(ppt_pl2_sppt, handle, attr, platform);
} }
FirmwareAttribute::PptPl3Fppt => { FirmwareAttribute::PptPl3Fppt => {
init_minmax_property!(ppt_pl3_fppt, handle, attr); init_minmax_property!(ppt_pl3_fppt, handle, attr);
setup_callback!(ppt_pl3_fppt, handle, attr, i32); setup_callback!(ppt_pl3_fppt, handle, attr, i32);
setup_callback_restore_default!(ppt_pl3_fppt, handle, attr);
setup_minmax_external!(ppt_pl3_fppt, handle, attr, platform); setup_minmax_external!(ppt_pl3_fppt, handle, attr, platform);
} }
FirmwareAttribute::PptFppt => { FirmwareAttribute::PptFppt => {
init_minmax_property!(ppt_fppt, handle, attr); init_minmax_property!(ppt_fppt, handle, attr);
setup_callback!(ppt_fppt, handle, attr, i32); setup_callback!(ppt_fppt, handle, attr, i32);
setup_callback_restore_default!(ppt_fppt, handle, attr);
setup_minmax_external!(ppt_fppt, handle, attr, platform); setup_minmax_external!(ppt_fppt, handle, attr, platform);
} }
FirmwareAttribute::PptApuSppt => { FirmwareAttribute::PptApuSppt => {
init_minmax_property!(ppt_apu_sppt, handle, attr); init_minmax_property!(ppt_apu_sppt, handle, attr);
setup_callback!(ppt_apu_sppt, handle, attr, i32); setup_callback!(ppt_apu_sppt, handle, attr, i32);
setup_callback_restore_default!(ppt_apu_sppt, handle, attr);
setup_minmax_external!(ppt_apu_sppt, handle, attr, platform); setup_minmax_external!(ppt_apu_sppt, handle, attr, platform);
} }
FirmwareAttribute::PptPlatformSppt => { FirmwareAttribute::PptPlatformSppt => {
init_minmax_property!(ppt_platform_sppt, handle, attr); init_minmax_property!(ppt_platform_sppt, handle, attr);
setup_callback!(ppt_platform_sppt, handle, attr, i32); setup_callback!(ppt_platform_sppt, handle, attr, i32);
setup_callback_restore_default!(ppt_platform_sppt, handle, attr);
setup_minmax_external!(ppt_platform_sppt, handle, attr, platform); setup_minmax_external!(ppt_platform_sppt, handle, attr, platform);
} }
FirmwareAttribute::NvDynamicBoost => { FirmwareAttribute::NvDynamicBoost => {
init_minmax_property!(nv_dynamic_boost, handle, attr); init_minmax_property!(nv_dynamic_boost, handle, attr);
setup_callback!(nv_dynamic_boost, handle, attr, i32); setup_callback!(nv_dynamic_boost, handle, attr, i32);
setup_callback_restore_default!(nv_dynamic_boost, handle, attr);
setup_minmax_external!(nv_dynamic_boost, handle, attr, platform); setup_minmax_external!(nv_dynamic_boost, handle, attr, platform);
} }
FirmwareAttribute::NvTempTarget => { FirmwareAttribute::NvTempTarget => {
init_minmax_property!(nv_temp_target, handle, attr); init_minmax_property!(nv_temp_target, handle, attr);
setup_callback!(nv_temp_target, handle, attr, i32); setup_callback!(nv_temp_target, handle, attr, i32);
setup_callback_restore_default!(nv_temp_target, handle, attr);
setup_minmax_external!(nv_temp_target, handle, attr, platform); setup_minmax_external!(nv_temp_target, handle, attr, platform);
} }
FirmwareAttribute::DgpuBaseTgp => {} FirmwareAttribute::DgpuBaseTgp => {}

View File

@@ -2,7 +2,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2025-01-18 22:33+0000\n" "POT-Creation-Date: 2025-01-18 23:02+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -292,142 +292,142 @@ msgctxt "SystemPageData"
msgid "Power" msgid "Power"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:130 #: rog-control-center/ui/pages/system.slint:138
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Power settings" msgid "Power settings"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:135 #: rog-control-center/ui/pages/system.slint:143
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Charge limit" msgid "Charge limit"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:147 #: rog-control-center/ui/pages/system.slint:155
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Throttle Policy" msgid "Throttle Policy"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:157 #: rog-control-center/ui/pages/system.slint:165
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Advanced" msgid "Advanced"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:175 #: rog-control-center/ui/pages/system.slint:183
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Armoury settings" msgid "Armoury settings"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:183 #: rog-control-center/ui/pages/system.slint:191
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Panel Overdrive" msgid "Panel Overdrive"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:191 #: rog-control-center/ui/pages/system.slint:199
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "MiniLED Mode" msgid "MiniLED Mode"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:199 #: rog-control-center/ui/pages/system.slint:207
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "POST boot sound" msgid "POST boot sound"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:210 #: rog-control-center/ui/pages/system.slint:218
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "The asus-armoury driver is not loaded" msgid "The asus-armoury driver is not loaded"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:215 #: rog-control-center/ui/pages/system.slint:223
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "For advanced features you will require a kernel with this driver added." msgid "For advanced features you will require a kernel with this driver added."
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:226 #: rog-control-center/ui/pages/system.slint:234
msgctxt "ppt_warning" msgctxt "ppt_warning"
msgid "The following settings may not be safe, please take care." msgid "The following settings may not be safe, please take care."
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:231 #: rog-control-center/ui/pages/system.slint:239
msgctxt "ppt_pl1_spl" msgctxt "ppt_pl1_spl"
msgid "PL1, sustained power limit" msgid "PL1, sustained power limit"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:242 #: rog-control-center/ui/pages/system.slint:250
msgctxt "ppt_pl2_sppt" msgctxt "ppt_pl2_sppt"
msgid "PL2, turbo power limit" msgid "PL2, turbo power limit"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:253 #: rog-control-center/ui/pages/system.slint:261
msgctxt "ppt_pl3_fppt" msgctxt "ppt_pl3_fppt"
msgid "PL3, Fast Power Limit" msgid "PL3, Fast Power Limit"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:263 #: rog-control-center/ui/pages/system.slint:271
msgctxt "ppt_fppt" msgctxt "ppt_fppt"
msgid "FPPT, Fast Power Limit" msgid "FPPT, Fast Power Limit"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:274 #: rog-control-center/ui/pages/system.slint:282
msgctxt "ppt_apu_sppt" msgctxt "ppt_apu_sppt"
msgid "SPPT, APU slow power limit" msgid "SPPT, APU slow power limit"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:285 #: rog-control-center/ui/pages/system.slint:293
msgctxt "ppt_platform_sppt" msgctxt "ppt_platform_sppt"
msgid "Slow package power tracking limit" msgid "Slow package power tracking limit"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:296 #: rog-control-center/ui/pages/system.slint:304
msgctxt "nv_dynamic_boost" msgctxt "nv_dynamic_boost"
msgid "dGPU boost overclock" msgid "dGPU boost overclock"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:307 #: rog-control-center/ui/pages/system.slint:315
msgctxt "nv_temp_target" msgctxt "nv_temp_target"
msgid "dGPU temperature max" msgid "dGPU temperature max"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:354 #: rog-control-center/ui/pages/system.slint:362
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Energy Performance Preference linked to Throttle Policy" msgid "Energy Performance Preference linked to Throttle Policy"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:358 #: rog-control-center/ui/pages/system.slint:366
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Change EPP based on Throttle Policy" msgid "Change EPP based on Throttle Policy"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:366 #: rog-control-center/ui/pages/system.slint:374
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "EPP for Balanced Policy" msgid "EPP for Balanced Policy"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:376 #: rog-control-center/ui/pages/system.slint:384
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "EPP for Performance Policy" msgid "EPP for Performance Policy"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:386 #: rog-control-center/ui/pages/system.slint:394
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "EPP for Quiet Policy" msgid "EPP for Quiet Policy"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:404 #: rog-control-center/ui/pages/system.slint:412
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Throttle Policy for power state" msgid "Throttle Policy for power state"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:410 #: rog-control-center/ui/pages/system.slint:418
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Throttle Policy on Battery" msgid "Throttle Policy on Battery"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:420 rog-control-center/ui/pages/system.slint:441 #: rog-control-center/ui/pages/system.slint:428 rog-control-center/ui/pages/system.slint:449
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Enabled" msgid "Enabled"
msgstr "" msgstr ""
#: rog-control-center/ui/pages/system.slint:431 #: rog-control-center/ui/pages/system.slint:439
msgctxt "PageSystem" msgctxt "PageSystem"
msgid "Throttle Policy on AC" msgid "Throttle Policy on AC"
msgstr "" msgstr ""

View File

@@ -57,6 +57,7 @@ export global SystemPageData {
val: 20, val: 20,
}; };
callback cb_ppt_pl1_spl(int); callback cb_ppt_pl1_spl(int);
callback cb_default_ppt_pl1_spl();
in-out property <AttrMinMax> ppt_pl2_sppt: { in-out property <AttrMinMax> ppt_pl2_sppt: {
min: 0, min: 0,
@@ -64,6 +65,7 @@ export global SystemPageData {
val: 20, val: 20,
}; };
callback cb_ppt_pl2_sppt(int); callback cb_ppt_pl2_sppt(int);
callback cb_default_ppt_pl2_sppt();
in-out property <AttrMinMax> ppt_pl3_fppt: { in-out property <AttrMinMax> ppt_pl3_fppt: {
min: 0, min: 0,
@@ -71,6 +73,7 @@ export global SystemPageData {
val: 20, val: 20,
}; };
callback cb_ppt_pl3_fppt(int); callback cb_ppt_pl3_fppt(int);
callback cb_default_ppt_pl3_fppt();
in-out property <AttrMinMax> ppt_fppt: { in-out property <AttrMinMax> ppt_fppt: {
min: 0, min: 0,
@@ -78,6 +81,7 @@ export global SystemPageData {
val: 20, val: 20,
}; };
callback cb_ppt_fppt(int); callback cb_ppt_fppt(int);
callback cb_default_ppt_fppt();
in-out property <AttrMinMax> ppt_apu_sppt: { in-out property <AttrMinMax> ppt_apu_sppt: {
min: 0, min: 0,
@@ -85,6 +89,7 @@ export global SystemPageData {
val: 20, val: 20,
}; };
callback cb_ppt_apu_sppt(int); callback cb_ppt_apu_sppt(int);
callback cb_default_ppt_apu_sppt();
in-out property <AttrMinMax> ppt_platform_sppt: { in-out property <AttrMinMax> ppt_platform_sppt: {
min: 0, min: 0,
@@ -92,6 +97,7 @@ export global SystemPageData {
val: 20, val: 20,
}; };
callback cb_ppt_platform_sppt(int); callback cb_ppt_platform_sppt(int);
callback cb_default_ppt_platform_sppt();
in-out property <AttrMinMax> nv_dynamic_boost: { in-out property <AttrMinMax> nv_dynamic_boost: {
min: 0, min: 0,
@@ -99,6 +105,7 @@ export global SystemPageData {
val: 5, val: 5,
}; };
callback cb_nv_dynamic_boost(int); callback cb_nv_dynamic_boost(int);
callback cb_default_nv_dynamic_boost();
in-out property <AttrMinMax> nv_temp_target: { in-out property <AttrMinMax> nv_temp_target: {
min: 0, min: 0,
@@ -106,6 +113,7 @@ export global SystemPageData {
val: 75, val: 75,
}; };
callback cb_nv_temp_target(int); callback cb_nv_temp_target(int);
callback cb_default_nv_temp_target();
} }
export component PageSystem inherits Rectangle { export component PageSystem inherits Rectangle {

View File

@@ -48,4 +48,6 @@ pub trait AsusArmoury {
/// take. Returns `-1` if not used or set. /// take. Returns `-1` if not used or set.
#[zbus(property)] #[zbus(property)]
fn scalar_increment(&self) -> zbus::Result<i32>; fn scalar_increment(&self) -> zbus::Result<i32>;
async fn restore_default(&self) -> zbus::Result<()>;
} }

View File

@@ -76,11 +76,11 @@ impl Attribute {
} }
/// Write the `current_value` directly to the attribute path /// Write the `current_value` directly to the attribute path
pub fn set_current_value(&self, new_value: AttrValue) -> Result<(), PlatformError> { pub fn set_current_value(&self, new_value: &AttrValue) -> Result<(), PlatformError> {
let path = self.base_path.join("current_value"); let path = self.base_path.join("current_value");
let value_str = match new_value { let value_str = match new_value {
AttrValue::Integer(val) => val.to_string(), AttrValue::Integer(val) => &val.to_string(),
AttrValue::String(val) => val, AttrValue::String(val) => val,
_ => return Err(PlatformError::InvalidValue) _ => return Err(PlatformError::InvalidValue)
}; };
@@ -94,6 +94,10 @@ impl Attribute {
&self.default_value &self.default_value
} }
pub fn restore_default(&self) -> Result<(), PlatformError> {
self.set_current_value(&self.default_value)
}
pub fn possible_values(&self) -> &AttrValue { pub fn possible_values(&self) -> &AttrValue {
&self.possible_values &self.possible_values
} }
@@ -453,6 +457,6 @@ mod tests {
if let AttrValue::Integer(val) = &mut val { if let AttrValue::Integer(val) = &mut val {
*val = 0; *val = 0;
} }
attr.set_current_value(val).unwrap(); attr.set_current_value(&val).unwrap();
} }
} }