mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
rog-profiles: fixup populating default curves if none
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
|
||||||
|
|
||||||
use crate::error::RogError;
|
use crate::error::RogError;
|
||||||
use crate::{CtrlTask, GetSupported};
|
use crate::{CtrlTask, GetSupported};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@@ -8,6 +6,7 @@ use rog_platform::supported::PlatformProfileFunctions;
|
|||||||
use rog_profiles::error::ProfileError;
|
use rog_profiles::error::ProfileError;
|
||||||
use rog_profiles::{FanCurveProfiles, Profile};
|
use rog_profiles::{FanCurveProfiles, Profile};
|
||||||
use smol::Executor;
|
use smol::Executor;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use super::config::ProfileConfig;
|
use super::config::ProfileConfig;
|
||||||
|
|
||||||
@@ -56,48 +55,31 @@ impl crate::Reloadable for CtrlPlatformProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CtrlPlatformProfile {
|
impl CtrlPlatformProfile {
|
||||||
pub fn new(mut config: ProfileConfig) -> Result<Self, RogError> {
|
pub fn new(config: ProfileConfig) -> Result<Self, RogError> {
|
||||||
if Profile::is_platform_profile_supported() {
|
if Profile::is_platform_profile_supported() {
|
||||||
info!("Device has profile control available");
|
info!("Device has profile control available");
|
||||||
|
|
||||||
|
let mut controller = CtrlPlatformProfile { config };
|
||||||
if FanCurveProfiles::get_device().is_ok() {
|
if FanCurveProfiles::get_device().is_ok() {
|
||||||
info!("Device has fan curves available");
|
info!("Device has fan curves available");
|
||||||
if config.fan_curves.is_none() {
|
if controller.config.fan_curves.is_none() {
|
||||||
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
controller.config.fan_curves = Some(Default::default());
|
||||||
let dev = FanCurveProfiles::get_device()?;
|
for _ in [Profile::Balanced, Profile::Performance, Profile::Quiet] {
|
||||||
let mut curves = FanCurveProfiles::default();
|
controller.set_next_profile()?;
|
||||||
|
controller.set_active_curve_to_defaults()?;
|
||||||
|
|
||||||
warn!("No default fan-curves: cycling profiles to set defaults");
|
let active = Profile::get_active_profile().unwrap_or(Profile::Balanced);
|
||||||
Profile::set_profile(Profile::Balanced)?;
|
if let Some(curves) = controller.config.fan_curves.as_ref() {
|
||||||
curves.read_from_dev_profile(Profile::Balanced, &dev);
|
info!(
|
||||||
info!(
|
"{active:?}: {}",
|
||||||
"{:?}: {}",
|
String::from(curves.get_fan_curves_for(active))
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(CtrlPlatformProfile { config });
|
return Ok(controller);
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(ProfileError::NotSupported.into())
|
Err(ProfileError::NotSupported.into())
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ impl Profile {
|
|||||||
|
|
||||||
pub fn set_profile(profile: Profile) -> Result<(), ProfileError> {
|
pub fn set_profile(profile: Profile) -> Result<(), ProfileError> {
|
||||||
let mut file = OpenOptions::new().write(true).open(PLATFORM_PROFILE)?;
|
let mut file = OpenOptions::new().write(true).open(PLATFORM_PROFILE)?;
|
||||||
|
|
||||||
file.write_all(<&str>::from(profile).as_bytes())?;
|
file.write_all(<&str>::from(profile).as_bytes())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user