From 493d61cf1934eab7b6bc306186f4fa1c942bfb95 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Mon, 29 Aug 2022 11:51:23 +1200 Subject: [PATCH] rog-profiles: fixup populating default curves if none --- daemon/src/ctrl_profiles/controller.rs | 52 +++++++++----------------- rog-profiles/src/lib.rs | 1 - 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/daemon/src/ctrl_profiles/controller.rs b/daemon/src/ctrl_profiles/controller.rs index 47864b58..80b9a60d 100644 --- a/daemon/src/ctrl_profiles/controller.rs +++ b/daemon/src/ctrl_profiles/controller.rs @@ -1,5 +1,3 @@ -use std::sync::{Arc, Mutex}; - use crate::error::RogError; use crate::{CtrlTask, GetSupported}; use async_trait::async_trait; @@ -8,6 +6,7 @@ use rog_platform::supported::PlatformProfileFunctions; use rog_profiles::error::ProfileError; use rog_profiles::{FanCurveProfiles, Profile}; use smol::Executor; +use std::sync::{Arc, Mutex}; use super::config::ProfileConfig; @@ -56,48 +55,31 @@ impl crate::Reloadable for CtrlPlatformProfile { } impl CtrlPlatformProfile { - pub fn new(mut config: ProfileConfig) -> Result { + pub fn new(config: ProfileConfig) -> Result { if Profile::is_platform_profile_supported() { info!("Device has profile control available"); + let mut controller = CtrlPlatformProfile { config }; if FanCurveProfiles::get_device().is_ok() { info!("Device has fan curves available"); - if config.fan_curves.is_none() { - let active = Profile::get_active_profile().unwrap_or(Profile::Balanced); - let dev = FanCurveProfiles::get_device()?; - let mut curves = FanCurveProfiles::default(); + if controller.config.fan_curves.is_none() { + controller.config.fan_curves = Some(Default::default()); + for _ in [Profile::Balanced, Profile::Performance, Profile::Quiet] { + controller.set_next_profile()?; + controller.set_active_curve_to_defaults()?; - warn!("No default fan-curves: cycling profiles to set defaults"); - Profile::set_profile(Profile::Balanced)?; - curves.read_from_dev_profile(Profile::Balanced, &dev); - info!( - "{:?}: {}", - config.active_profile, - String::from(curves.get_fan_curves_for(Profile::Balanced)) - ); - Profile::set_profile(Profile::Performance)?; - curves.read_from_dev_profile(Profile::Performance, &dev); - info!( - "{:?}: {}", - config.active_profile, - String::from(curves.get_fan_curves_for(Profile::Performance)) - ); - Profile::set_profile(Profile::Quiet)?; - curves.read_from_dev_profile(Profile::Quiet, &dev); - info!( - "{:?}: {}", - config.active_profile, - String::from(curves.get_fan_curves_for(Profile::Quiet)) - ); - - Profile::set_profile(active)?; - config.fan_curves = Some(curves); - config.write(); - info!("Set fan curve defaults"); + let active = Profile::get_active_profile().unwrap_or(Profile::Balanced); + if let Some(curves) = controller.config.fan_curves.as_ref() { + info!( + "{active:?}: {}", + String::from(curves.get_fan_curves_for(active)) + ); + } + } } } - return Ok(CtrlPlatformProfile { config }); + return Ok(controller); } Err(ProfileError::NotSupported.into()) diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index b3b462d4..be9054e0 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -68,7 +68,6 @@ impl Profile { pub fn set_profile(profile: Profile) -> Result<(), ProfileError> { let mut file = OpenOptions::new().write(true).open(PLATFORM_PROFILE)?; - file.write_all(<&str>::from(profile).as_bytes())?; Ok(()) }