mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
ROGCC: refactor many more parts of the PPT settings
This commit is contained in:
@@ -417,7 +417,7 @@ pub async fn set_config_or_default(
|
||||
<&str>::from(name),
|
||||
i
|
||||
);
|
||||
config.write();
|
||||
// config.write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -21,7 +21,7 @@ const MINMAX: AttrMinMax = AttrMinMax {
|
||||
|
||||
pub fn setup_system_page(ui: &MainWindow, _config: Arc<Mutex<Config>>) {
|
||||
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::<AsusArmouryProxyBlocking>("xyz.ljones.AsusArmoury").unwrap();
|
||||
|
||||
@@ -191,7 +191,6 @@ macro_rules! setup_value_watch {
|
||||
let mut tmp: AttrMinMax =
|
||||
handle.global::<SystemPageData>().getter();
|
||||
tmp.$value_type = out $($conv)*;
|
||||
dbg!(tmp.$value_type);
|
||||
concat_idents!(setter = set_, $property {
|
||||
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 {
|
||||
// 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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -12,6 +12,7 @@ export component RogItem inherits Rectangle {
|
||||
export component SystemSlider inherits RogItem {
|
||||
in property <string> title;
|
||||
in property <string> text;
|
||||
in-out property <bool> enabled;
|
||||
in-out property <float> value;
|
||||
in-out property <float> minimum;
|
||||
in-out property <float> 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user