mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fix remove the leftover initial config writes on new() for some controllers
Closes #320
This commit is contained in:
@@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- ROGCC: Add CLI opt for viewing all layout files + filenames to help find a layout matching your laptop
|
- ROGCC: Add CLI opt for viewing all layout files + filenames to help find a layout matching your laptop
|
||||||
+ Both of these options would hopefully be temporary and replaced with a "wizard" GUI helper
|
+ Both of these options would hopefully be temporary and replaced with a "wizard" GUI helper
|
||||||
- Fix profile controller not detecting if platform_profile is changed
|
- Fix profile controller not detecting if platform_profile is changed
|
||||||
|
- Fix remove the leftover initial config writes on `new()` for some controllers to prevent resetting settings on startup
|
||||||
|
+ refactor the loading of systemd curve defaults and config file
|
||||||
### BREAKING
|
### BREAKING
|
||||||
- Rename aura dbus method from `per_key_raw` to `direct_addressing_raw` and add doc comment
|
- Rename aura dbus method from `per_key_raw` to `direct_addressing_raw` and add doc comment
|
||||||
- Changes to aura.conf:
|
- Changes to aura.conf:
|
||||||
|
|||||||
20
Cargo.lock
generated
20
Cargo.lock
generated
@@ -149,7 +149,7 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "asusctl"
|
name = "asusctl"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"daemon",
|
"daemon",
|
||||||
@@ -666,7 +666,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "config-traits"
|
name = "config-traits"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"log",
|
"log",
|
||||||
@@ -798,7 +798,7 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "daemon"
|
name = "daemon"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
@@ -822,7 +822,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "daemon-user"
|
name = "daemon-user"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"config-traits",
|
"config-traits",
|
||||||
@@ -2717,7 +2717,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog-control-center"
|
name = "rog-control-center"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"daemon",
|
"daemon",
|
||||||
@@ -2749,7 +2749,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_anime"
|
name = "rog_anime"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"gif",
|
"gif",
|
||||||
@@ -2766,7 +2766,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_aura"
|
name = "rog_aura"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"log",
|
"log",
|
||||||
@@ -2779,7 +2779,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_dbus"
|
name = "rog_dbus"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"rog_anime",
|
"rog_anime",
|
||||||
@@ -2791,7 +2791,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_platform"
|
name = "rog_platform"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"concat-idents",
|
"concat-idents",
|
||||||
@@ -2808,7 +2808,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_profiles"
|
name = "rog_profiles"
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo-husky",
|
"cargo-husky",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
members = ["asusctl", "config-traits", "daemon", "daemon-user", "rog-platform", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles", "rog-control-center"]
|
members = ["asusctl", "config-traits", "daemon", "daemon-user", "rog-platform", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles", "rog-control-center"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "4.6.0-rc1"
|
version = "4.6.0-rc2"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
async-trait = "^0.1"
|
async-trait = "^0.1"
|
||||||
|
|||||||
@@ -163,13 +163,13 @@ macro_rules! std_config_load {
|
|||||||
/// use serde::{Deserialize, Serialize};
|
/// use serde::{Deserialize, Serialize};
|
||||||
/// use config_traits::{StdConfig, StdConfigLoad2};
|
/// use config_traits::{StdConfig, StdConfigLoad2};
|
||||||
///
|
///
|
||||||
/// #[derive(Deserialize, Serialize)]
|
/// #[derive(Deserialize, Serialize, Debug)]
|
||||||
/// struct FanCurveConfigOld {}
|
/// struct FanCurveConfigOld {}
|
||||||
///
|
///
|
||||||
/// #[derive(Deserialize, Serialize)]
|
/// #[derive(Deserialize, Serialize, Debug)]
|
||||||
/// struct FanCurveConfigOlder {}
|
/// struct FanCurveConfigOlder {}
|
||||||
///
|
///
|
||||||
/// #[derive(Deserialize, Serialize)]
|
/// #[derive(Deserialize, Serialize, Debug)]
|
||||||
/// struct FanCurveConfig {}
|
/// struct FanCurveConfig {}
|
||||||
///
|
///
|
||||||
/// impl From<FanCurveConfigOld> for FanCurveConfig {
|
/// impl From<FanCurveConfigOld> for FanCurveConfig {
|
||||||
@@ -195,7 +195,7 @@ macro_rules! std_config_load {
|
|||||||
/// new one created
|
/// new one created
|
||||||
pub trait $trait_name<$($generic),*>
|
pub trait $trait_name<$($generic),*>
|
||||||
where
|
where
|
||||||
Self: $crate::StdConfig + DeserializeOwned + Serialize,
|
Self: $crate::StdConfig +std::fmt::Debug + DeserializeOwned + Serialize,
|
||||||
$($generic: DeserializeOwned + Into<Self>),*
|
$($generic: DeserializeOwned + Into<Self>),*
|
||||||
{
|
{
|
||||||
fn load(mut self) -> Self {
|
fn load(mut self) -> Self {
|
||||||
@@ -205,16 +205,22 @@ macro_rules! std_config_load {
|
|||||||
if read_len != 0 {
|
if read_len != 0 {
|
||||||
if let Ok(data) = ron::from_str(&buf) {
|
if let Ok(data) = ron::from_str(&buf) {
|
||||||
self = data;
|
self = data;
|
||||||
|
log::info!("Parsed RON for {:?}", std::any::type_name::<Self>());
|
||||||
} else if let Ok(data) = serde_json::from_str(&buf) {
|
} else if let Ok(data) = serde_json::from_str(&buf) {
|
||||||
self = data;
|
self = data;
|
||||||
|
log::info!("Parsed JSON for {:?}", std::any::type_name::<Self>());
|
||||||
} else if let Ok(data) = toml::from_str(&buf) {
|
} else if let Ok(data) = toml::from_str(&buf) {
|
||||||
self = data;
|
self = data;
|
||||||
|
log::info!("Parsed TOML for {:?}", std::any::type_name::<Self>());
|
||||||
} $(else if let Ok(data) = ron::from_str::<$generic>(&buf) {
|
} $(else if let Ok(data) = ron::from_str::<$generic>(&buf) {
|
||||||
self = data.into();
|
self = data.into();
|
||||||
|
log::info!("New version failed, trying previous: Parsed RON for {:?}", std::any::type_name::<$generic>());
|
||||||
} else if let Ok(data) = serde_json::from_str::<$generic>(&buf) {
|
} else if let Ok(data) = serde_json::from_str::<$generic>(&buf) {
|
||||||
self = data.into();
|
self = data.into();
|
||||||
|
log::info!("New version failed, trying previous: Parsed JSON for {:?}", std::any::type_name::<$generic>());
|
||||||
} else if let Ok(data) = toml::from_str::<$generic>(&buf) {
|
} else if let Ok(data) = toml::from_str::<$generic>(&buf) {
|
||||||
self = data.into();
|
self = data.into();
|
||||||
|
log::info!("Newvious version failed, trying previous: Parsed TOML for {:?}", std::any::type_name::<$generic>());
|
||||||
})* else {
|
})* else {
|
||||||
self.rename_file_old();
|
self.rename_file_old();
|
||||||
self = Self::new();
|
self = Self::new();
|
||||||
@@ -242,10 +248,10 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_macro_from_1() {
|
fn check_macro_from_1() {
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||||
struct Test {}
|
struct Test {}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||||
struct Old1 {}
|
struct Old1 {}
|
||||||
|
|
||||||
impl crate::StdConfig for Test {
|
impl crate::StdConfig for Test {
|
||||||
@@ -273,16 +279,16 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_macro_from_3() {
|
fn check_macro_from_3() {
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||||
struct Test {}
|
struct Test {}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||||
struct Old1 {}
|
struct Old1 {}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||||
struct Old2 {}
|
struct Old2 {}
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize, Debug)]
|
||||||
struct Old3 {}
|
struct Old3 {}
|
||||||
|
|
||||||
impl crate::StdConfig for Test {
|
impl crate::StdConfig for Test {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use serde_derive::{Deserialize, Serialize};
|
|||||||
|
|
||||||
const CONFIG_FILE: &str = "asusd.ron";
|
const CONFIG_FILE: &str = "asusd.ron";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Default)]
|
#[derive(Deserialize, Serialize, Default, Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// Save charge limit for restoring on boot
|
/// Save charge limit for restoring on boot
|
||||||
pub bat_charge_limit: u8,
|
pub bat_charge_limit: u8,
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ impl AnimeConfigCached {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Config for base system actions for the anime display
|
/// Config for base system actions for the anime display
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
pub struct AnimeConfig {
|
pub struct AnimeConfig {
|
||||||
pub system: Vec<ActionLoader>,
|
pub system: Vec<ActionLoader>,
|
||||||
pub boot: Vec<ActionLoader>,
|
pub boot: Vec<ActionLoader>,
|
||||||
@@ -164,7 +164,7 @@ impl AnimeConfig {
|
|||||||
|
|
||||||
fn create_default() -> Self {
|
fn create_default() -> Self {
|
||||||
// create a default config here
|
// create a default config here
|
||||||
let config = AnimeConfig {
|
AnimeConfig {
|
||||||
system: vec![],
|
system: vec![],
|
||||||
boot: vec![ActionLoader::ImageAnimation {
|
boot: vec![ActionLoader::ImageAnimation {
|
||||||
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
file: "/usr/share/asusd/anime/custom/sonic-run.gif".into(),
|
||||||
@@ -201,8 +201,6 @@ impl AnimeConfig {
|
|||||||
brightness: 1.0,
|
brightness: 1.0,
|
||||||
awake_enabled: true,
|
awake_enabled: true,
|
||||||
boot_anim_enabled: true,
|
boot_anim_enabled: true,
|
||||||
};
|
}
|
||||||
config.write();
|
|
||||||
config
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ impl From<&AuraPowerConfig> for AuraPowerDev {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
// #[serde(default)]
|
// #[serde(default)]
|
||||||
pub struct AuraConfig {
|
pub struct AuraConfig {
|
||||||
pub brightness: LedBrightness,
|
pub brightness: LedBrightness,
|
||||||
@@ -232,7 +232,6 @@ impl AuraConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config.write();
|
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use config_traits::{StdConfig, StdConfigLoad};
|
use config_traits::{StdConfig, StdConfigLoad};
|
||||||
use rog_profiles::fan_curve_set::FanCurveSet;
|
use rog_profiles::fan_curve_set::FanCurveSet;
|
||||||
use rog_profiles::{FanCurveProfiles, Profile};
|
use rog_profiles::Profile;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::CONFIG_PATH_BASE;
|
use crate::CONFIG_PATH_BASE;
|
||||||
@@ -36,40 +36,16 @@ impl StdConfigLoad for ProfileConfig {}
|
|||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, Default)]
|
#[derive(Deserialize, Serialize, Debug, Default)]
|
||||||
pub struct FanCurveConfig {
|
pub struct FanCurveConfig {
|
||||||
balanced: FanCurveSet,
|
pub balanced: FanCurveSet,
|
||||||
performance: FanCurveSet,
|
pub performance: FanCurveSet,
|
||||||
quiet: FanCurveSet,
|
pub quiet: FanCurveSet,
|
||||||
#[serde(skip)]
|
|
||||||
device: FanCurveProfiles,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FanCurveConfig {
|
|
||||||
pub fn update_device_config(&mut self) {
|
|
||||||
self.balanced = self.device.balanced.clone();
|
|
||||||
self.performance = self.device.performance.clone();
|
|
||||||
self.quiet = self.device.quiet.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_config(&mut self) {
|
|
||||||
self.balanced = self.device.balanced.clone();
|
|
||||||
self.performance = self.device.performance.clone();
|
|
||||||
self.quiet = self.device.quiet.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn device(&self) -> &FanCurveProfiles {
|
|
||||||
&self.device
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn device_mut(&mut self) -> &mut FanCurveProfiles {
|
|
||||||
&mut self.device
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdConfig for FanCurveConfig {
|
impl StdConfig for FanCurveConfig {
|
||||||
|
/// Create a new config. The defaults are zeroed so the device must be read
|
||||||
|
/// to get the actual device defaults.
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let mut tmp = Self::default();
|
Self::default()
|
||||||
tmp.update_device_config();
|
|
||||||
tmp
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn config_dir() -> std::path::PathBuf {
|
fn config_dir() -> std::path::PathBuf {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use config_traits::StdConfig;
|
use config_traits::{StdConfig, StdConfigLoad};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use rog_platform::platform::AsusPlatform;
|
use rog_platform::platform::AsusPlatform;
|
||||||
use rog_platform::supported::PlatformProfileFunctions;
|
use rog_platform::supported::PlatformProfileFunctions;
|
||||||
@@ -9,9 +9,39 @@ use super::config::{FanCurveConfig, ProfileConfig};
|
|||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
use crate::GetSupported;
|
use crate::GetSupported;
|
||||||
|
|
||||||
|
// TODO: macro wrapper for warn/info/error log macros to add module name
|
||||||
|
const MOD_NAME: &str = "CtrlPlatformProfile";
|
||||||
|
|
||||||
|
pub struct FanCurves {
|
||||||
|
config_file: FanCurveConfig,
|
||||||
|
profiles: FanCurveProfiles,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FanCurves {
|
||||||
|
pub fn update_profiles_from_config(&mut self) {
|
||||||
|
self.profiles.balanced = self.config_file.balanced.clone();
|
||||||
|
self.profiles.performance = self.config_file.performance.clone();
|
||||||
|
self.profiles.quiet = self.config_file.quiet.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn update_config_from_profiles(&mut self) {
|
||||||
|
self.config_file.balanced = self.profiles.balanced.clone();
|
||||||
|
self.config_file.performance = self.profiles.performance.clone();
|
||||||
|
self.config_file.quiet = self.profiles.quiet.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn profiles(&self) -> &FanCurveProfiles {
|
||||||
|
&self.profiles
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn profiles_mut(&mut self) -> &mut FanCurveProfiles {
|
||||||
|
&mut self.profiles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct CtrlPlatformProfile {
|
pub struct CtrlPlatformProfile {
|
||||||
pub profile_config: ProfileConfig,
|
pub profile_config: ProfileConfig,
|
||||||
pub fan_config: Option<FanCurveConfig>,
|
pub fan_curves: Option<FanCurves>,
|
||||||
pub platform: AsusPlatform,
|
pub platform: AsusPlatform,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,30 +80,50 @@ impl CtrlPlatformProfile {
|
|||||||
pub fn new(config: ProfileConfig) -> Result<Self, RogError> {
|
pub fn new(config: ProfileConfig) -> Result<Self, RogError> {
|
||||||
let platform = AsusPlatform::new()?;
|
let platform = AsusPlatform::new()?;
|
||||||
if platform.has_platform_profile() || platform.has_throttle_thermal_policy() {
|
if platform.has_platform_profile() || platform.has_throttle_thermal_policy() {
|
||||||
info!("Device has profile control available");
|
info!("{MOD_NAME}: Device has profile control available");
|
||||||
|
|
||||||
let mut controller = CtrlPlatformProfile {
|
let mut controller = CtrlPlatformProfile {
|
||||||
profile_config: config,
|
profile_config: config,
|
||||||
fan_config: None,
|
fan_curves: None,
|
||||||
platform,
|
platform,
|
||||||
};
|
};
|
||||||
if FanCurveProfiles::get_device().is_ok() {
|
if FanCurveProfiles::get_device().is_ok() {
|
||||||
info!("Device has fan curves available");
|
info!("{MOD_NAME}: Device has fan curves available");
|
||||||
if controller.fan_config.is_none() {
|
let fan_config = FanCurveConfig::new();
|
||||||
controller.fan_config = Some(Default::default());
|
// Only do defaults if the config doesn't already exist
|
||||||
|
if !fan_config.file_path().exists() {
|
||||||
|
info!("{MOD_NAME}: Fetching default fan curves");
|
||||||
|
controller.fan_curves = Some(FanCurves {
|
||||||
|
config_file: fan_config,
|
||||||
|
profiles: FanCurveProfiles::default(),
|
||||||
|
});
|
||||||
for _ in [Profile::Balanced, Profile::Performance, Profile::Quiet] {
|
for _ in [Profile::Balanced, Profile::Performance, Profile::Quiet] {
|
||||||
|
// For each profile we need to switch to it before we
|
||||||
|
// can read the existing values from hardware. The ACPI method used
|
||||||
|
// for this is what limits us.
|
||||||
controller.set_next_profile()?;
|
controller.set_next_profile()?;
|
||||||
|
// Make sure to set the baseline to default
|
||||||
controller.set_active_curve_to_defaults()?;
|
controller.set_active_curve_to_defaults()?;
|
||||||
|
|
||||||
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
||||||
if let Some(curves) = controller.fan_config.as_ref() {
|
|
||||||
|
if let Some(curves) = controller.fan_curves.as_ref() {
|
||||||
info!(
|
info!(
|
||||||
"{active:?}: {}",
|
"{MOD_NAME}: {active:?}: {}",
|
||||||
String::from(curves.device().get_fan_curves_for(active))
|
String::from(curves.profiles().get_fan_curves_for(active))
|
||||||
);
|
);
|
||||||
curves.write();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(curves) = controller.fan_curves.as_ref() {
|
||||||
|
curves.config_file.write();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
info!("{MOD_NAME}: Fan curves previously stored, loading...");
|
||||||
|
let mut fan_curves = FanCurves {
|
||||||
|
config_file: fan_config.load(),
|
||||||
|
profiles: FanCurveProfiles::default(),
|
||||||
|
};
|
||||||
|
fan_curves.update_profiles_from_config();
|
||||||
|
controller.fan_curves = Some(fan_curves);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,9 +135,9 @@ impl CtrlPlatformProfile {
|
|||||||
|
|
||||||
pub fn save_config(&mut self) {
|
pub fn save_config(&mut self) {
|
||||||
self.profile_config.write();
|
self.profile_config.write();
|
||||||
if let Some(fans) = self.fan_config.as_mut() {
|
if let Some(fans) = self.fan_curves.as_mut() {
|
||||||
fans.update_config();
|
fans.update_config_from_profiles();
|
||||||
fans.write();
|
fans.config_file.write(); // config write
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,9 +165,9 @@ impl CtrlPlatformProfile {
|
|||||||
|
|
||||||
/// Set the curve for the active profile active
|
/// Set the curve for the active profile active
|
||||||
pub(super) fn write_profile_curve_to_platform(&mut self) -> Result<(), RogError> {
|
pub(super) fn write_profile_curve_to_platform(&mut self) -> Result<(), RogError> {
|
||||||
if let Some(curves) = &mut self.fan_config {
|
if let Some(curves) = &mut self.fan_curves {
|
||||||
if let Ok(mut device) = FanCurveProfiles::get_device() {
|
if let Ok(mut device) = FanCurveProfiles::get_device() {
|
||||||
curves.device_mut().write_profile_curve_to_platform(
|
curves.profiles_mut().write_profile_curve_to_platform(
|
||||||
self.profile_config.active_profile,
|
self.profile_config.active_profile,
|
||||||
&mut device,
|
&mut device,
|
||||||
)?;
|
)?;
|
||||||
@@ -127,13 +177,13 @@ impl CtrlPlatformProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn set_active_curve_to_defaults(&mut self) -> Result<(), RogError> {
|
pub(super) fn set_active_curve_to_defaults(&mut self) -> Result<(), RogError> {
|
||||||
if let Some(curves) = self.fan_config.as_mut() {
|
if let Some(curves) = self.fan_curves.as_mut() {
|
||||||
if let Ok(mut device) = FanCurveProfiles::get_device() {
|
if let Ok(mut device) = FanCurveProfiles::get_device() {
|
||||||
curves.device_mut().set_active_curve_to_defaults(
|
curves.profiles_mut().set_active_curve_to_defaults(
|
||||||
self.profile_config.active_profile,
|
self.profile_config.active_profile,
|
||||||
&mut device,
|
&mut device,
|
||||||
)?;
|
)?;
|
||||||
curves.update_config();
|
curves.update_config_from_profiles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ use super::controller::CtrlPlatformProfile;
|
|||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
use crate::CtrlTask;
|
use crate::CtrlTask;
|
||||||
|
|
||||||
|
const MOD_NAME: &str = "ProfileZbus";
|
||||||
|
|
||||||
const ZBUS_PATH: &str = "/org/asuslinux/Profile";
|
const ZBUS_PATH: &str = "/org/asuslinux/Profile";
|
||||||
const UNSUPPORTED_MSG: &str =
|
const UNSUPPORTED_MSG: &str =
|
||||||
"Fan curves are not supported on this laptop or you require a patched kernel";
|
"Fan curves are not supported on this laptop or you require a patched kernel";
|
||||||
@@ -39,7 +41,7 @@ impl ProfileZbus {
|
|||||||
async fn next_profile(&mut self, #[zbus(signal_context)] ctxt: SignalContext<'_>) {
|
async fn next_profile(&mut self, #[zbus(signal_context)] ctxt: SignalContext<'_>) {
|
||||||
let mut ctrl = self.0.lock().await;
|
let mut ctrl = self.0.lock().await;
|
||||||
ctrl.set_next_profile()
|
ctrl.set_next_profile()
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.unwrap_or_else(|err| warn!("{MOD_NAME}: {}", err));
|
||||||
ctrl.save_config();
|
ctrl.save_config();
|
||||||
|
|
||||||
Self::notify_profile(&ctxt, ctrl.profile_config.active_profile)
|
Self::notify_profile(&ctxt, ctrl.profile_config.active_profile)
|
||||||
@@ -64,11 +66,11 @@ impl ProfileZbus {
|
|||||||
// Read first just incase the user has modified the config before calling this
|
// Read first just incase the user has modified the config before calling this
|
||||||
ctrl.profile_config.read();
|
ctrl.profile_config.read();
|
||||||
Profile::set_profile(profile)
|
Profile::set_profile(profile)
|
||||||
.map_err(|e| warn!("set_profile, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: set_profile, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
ctrl.profile_config.active_profile = profile;
|
ctrl.profile_config.active_profile = profile;
|
||||||
ctrl.write_profile_curve_to_platform()
|
ctrl.write_profile_curve_to_platform()
|
||||||
.map_err(|e| warn!("write_profile_curve_to_platform, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: write_profile_curve_to_platform, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
ctrl.save_config();
|
ctrl.save_config();
|
||||||
@@ -82,8 +84,8 @@ impl ProfileZbus {
|
|||||||
async fn enabled_fan_profiles(&mut self) -> zbus::fdo::Result<Vec<Profile>> {
|
async fn enabled_fan_profiles(&mut self) -> zbus::fdo::Result<Vec<Profile>> {
|
||||||
let mut ctrl = self.0.lock().await;
|
let mut ctrl = self.0.lock().await;
|
||||||
ctrl.profile_config.read();
|
ctrl.profile_config.read();
|
||||||
if let Some(curves) = &mut ctrl.fan_config {
|
if let Some(curves) = &mut ctrl.fan_curves {
|
||||||
return Ok(curves.device().get_enabled_curve_profiles());
|
return Ok(curves.profiles().get_enabled_curve_profiles());
|
||||||
}
|
}
|
||||||
Err(Error::Failed(UNSUPPORTED_MSG.to_owned()))
|
Err(Error::Failed(UNSUPPORTED_MSG.to_owned()))
|
||||||
}
|
}
|
||||||
@@ -97,14 +99,13 @@ impl ProfileZbus {
|
|||||||
) -> zbus::fdo::Result<()> {
|
) -> zbus::fdo::Result<()> {
|
||||||
let mut ctrl = self.0.lock().await;
|
let mut ctrl = self.0.lock().await;
|
||||||
ctrl.profile_config.read();
|
ctrl.profile_config.read();
|
||||||
if let Some(curves) = &mut ctrl.fan_config {
|
if let Some(curves) = &mut ctrl.fan_curves {
|
||||||
curves
|
curves
|
||||||
.device_mut()
|
.profiles_mut()
|
||||||
.set_profile_curve_enabled(profile, enabled);
|
.set_profile_curve_enabled(profile, enabled);
|
||||||
curves.update_config();
|
|
||||||
|
|
||||||
ctrl.write_profile_curve_to_platform()
|
ctrl.write_profile_curve_to_platform()
|
||||||
.map_err(|e| warn!("write_profile_curve_to_platform, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: write_profile_curve_to_platform, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
ctrl.save_config();
|
ctrl.save_config();
|
||||||
@@ -118,8 +119,8 @@ impl ProfileZbus {
|
|||||||
async fn fan_curve_data(&mut self, profile: Profile) -> zbus::fdo::Result<FanCurveSet> {
|
async fn fan_curve_data(&mut self, profile: Profile) -> zbus::fdo::Result<FanCurveSet> {
|
||||||
let mut ctrl = self.0.lock().await;
|
let mut ctrl = self.0.lock().await;
|
||||||
ctrl.profile_config.read();
|
ctrl.profile_config.read();
|
||||||
if let Some(curves) = &mut ctrl.fan_config {
|
if let Some(curves) = &mut ctrl.fan_curves {
|
||||||
let curve = curves.device().get_fan_curves_for(profile);
|
let curve = curves.profiles().get_fan_curves_for(profile);
|
||||||
return Ok(curve.clone());
|
return Ok(curve.clone());
|
||||||
}
|
}
|
||||||
Err(Error::Failed(UNSUPPORTED_MSG.to_owned()))
|
Err(Error::Failed(UNSUPPORTED_MSG.to_owned()))
|
||||||
@@ -130,17 +131,16 @@ impl ProfileZbus {
|
|||||||
async fn set_fan_curve(&self, profile: Profile, curve: CurveData) -> zbus::fdo::Result<()> {
|
async fn set_fan_curve(&self, profile: Profile, curve: CurveData) -> zbus::fdo::Result<()> {
|
||||||
let mut ctrl = self.0.lock().await;
|
let mut ctrl = self.0.lock().await;
|
||||||
ctrl.profile_config.read();
|
ctrl.profile_config.read();
|
||||||
if let Some(curves) = &mut ctrl.fan_config {
|
if let Some(curves) = &mut ctrl.fan_curves {
|
||||||
curves
|
curves
|
||||||
.device_mut()
|
.profiles_mut()
|
||||||
.save_fan_curve(curve, profile)
|
.save_fan_curve(curve, profile)
|
||||||
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
|
.map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?;
|
||||||
curves.update_config();
|
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_owned()));
|
return Err(Error::Failed(UNSUPPORTED_MSG.to_owned()));
|
||||||
}
|
}
|
||||||
ctrl.write_profile_curve_to_platform()
|
ctrl.write_profile_curve_to_platform()
|
||||||
.map_err(|e| warn!("Profile::set_profile, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: Profile::set_profile, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
ctrl.save_config();
|
ctrl.save_config();
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ impl ProfileZbus {
|
|||||||
let mut ctrl = self.0.lock().await;
|
let mut ctrl = self.0.lock().await;
|
||||||
ctrl.profile_config.read();
|
ctrl.profile_config.read();
|
||||||
ctrl.set_active_curve_to_defaults()
|
ctrl.set_active_curve_to_defaults()
|
||||||
.map_err(|e| warn!("Profile::set_active_curve_to_defaults, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: Profile::set_active_curve_to_defaults, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
ctrl.save_config();
|
ctrl.save_config();
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -173,14 +173,14 @@ impl ProfileZbus {
|
|||||||
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
||||||
|
|
||||||
Profile::set_profile(profile)
|
Profile::set_profile(profile)
|
||||||
.map_err(|e| warn!("set_profile, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: set_profile, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
ctrl.set_active_curve_to_defaults()
|
ctrl.set_active_curve_to_defaults()
|
||||||
.map_err(|e| warn!("Profile::set_active_curve_to_defaults, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: Profile::set_active_curve_to_defaults, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
Profile::set_profile(active)
|
Profile::set_profile(active)
|
||||||
.map_err(|e| warn!("set_profile, {}", e))
|
.map_err(|e| warn!("{MOD_NAME}: set_profile, {}", e))
|
||||||
.ok();
|
.ok();
|
||||||
ctrl.save_config();
|
ctrl.save_config();
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -222,12 +222,12 @@ impl CtrlTask for ProfileZbus {
|
|||||||
let mut lock = ctrl.lock().await;
|
let mut lock = ctrl.lock().await;
|
||||||
if let Ok(profile) =
|
if let Ok(profile) =
|
||||||
lock.platform.get_throttle_thermal_policy().map_err(|e| {
|
lock.platform.get_throttle_thermal_policy().map_err(|e| {
|
||||||
error!("get_throttle_thermal_policy error: {e}");
|
error!("{MOD_NAME}: get_throttle_thermal_policy error: {e}");
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
let new_profile = Profile::from_throttle_thermal_policy(profile);
|
let new_profile = Profile::from_throttle_thermal_policy(profile);
|
||||||
if new_profile != lock.profile_config.active_profile {
|
if new_profile != lock.profile_config.active_profile {
|
||||||
info!("platform_profile changed to {new_profile}");
|
info!("{MOD_NAME}: platform_profile changed to {new_profile}");
|
||||||
lock.profile_config.active_profile = new_profile;
|
lock.profile_config.active_profile = new_profile;
|
||||||
lock.write_profile_curve_to_platform().unwrap();
|
lock.write_profile_curve_to_platform().unwrap();
|
||||||
lock.save_config();
|
lock.save_config();
|
||||||
@@ -262,7 +262,7 @@ impl CtrlTask for ProfileZbus {
|
|||||||
error!("Profile::from_str(&profile) error: {e}");
|
error!("Profile::from_str(&profile) error: {e}");
|
||||||
}) {
|
}) {
|
||||||
if new_profile != lock.profile_config.active_profile {
|
if new_profile != lock.profile_config.active_profile {
|
||||||
info!("platform_profile changed to {new_profile}");
|
info!("{MOD_NAME}: platform_profile changed to {new_profile}");
|
||||||
lock.profile_config.active_profile = new_profile;
|
lock.profile_config.active_profile = new_profile;
|
||||||
lock.write_profile_curve_to_platform().unwrap();
|
lock.write_profile_curve_to_platform().unwrap();
|
||||||
lock.save_config();
|
lock.save_config();
|
||||||
@@ -295,15 +295,14 @@ impl crate::Reloadable for ProfileZbus {
|
|||||||
async fn reload(&mut self) -> Result<(), RogError> {
|
async fn reload(&mut self) -> Result<(), RogError> {
|
||||||
let mut ctrl = self.0.lock().await;
|
let mut ctrl = self.0.lock().await;
|
||||||
let active = ctrl.profile_config.active_profile;
|
let active = ctrl.profile_config.active_profile;
|
||||||
if let Some(curves) = &mut ctrl.fan_config {
|
if let Some(curves) = &mut ctrl.fan_curves {
|
||||||
if let Ok(mut device) = FanCurveProfiles::get_device() {
|
if let Ok(mut device) = FanCurveProfiles::get_device() {
|
||||||
// There is a possibility that the curve was default zeroed, so this call
|
// There is a possibility that the curve was default zeroed, so this call
|
||||||
// initialises the data from system read and we need to save it
|
// initialises the data from system read and we need to save it
|
||||||
// after
|
// after
|
||||||
curves
|
curves
|
||||||
.device_mut()
|
.profiles_mut()
|
||||||
.write_profile_curve_to_platform(active, &mut device)?;
|
.write_profile_curve_to_platform(active, &mut device)?;
|
||||||
curves.update_config();
|
|
||||||
ctrl.profile_config.write();
|
ctrl.profile_config.write();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user