mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
feat: apply the proper configuration depending on the plug status
This commit is contained in:
@@ -179,25 +179,31 @@ impl crate::Reloadable for AsusArmouryAttribute {
|
|||||||
error!("Could not get power status: {e:?}");
|
error!("Could not get power status: {e:?}");
|
||||||
e
|
e
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default()
|
||||||
let config = if power_plugged == 1 {
|
== 1;
|
||||||
&self.config.lock().await.ac_profile_tunings
|
|
||||||
} else {
|
let apply_value = {
|
||||||
&self.config.lock().await.dc_profile_tunings
|
let config = self.config.lock().await;
|
||||||
|
config
|
||||||
|
.select_tunings_ref(power_plugged, profile)
|
||||||
|
.and_then(|tuning| {
|
||||||
|
if tuning.enabled {
|
||||||
|
tuning.group.get(&self.name()).copied()
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
};
|
};
|
||||||
if let Some(tuning) = config.get(&profile) {
|
|
||||||
if tuning.enabled {
|
if let Some(tune) = apply_value {
|
||||||
if let Some(tune) = tuning.group.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:?}", self.attr.name());
|
||||||
error!("Could not set {} value: {e:?}", self.attr.name());
|
self.attr.base_path_exists();
|
||||||
self.attr.base_path_exists();
|
e
|
||||||
e
|
})?;
|
||||||
})?;
|
info!("Set {} to {:?}", self.attr.name(), tune);
|
||||||
info!("Set {} to {:?}", self.attr.name(), tune);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle non-PPT attributes (boolean and other settings)
|
// Handle non-PPT attributes (boolean and other settings)
|
||||||
@@ -339,12 +345,15 @@ impl AsusArmouryAttribute {
|
|||||||
error!("Could not get power status: {e:?}");
|
error!("Could not get power status: {e:?}");
|
||||||
e
|
e
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.unwrap_or_default()
|
||||||
let mut config = self.config.lock().await;
|
== 1;
|
||||||
let tuning = config.select_tunings(power_plugged == 1, profile);
|
let config = self.config.lock().await;
|
||||||
if let Some(tune) = tuning.group.get(&self.name()) {
|
if let Some(tuning) = config.select_tunings_ref(power_plugged, profile) {
|
||||||
return Ok(*tune);
|
if let Some(tune) = tuning.group.get(&self.name()) {
|
||||||
} else if let AttrValue::Integer(i) = self.attr.default_value() {
|
return Ok(*tune);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let AttrValue::Integer(i) = self.attr.default_value() {
|
||||||
return Ok(*i);
|
return Ok(*i);
|
||||||
}
|
}
|
||||||
return Err(fdo::Error::Failed(
|
return Err(fdo::Error::Failed(
|
||||||
@@ -360,6 +369,83 @@ impl AsusArmouryAttribute {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn stored_value_for_power(&self, on_ac: bool) -> fdo::Result<i32> {
|
||||||
|
if !self.name().is_ppt() {
|
||||||
|
return Err(fdo::Error::NotSupported(
|
||||||
|
"Stored values are only available for PPT attributes".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||||
|
let config = self.config.lock().await;
|
||||||
|
if let Some(tuning) = config.select_tunings_ref(on_ac, profile) {
|
||||||
|
if let Some(tune) = tuning.group.get(&self.name()) {
|
||||||
|
return Ok(*tune);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let AttrValue::Integer(i) = self.attr.default_value() {
|
||||||
|
return Ok(*i);
|
||||||
|
}
|
||||||
|
Err(fdo::Error::Failed(
|
||||||
|
"Could not read stored value".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn set_value_for_power(&mut self, on_ac: bool, value: i32) -> fdo::Result<()> {
|
||||||
|
if !self.name().is_ppt() {
|
||||||
|
return Err(fdo::Error::NotSupported(
|
||||||
|
"Setting stored values is only supported for PPT attributes".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
let profile: PlatformProfile = self.platform.get_platform_profile()?.into();
|
||||||
|
let apply_now;
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut config = self.config.lock().await;
|
||||||
|
let tuning = config.select_tunings(on_ac, profile);
|
||||||
|
|
||||||
|
if let Some(tune) = tuning.group.get_mut(&self.name()) {
|
||||||
|
*tune = value;
|
||||||
|
} else {
|
||||||
|
tuning.group.insert(self.name(), value);
|
||||||
|
debug!(
|
||||||
|
"Store {} value for {} power = {}",
|
||||||
|
self.attr.name(),
|
||||||
|
if on_ac { "AC" } else { "DC" },
|
||||||
|
value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
apply_now = tuning.enabled;
|
||||||
|
config.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
if apply_now {
|
||||||
|
let power_plugged = self
|
||||||
|
.power
|
||||||
|
.get_online()
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not get power status: {e:?}");
|
||||||
|
e
|
||||||
|
})
|
||||||
|
.unwrap_or_default()
|
||||||
|
!= 0;
|
||||||
|
|
||||||
|
if power_plugged == on_ac {
|
||||||
|
self.attr
|
||||||
|
.set_current_value(&AttrValue::Integer(value))
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Could not set value: {e:?}");
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[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<()> {
|
||||||
if self.name().is_ppt() {
|
if self.name().is_ppt() {
|
||||||
|
|||||||
@@ -67,6 +67,19 @@ impl Config {
|
|||||||
};
|
};
|
||||||
config.entry(profile).or_insert_with(Tuning::default)
|
config.entry(profile).or_insert_with(Tuning::default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn select_tunings_ref(
|
||||||
|
&self,
|
||||||
|
power_plugged: bool,
|
||||||
|
profile: PlatformProfile,
|
||||||
|
) -> Option<&Tuning> {
|
||||||
|
let config = if power_plugged {
|
||||||
|
&self.ac_profile_tunings
|
||||||
|
} else {
|
||||||
|
&self.dc_profile_tunings
|
||||||
|
};
|
||||||
|
config.get(&profile)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
@@ -146,7 +159,7 @@ pub struct Config611 {
|
|||||||
|
|
||||||
impl From<Config611> for Config {
|
impl From<Config611> for Config {
|
||||||
fn from(c: Config611) -> Self {
|
fn from(c: Config611) -> Self {
|
||||||
Self {
|
let mut config = Self {
|
||||||
// Restore the base charge limit
|
// Restore the base charge limit
|
||||||
charge_control_end_threshold: c.charge_control_end_threshold,
|
charge_control_end_threshold: c.charge_control_end_threshold,
|
||||||
base_charge_control_end_threshold: c.charge_control_end_threshold,
|
base_charge_control_end_threshold: c.charge_control_end_threshold,
|
||||||
@@ -168,7 +181,12 @@ impl From<Config611> for Config {
|
|||||||
armoury_settings: HashMap::default(),
|
armoury_settings: HashMap::default(),
|
||||||
screenpad_gamma: None,
|
screenpad_gamma: None,
|
||||||
screenpad_sync_primary: Default::default(),
|
screenpad_sync_primary: Default::default(),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
config.ac_profile_tunings = c.ac_profile_tunings;
|
||||||
|
config.dc_profile_tunings = c.dc_profile_tunings;
|
||||||
|
config.armoury_settings = c.armoury_settings;
|
||||||
|
config
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user