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
- Per-AC/DC, per-profile tunings enabled (Battery vs AC power + platform profile)
- Add ability to restore PPT defaults (WIP)
## [v6.1.0-rc4]

View File

@@ -96,6 +96,9 @@ pub struct GraphicsCommand {
pub struct ArmouryCommand {
#[options(help = "print help message")]
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>
}

View File

@@ -9,7 +9,7 @@ use aura_cli::{LedPowerCommand1, LedPowerCommand2};
use dmi_id::DMIID;
use fan_curve_cli::FanCurveCommand;
use gumdrop::{Opt, Options};
use log::error;
use log::{error, info};
use rog_anime::usb::get_anime_type;
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType, Vec2};
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() {
let name = attr.name()?;
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)?;
}
}

View File

@@ -118,7 +118,7 @@ impl crate::Reloadable for AsusArmouryAttribute {
if let Some(tunings) = config.get(&profile) {
if let Some(tune) = tunings.get(&self.name()) {
self.attr
.set_current_value(AttrValue::Integer(*tune))
.set_current_value(&AttrValue::Integer(*tune))
.map_err(|e| {
error!("Could not set value: {e:?}");
e
@@ -179,6 +179,11 @@ impl AsusArmouryAttribute {
}
}
async fn restore_default(&self) -> fdo::Result<()> {
self.attr.restore_default()?;
Ok(())
}
#[zbus(property)]
async fn min_value(&self) -> i32 {
match self.attr.min_value() {
@@ -224,7 +229,7 @@ impl AsusArmouryAttribute {
#[zbus(property)]
async fn set_current_value(&mut self, value: i32) -> fdo::Result<()> {
self.attr
.set_current_value(AttrValue::Integer(value))
.set_current_value(&AttrValue::Integer(value))
.map_err(|e| {
error!("Could not set value: {e:?}");
e
@@ -319,20 +324,20 @@ pub async fn set_config_or_default(
let tunings = config.select_tunings(power_plugged, profile);
if let Some(tune) = tunings.get(&name) {
attr.set_current_value(AttrValue::Integer(*tune))
attr.set_current_value(&AttrValue::Integer(*tune))
.map_err(|e| {
error!("Failed to set {}: {e}", <&str>::from(name));
})
.ok();
} else {
let default = attr.default_value().clone();
attr.set_current_value(default.clone())
let default = attr.default_value();
attr.set_current_value(default)
.map_err(|e| {
error!("Failed to set {}: {e}", <&str>::from(name));
})
.ok();
if let AttrValue::Integer(i) = default {
tunings.insert(name, i);
tunings.insert(name, *i);
info!(
"Set default tuning config for {} = {:?}",
<&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 {
($property:ident, $type:tt, $handle:expr, $attr:expr, $value:expr) => {{
// EXTERNAL CHANGES
@@ -358,41 +375,49 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
FirmwareAttribute::PptPl1Spl => {
init_minmax_property!(ppt_pl1_spl, handle, attr);
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);
}
FirmwareAttribute::PptPl2Sppt => {
init_minmax_property!(ppt_pl2_sppt, handle, attr);
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);
}
FirmwareAttribute::PptPl3Fppt => {
init_minmax_property!(ppt_pl3_fppt, handle, attr);
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);
}
FirmwareAttribute::PptFppt => {
init_minmax_property!(ppt_fppt, handle, attr);
setup_callback!(ppt_fppt, handle, attr, i32);
setup_callback_restore_default!(ppt_fppt, handle, attr);
setup_minmax_external!(ppt_fppt, handle, attr, platform);
}
FirmwareAttribute::PptApuSppt => {
init_minmax_property!(ppt_apu_sppt, handle, attr);
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);
}
FirmwareAttribute::PptPlatformSppt => {
init_minmax_property!(ppt_platform_sppt, handle, attr);
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);
}
FirmwareAttribute::NvDynamicBoost => {
init_minmax_property!(nv_dynamic_boost, handle, attr);
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);
}
FirmwareAttribute::NvTempTarget => {
init_minmax_property!(nv_temp_target, handle, attr);
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);
}
FirmwareAttribute::DgpuBaseTgp => {}

View File

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

View File

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

View File

@@ -48,4 +48,6 @@ pub trait AsusArmoury {
/// take. Returns `-1` if not used or set.
#[zbus(property)]
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
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 value_str = match new_value {
AttrValue::Integer(val) => val.to_string(),
AttrValue::Integer(val) => &val.to_string(),
AttrValue::String(val) => val,
_ => return Err(PlatformError::InvalidValue)
};
@@ -94,6 +94,10 @@ impl Attribute {
&self.default_value
}
pub fn restore_default(&self) -> Result<(), PlatformError> {
self.set_current_value(&self.default_value)
}
pub fn possible_values(&self) -> &AttrValue {
&self.possible_values
}
@@ -453,6 +457,6 @@ mod tests {
if let AttrValue::Integer(val) = &mut val {
*val = 0;
}
attr.set_current_value(val).unwrap();
attr.set_current_value(&val).unwrap();
}
}