mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fetch and store fan curve correctly
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use log::{error, warn};
|
||||
use rog_profiles::fan_curves::FanCurveSet;
|
||||
use rog_profiles::{FanCurves, Profile};
|
||||
use rog_profiles::fan_curve_set::FanCurveSet;
|
||||
use rog_profiles::{FanCurveProfiles, Profile};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{Read, Write};
|
||||
@@ -12,20 +12,20 @@ pub struct ProfileConfig {
|
||||
/// For restore on boot
|
||||
pub active_profile: Profile,
|
||||
/// States to restore
|
||||
pub fan_curves: Option<FanCurves>,
|
||||
pub fan_curves: Option<FanCurveProfiles>,
|
||||
}
|
||||
|
||||
impl ProfileConfig {
|
||||
fn new(config_path: String) -> Self {
|
||||
let mut platform = ProfileConfig {
|
||||
config_path,
|
||||
active_profile: Profile::Balanced,
|
||||
active_profile: Profile::get_active_profile().unwrap_or(Profile::Balanced),
|
||||
fan_curves: None,
|
||||
};
|
||||
|
||||
if let Ok(res) = FanCurveSet::is_supported() {
|
||||
if res {
|
||||
let curves = FanCurves::default();
|
||||
let curves = FanCurveProfiles::default();
|
||||
platform.fan_curves = Some(curves);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ impl ProfileConfig {
|
||||
if let Ok(read_len) = file.read_to_string(&mut buf) {
|
||||
if read_len == 0 {
|
||||
config = Self::new(config_path);
|
||||
} else if let Ok(data) = serde_json::from_str(&buf) {
|
||||
} else if let Ok(data) = toml::from_str(&buf) {
|
||||
config = data;
|
||||
config.config_path = config_path;
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ impl ProfileConfig {
|
||||
if l == 0 {
|
||||
warn!("File is empty {}", self.config_path);
|
||||
} else {
|
||||
let mut data: ProfileConfig = serde_json::from_str(&buf)
|
||||
let mut data: ProfileConfig = toml::from_str(&buf)
|
||||
.unwrap_or_else(|_| panic!("Could not deserialise {}", self.config_path));
|
||||
// copy over serde skipped values
|
||||
data.config_path = self.config_path.clone();
|
||||
@@ -81,8 +81,8 @@ impl ProfileConfig {
|
||||
|
||||
pub fn write(&self) {
|
||||
let mut file = File::create(&self.config_path).expect("Couldn't overwrite config");
|
||||
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
|
||||
file.write_all(json.as_bytes())
|
||||
let data = toml::to_string(self).expect("Parse config to toml failed");
|
||||
file.write_all(data.as_bytes())
|
||||
.unwrap_or_else(|err| error!("Could not write config: {}", err));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ use crate::error::RogError;
|
||||
use crate::GetSupported;
|
||||
use log::{info, warn};
|
||||
use rog_profiles::error::ProfileError;
|
||||
use rog_profiles::fan_curves::FanCurveSet;
|
||||
use rog_profiles::{Profile};
|
||||
use rog_profiles::fan_curve_set::FanCurveSet;
|
||||
use rog_profiles::Profile;
|
||||
use rog_supported::PlatformProfileFunctions;
|
||||
use udev::Device;
|
||||
|
||||
@@ -55,21 +55,33 @@ Please note that as of 24/08/2021 this is not final.
|
||||
impl crate::Reloadable for CtrlPlatformProfile {
|
||||
/// Fetch the active profile and use that to set all related components up
|
||||
fn reload(&mut self) -> Result<(), RogError> {
|
||||
if let Some(curves) = &self.config.fan_curves {
|
||||
if let Ok(mut device) = FanCurveSet::get_device() {
|
||||
curves.write_to_platform(self.config.active_profile, &mut device);
|
||||
}
|
||||
if let Some(curves) = &self.config.fan_curves {
|
||||
if let Ok(mut device) = FanCurveSet::get_device() {
|
||||
curves.write_to_platform(self.config.active_profile, &mut device);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CtrlPlatformProfile {
|
||||
pub fn new(config: ProfileConfig, fan_device: Option<Device>) -> Result<Self, RogError> {
|
||||
pub fn new(mut config: ProfileConfig, fan_device: Option<Device>) -> Result<Self, RogError> {
|
||||
if Profile::is_platform_profile_supported() {
|
||||
info!("Device has profile control available");
|
||||
|
||||
if let Some(ref device) = fan_device {
|
||||
let profile = config.active_profile;
|
||||
config
|
||||
.fan_curves
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.read_from_dev_profile(profile, device);
|
||||
}
|
||||
config.write();
|
||||
|
||||
return Ok(CtrlPlatformProfile { config, fan_device });
|
||||
}
|
||||
|
||||
Err(ProfileError::NotSupported.into())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use log::warn;
|
||||
use rog_profiles::fan_curves::CurveData;
|
||||
use rog_profiles::fan_curves::FanCurveSet;
|
||||
use rog_profiles::fan_curve_set::CurveData;
|
||||
use rog_profiles::fan_curve_set::FanCurveSet;
|
||||
use rog_profiles::Profile;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
Reference in New Issue
Block a user