ROGCC: refactor many more parts of the PPT settings

This commit is contained in:
Luke Jones
2025-02-04 17:48:52 +13:00
parent 5833a011ce
commit 16700e55f4
6 changed files with 69 additions and 59 deletions

View File

@@ -417,7 +417,7 @@ pub async fn set_config_or_default(
<&str>::from(name), <&str>::from(name),
i i
); );
config.write(); // config.write();
} }
} }
} }

View File

@@ -350,27 +350,17 @@ impl CtrlPlatform {
} }
#[zbus(property)] #[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 // TODO: watch for external changes
if self.platform.has_platform_profile() { if self.platform.has_platform_profile() {
let change_epp = self.config.lock().await.platform_profile_linked_epp; let change_epp = self.config.lock().await.platform_profile_linked_epp;
let epp = self.get_config_epp_for_throttle(policy).await; let epp = self.get_config_epp_for_throttle(policy).await;
self.check_and_set_epp(epp, change_epp); 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(); self.config.lock().await.write();
// TODO: Need to get supported profiles here and ensure we translate to one // TODO: Need to get supported profiles here and ensure we translate to one
self.platform self.platform
@@ -378,7 +368,9 @@ impl CtrlPlatform {
.map_err(|err| { .map_err(|err| {
warn!("platform_profile {}", err); warn!("platform_profile {}", err);
FdoErr::Failed(format!("RogPlatform: platform_profile: {err}")) FdoErr::Failed(format!("RogPlatform: platform_profile: {err}"))
}) })?;
self.enable_ppt_group_changed(&ctxt).await?;
Ok(())
} else { } else {
Err(FdoErr::NotSupported( Err(FdoErr::NotSupported(
"RogPlatform: platform_profile not supported".to_owned() "RogPlatform: platform_profile not supported".to_owned()
@@ -406,10 +398,11 @@ impl CtrlPlatform {
#[zbus(property)] #[zbus(property)]
async fn set_platform_profile_on_battery( async fn set_platform_profile_on_battery(
&mut self, &mut self,
#[zbus(signal_context)] ctxt: SignalEmitter<'_>,
policy: PlatformProfile policy: PlatformProfile
) -> Result<(), FdoErr> { ) -> Result<(), FdoErr> {
self.config.lock().await.platform_profile_on_battery = policy; 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(); self.config.lock().await.write();
Ok(()) Ok(())
} }
@@ -432,9 +425,13 @@ impl CtrlPlatform {
} }
#[zbus(property)] #[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.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(); self.config.lock().await.write();
Ok(()) Ok(())
} }
@@ -533,45 +530,41 @@ impl CtrlPlatform {
.unwrap_or_default(); .unwrap_or_default();
let profile: PlatformProfile = self.platform.get_platform_profile()?.into(); let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
// Clone to reduce blocking if enable {
let tuning = self // Clone to reduce blocking
.config let tuning = self
.lock() .config
.await .lock()
.select_tunings(power_plugged == 1, profile) .await
.clone(); .select_tunings(power_plugged == 1, profile)
.clone();
for attr in self.attributes.attributes() { for attr in self.attributes.attributes() {
let name: FirmwareAttribute = attr.name().into(); let name: FirmwareAttribute = attr.name().into();
if name.is_ppt() { if name.is_ppt() {
// reset stored value // reset stored value
if let Some(tune) = self if let Some(tune) = self
.config .config
.lock() .lock()
.await .await
.select_tunings(power_plugged == 1, profile) .select_tunings(power_plugged == 1, profile)
.group .group
.get_mut(&name) .get_mut(&name)
{ {
let value = if !enable { let value = tuning
attr.default_value().clone()
} else {
tuning
.group .group
.get(&name) .get(&name)
.map(|v| AttrValue::Integer(*v)) .map(|v| AttrValue::Integer(*v))
.unwrap_or_else(|| attr.default_value().clone()) .unwrap_or_else(|| attr.default_value().clone());
}; // restore default
// restore default attr.set_current_value(&value)?;
attr.set_current_value(&value)?; if let AttrValue::Integer(i) = value {
if let AttrValue::Integer(i) = value { *tune = i
*tune = i }
} }
} }
} }
} } else {
if !enable {
// finally, reapply the profile to ensure acpi does the thingy // finally, reapply the profile to ensure acpi does the thingy
self.platform.set_platform_profile(profile.into())?; self.platform.set_platform_profile(profile.into())?;
} }
@@ -683,6 +676,7 @@ impl CtrlTask for CtrlPlatform {
let platform1 = self.clone(); let platform1 = self.clone();
let platform2 = self.clone(); let platform2 = self.clone();
let platform3 = self.clone(); let platform3 = self.clone();
let signal_ctxt_copy = signal_ctxt.clone();
self.create_sys_event_tasks( self.create_sys_event_tasks(
move |sleeping| { move |sleeping| {
let platform1 = platform1.clone(); let platform1 = platform1.clone();
@@ -750,6 +744,7 @@ impl CtrlTask for CtrlPlatform {
}, },
move |power_plugged| { move |power_plugged| {
let platform3 = platform3.clone(); let platform3 = platform3.clone();
let signal_ctxt_copy = signal_ctxt.clone();
// power change // power change
async move { async move {
if platform3.platform.has_platform_profile() { if platform3.platform.has_platform_profile() {
@@ -781,6 +776,10 @@ impl CtrlTask for CtrlPlatform {
profile profile
) )
.await; .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. // This spawns a new task for every item.
// TODO: find a better way to manage this // 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?; .await?;
let watch_platform_profile = self.platform.monitor_platform_profile()?; 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 change_epp = ctrl.config.lock().await.platform_profile_linked_epp;
let epp = ctrl.get_config_epp_for_throttle(profile).await; let epp = ctrl.get_config_epp_for_throttle(profile).await;
ctrl.check_and_set_epp(epp, change_epp); ctrl.check_and_set_epp(epp, change_epp);
ctrl.platform_profile_changed(&signal_ctxt).await.ok(); ctrl.platform_profile_changed(&signal_ctxt_copy).await.ok();
ctrl.enable_ppt_group_changed(&signal_ctxt).await.ok(); ctrl.enable_ppt_group_changed(&signal_ctxt_copy).await.ok();
let power_plugged = ctrl let power_plugged = ctrl
.power .power
.get_online() .get_online()

View File

@@ -91,7 +91,7 @@ impl LedSupportFile {
/// to ensure we match to *whole names* first before doing a glob match /// to ensure we match to *whole names* first before doing a glob match
fn match_device(&self, device_name: &str, product_id: &str) -> LedSupportData { fn match_device(&self, device_name: &str, product_id: &str) -> LedSupportData {
for config in self.0.iter().rev() { 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); info!("Matched to {}", config.device_name);
if !config.product_id.is_empty() { if !config.product_id.is_empty() {
info!("Checking product ID"); info!("Checking product ID");

View File

@@ -21,7 +21,7 @@ const MINMAX: AttrMinMax = AttrMinMax {
pub fn setup_system_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) { pub fn setup_system_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
let conn = zbus::blocking::Connection::system().unwrap(); let conn = zbus::blocking::Connection::system().unwrap();
let platform = PlatformProxyBlocking::new(&conn).unwrap(); let platform = PlatformProxyBlocking::builder(&conn).build().unwrap();
// let armoury_attrs = // let armoury_attrs =
// find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury").unwrap(); // find_iface::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury").unwrap();
@@ -191,7 +191,6 @@ macro_rules! setup_value_watch {
let mut tmp: AttrMinMax = let mut tmp: AttrMinMax =
handle.global::<SystemPageData>().getter(); handle.global::<SystemPageData>().getter();
tmp.$value_type = out $($conv)*; tmp.$value_type = out $($conv)*;
dbg!(tmp.$value_type);
concat_idents!(setter = set_, $property { concat_idents!(setter = set_, $property {
handle.global::<SystemPageData>().setter(tmp); handle.global::<SystemPageData>().setter(tmp);
}); });
@@ -260,7 +259,7 @@ pub fn setup_system_page_callbacks(ui: &MainWindow, _states: Arc<Mutex<Config>>)
tokio::spawn(async move { tokio::spawn(async move {
// Create the connections/proxies here to prevent future delays in process // Create the connections/proxies here to prevent future delays in process
let conn = zbus::Connection::system().await.unwrap(); 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!( set_ui_props_async!(
handle, handle,

View File

@@ -265,6 +265,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.ppt_pl1_spl.min; minimum: SystemPageData.ppt_pl1_spl.min;
maximum: SystemPageData.ppt_pl1_spl.max; maximum: SystemPageData.ppt_pl1_spl.max;
value: SystemPageData.ppt_pl1_spl.current; value: SystemPageData.ppt_pl1_spl.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_ppt_pl1_spl(); SystemPageData.cb_default_ppt_pl1_spl();
@@ -282,6 +283,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.ppt_pl2_sppt.min; minimum: SystemPageData.ppt_pl2_sppt.min;
maximum: SystemPageData.ppt_pl2_sppt.max; maximum: SystemPageData.ppt_pl2_sppt.max;
value: SystemPageData.ppt_pl2_sppt.current; value: SystemPageData.ppt_pl2_sppt.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_ppt_pl2_sppt(); SystemPageData.cb_default_ppt_pl2_sppt();
@@ -299,6 +301,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.ppt_pl3_fppt.min; minimum: SystemPageData.ppt_pl3_fppt.min;
maximum: SystemPageData.ppt_pl3_fppt.max; maximum: SystemPageData.ppt_pl3_fppt.max;
value: SystemPageData.ppt_pl3_fppt.current; value: SystemPageData.ppt_pl3_fppt.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_ppt_pl3_fppt(); SystemPageData.cb_default_ppt_pl3_fppt();
@@ -315,6 +318,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.ppt_fppt.min; minimum: SystemPageData.ppt_fppt.min;
maximum: SystemPageData.ppt_fppt.max; maximum: SystemPageData.ppt_fppt.max;
value: SystemPageData.ppt_fppt.current; value: SystemPageData.ppt_fppt.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_ppt_fppt(); SystemPageData.cb_default_ppt_fppt();
@@ -332,6 +336,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.ppt_apu_sppt.min; minimum: SystemPageData.ppt_apu_sppt.min;
maximum: SystemPageData.ppt_apu_sppt.max; maximum: SystemPageData.ppt_apu_sppt.max;
value: SystemPageData.ppt_apu_sppt.current; value: SystemPageData.ppt_apu_sppt.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_ppt_apu_sppt(); SystemPageData.cb_default_ppt_apu_sppt();
@@ -349,6 +354,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.ppt_platform_sppt.min; minimum: SystemPageData.ppt_platform_sppt.min;
maximum: SystemPageData.ppt_platform_sppt.max; maximum: SystemPageData.ppt_platform_sppt.max;
value: SystemPageData.ppt_platform_sppt.current; value: SystemPageData.ppt_platform_sppt.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_ppt_platform_sppt(); SystemPageData.cb_default_ppt_platform_sppt();
@@ -366,6 +372,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.nv_dynamic_boost.min; minimum: SystemPageData.nv_dynamic_boost.min;
maximum: SystemPageData.nv_dynamic_boost.max; maximum: SystemPageData.nv_dynamic_boost.max;
value: SystemPageData.nv_dynamic_boost.current; value: SystemPageData.nv_dynamic_boost.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_nv_dynamic_boost(); SystemPageData.cb_default_nv_dynamic_boost();
@@ -383,6 +390,7 @@ export component PageSystem inherits Rectangle {
minimum: SystemPageData.nv_temp_target.min; minimum: SystemPageData.nv_temp_target.min;
maximum: SystemPageData.nv_temp_target.max; maximum: SystemPageData.nv_temp_target.max;
value: SystemPageData.nv_temp_target.current; value: SystemPageData.nv_temp_target.current;
enabled <=> SystemPageData.enable_ppt_group;
has_reset: true; has_reset: true;
cb_do_reset => { cb_do_reset => {
SystemPageData.cb_default_nv_temp_target(); SystemPageData.cb_default_nv_temp_target();

View File

@@ -12,6 +12,7 @@ export component RogItem inherits Rectangle {
export component SystemSlider inherits RogItem { export component SystemSlider inherits RogItem {
in property <string> title; in property <string> title;
in property <string> text; in property <string> text;
in-out property <bool> enabled;
in-out property <float> value; in-out property <float> value;
in-out property <float> minimum; in-out property <float> minimum;
in-out property <float> maximum; in-out property <float> maximum;
@@ -27,6 +28,7 @@ export component SystemSlider inherits RogItem {
alignment: LayoutAlignment.stretch; alignment: LayoutAlignment.stretch;
padding-left: 10px; padding-left: 10px;
TouchArea { TouchArea {
enabled <=> root.enabled;
clicked => { clicked => {
slider.value += 1; slider.value += 1;
if slider.value > slider.maximum { if slider.value > slider.maximum {
@@ -57,6 +59,7 @@ export component SystemSlider inherits RogItem {
// alignment: LayoutAlignment.end; // alignment: LayoutAlignment.end;
padding-right: 20px; padding-right: 20px;
slider := Slider { slider := Slider {
enabled <=> root.enabled;
maximum: root.maximum; maximum: root.maximum;
minimum: root.minimum; minimum: root.minimum;
value <=> root.value; value <=> root.value;
@@ -150,6 +153,7 @@ export component SystemSlider inherits RogItem {
reset := HorizontalBox { reset := HorizontalBox {
if (has_reset): StandardButton { if (has_reset): StandardButton {
kind: StandardButtonKind.reset; kind: StandardButtonKind.reset;
enabled <=> root.enabled;
clicked => { clicked => {
reset_popup.show(); reset_popup.show();
} }