mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Begin syncing changes with patch series
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use log::{error, warn};
|
||||
use rog_profiles::fan_curves::FanCurveSet;
|
||||
use rog_profiles::{FanCurves, Profile};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::fs::{File, OpenOptions};
|
||||
@@ -22,10 +23,11 @@ impl ProfileConfig {
|
||||
fan_curves: None,
|
||||
};
|
||||
|
||||
if FanCurves::is_fan_curves_supported() {
|
||||
let mut curves = FanCurves::default();
|
||||
curves.update_from_platform();
|
||||
platform.fan_curves = Some(curves);
|
||||
if let Ok(res) = FanCurveSet::is_supported() {
|
||||
if res {
|
||||
let mut curves = FanCurves::default();
|
||||
platform.fan_curves = Some(curves);
|
||||
}
|
||||
}
|
||||
|
||||
platform
|
||||
|
||||
@@ -2,37 +2,16 @@ use crate::error::RogError;
|
||||
use crate::GetSupported;
|
||||
use log::{info, warn};
|
||||
use rog_profiles::error::ProfileError;
|
||||
use rog_profiles::{FanCurves, Profile};
|
||||
use rog_profiles::fan_curves::FanCurveSet;
|
||||
use rog_profiles::{Profile};
|
||||
use rog_supported::PlatformProfileFunctions;
|
||||
use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use udev::Device;
|
||||
|
||||
use super::config::ProfileConfig;
|
||||
|
||||
pub struct CtrlPlatformTask {
|
||||
config: Arc<Mutex<ProfileConfig>>,
|
||||
}
|
||||
|
||||
impl CtrlPlatformTask {
|
||||
pub fn new(config: Arc<Mutex<ProfileConfig>>) -> Self {
|
||||
Self { config }
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::CtrlTask for CtrlPlatformTask {
|
||||
fn do_task(&self) -> Result<(), RogError> {
|
||||
if let Ok(mut lock) = self.config.try_lock() {
|
||||
// Refresh the config in-case the user has edited it
|
||||
if let Some(curves) = &mut lock.fan_curves {
|
||||
curves.update_from_platform();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CtrlPlatformProfile {
|
||||
pub config: Arc<Mutex<ProfileConfig>>,
|
||||
pub config: ProfileConfig,
|
||||
pub fan_device: Option<Device>,
|
||||
}
|
||||
|
||||
impl GetSupported for CtrlPlatformProfile {
|
||||
@@ -48,7 +27,14 @@ https://lkml.org/lkml/2021/8/18/1022
|
||||
"#
|
||||
);
|
||||
}
|
||||
if !FanCurves::is_fan_curves_supported() {
|
||||
|
||||
let res = FanCurveSet::is_supported();
|
||||
let mut fan_curve_supported = res.is_err();
|
||||
if let Ok(r) = res {
|
||||
fan_curve_supported = r;
|
||||
};
|
||||
|
||||
if fan_curve_supported {
|
||||
info!(
|
||||
r#"
|
||||
fan curves kernel interface not found, your laptop does not support this, or the interface is missing.
|
||||
@@ -58,9 +44,10 @@ Please note that as of 24/08/2021 this is not final.
|
||||
"#
|
||||
);
|
||||
}
|
||||
|
||||
PlatformProfileFunctions {
|
||||
platform_profile: Profile::is_platform_profile_supported(),
|
||||
fan_curves: FanCurves::is_fan_curves_supported(),
|
||||
fan_curves: fan_curve_supported,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,53 +55,54 @@ 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 Ok(cfg) = self.config.clone().try_lock() {
|
||||
if let Some(curves) = &cfg.fan_curves {
|
||||
curves.update_platform();
|
||||
if let Some(curves) = &self.config.fan_curves {
|
||||
if let Ok(mut device) = FanCurveSet::get_device() {
|
||||
curves.write_to_platform(self.config.active, &mut device);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl CtrlPlatformProfile {
|
||||
pub fn new(config: Arc<Mutex<ProfileConfig>>) -> Result<Self, RogError> {
|
||||
pub fn new(config: ProfileConfig, fan_device: Option<Device>) -> Result<Self, RogError> {
|
||||
if Profile::is_platform_profile_supported() {
|
||||
info!("Device has profile control available");
|
||||
return Ok(CtrlPlatformProfile { config });
|
||||
return Ok(CtrlPlatformProfile { config, fan_device });
|
||||
}
|
||||
Err(ProfileError::NotSupported.into())
|
||||
}
|
||||
|
||||
pub fn get_device(&self) -> Option<Device> {
|
||||
self.fan_device.clone()
|
||||
}
|
||||
|
||||
pub fn save_config(&self) {
|
||||
if let Ok(lock) = self.config.lock() {
|
||||
lock.write();
|
||||
}
|
||||
self.config.write();
|
||||
}
|
||||
|
||||
/// Toggle to next profile in list. This will first read the config, switch, then write out
|
||||
pub(super) fn set_next_profile(&mut self) -> Result<(), RogError> {
|
||||
if let Ok(mut config) = self.config.clone().try_lock() {
|
||||
// Read first just incase the user has modified the config before calling this
|
||||
config.read();
|
||||
// Read first just incase the user has modified the config before calling this
|
||||
self.config.read();
|
||||
|
||||
match config.active {
|
||||
Profile::Balanced => {
|
||||
Profile::set_profile(Profile::Performance)?;
|
||||
config.active = Profile::Performance;
|
||||
}
|
||||
Profile::Performance => {
|
||||
Profile::set_profile(Profile::Quiet)?;
|
||||
config.active = Profile::Quiet;
|
||||
}
|
||||
Profile::Quiet => {
|
||||
Profile::set_profile(Profile::Balanced)?;
|
||||
config.active = Profile::Balanced;
|
||||
}
|
||||
match self.config.active {
|
||||
Profile::Balanced => {
|
||||
Profile::set_profile(Profile::Performance)?;
|
||||
self.config.active = Profile::Performance;
|
||||
}
|
||||
Profile::Performance => {
|
||||
Profile::set_profile(Profile::Quiet)?;
|
||||
self.config.active = Profile::Quiet;
|
||||
}
|
||||
Profile::Quiet => {
|
||||
Profile::set_profile(Profile::Balanced)?;
|
||||
self.config.active = Profile::Balanced;
|
||||
}
|
||||
|
||||
config.write();
|
||||
}
|
||||
|
||||
self.config.write();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use log::warn;
|
||||
use rog_profiles::FanCurve;
|
||||
use rog_profiles::fan_curves::FanCurveSet;
|
||||
use rog_profiles::Profile;
|
||||
|
||||
use std::sync::Arc;
|
||||
@@ -45,11 +45,9 @@ impl ProfileZbus {
|
||||
|
||||
/// Fetch the active profile name
|
||||
fn active_profile(&mut self) -> zbus::fdo::Result<Profile> {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
cfg.read();
|
||||
return Ok(cfg.active);
|
||||
}
|
||||
if let Ok(mut ctrl) = self.inner.try_lock() {
|
||||
ctrl.config.read();
|
||||
return Ok(ctrl.config.active);
|
||||
}
|
||||
Err(Error::Failed(
|
||||
"Failed to get active profile name".to_string(),
|
||||
@@ -58,15 +56,14 @@ impl ProfileZbus {
|
||||
|
||||
/// Set this platform_profile name as active
|
||||
fn set_active_profile(&self, profile: Profile) {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
// Read first just incase the user has modified the config before calling this
|
||||
cfg.read();
|
||||
Profile::set_profile(profile)
|
||||
.map_err(|e| warn!("Profile::set_profile, {}", e))
|
||||
.ok();
|
||||
cfg.active = profile;
|
||||
}
|
||||
if let Ok(mut ctrl) = self.inner.try_lock() {
|
||||
// Read first just incase the user has modified the config before calling this
|
||||
ctrl.config.read();
|
||||
Profile::set_profile(profile)
|
||||
.map_err(|e| warn!("Profile::set_profile, {}", e))
|
||||
.ok();
|
||||
ctrl.config.active = profile;
|
||||
|
||||
ctrl.save_config();
|
||||
}
|
||||
self.do_notification();
|
||||
@@ -74,14 +71,12 @@ impl ProfileZbus {
|
||||
|
||||
/// Get a list of profiles that have fan-curves enabled.
|
||||
fn enabled_fan_profiles(&mut self) -> zbus::fdo::Result<Vec<Profile>> {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
cfg.read();
|
||||
if let Some(curves) = &cfg.fan_curves {
|
||||
return Ok(curves.get_enabled_curve_names().to_vec());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
if let Ok(mut ctrl) = self.inner.try_lock() {
|
||||
ctrl.config.read();
|
||||
if let Some(curves) = &ctrl.config.fan_curves {
|
||||
return Ok(curves.get_enabled_curve_names().to_vec());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
}
|
||||
Err(Error::Failed(
|
||||
"Failed to get enabled fan curve names".to_string(),
|
||||
@@ -89,43 +84,41 @@ impl ProfileZbus {
|
||||
}
|
||||
|
||||
/// Get the fan-curve data for the currently active Profile
|
||||
fn active_fan_curve_data(&mut self) -> zbus::fdo::Result<FanCurve> {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
cfg.read();
|
||||
if let Some(curves) = &cfg.fan_curves {
|
||||
return Ok((*curves.get_active_fan_curves()).clone());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
fn active_fan_curve_data(&mut self) -> zbus::fdo::Result<FanCurveSet> {
|
||||
if let Ok(mut ctrl) = self.inner.try_lock() {
|
||||
ctrl.config.read();
|
||||
if let Some(curves) = &ctrl.config.fan_curves {
|
||||
return Ok((*curves.get_active_fan_curves()).clone());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
}
|
||||
Err(Error::Failed("Failed to get fan curve data".to_string()))
|
||||
}
|
||||
|
||||
/// Get fan-curve data for each Profile as an array of objects
|
||||
fn fan_curves(&self) -> zbus::fdo::Result<Vec<FanCurve>> {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
cfg.read();
|
||||
if let Some(curves) = &cfg.fan_curves {
|
||||
return Ok(curves.get_all_fan_curves());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
fn fan_curves(&self) -> zbus::fdo::Result<Vec<FanCurveSet>> {
|
||||
if let Ok(mut ctrl) = self.inner.try_lock() {
|
||||
ctrl.config.read();
|
||||
if let Some(curves) = &ctrl.config.fan_curves {
|
||||
return Ok(curves.get_all_fan_curves());
|
||||
}
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
}
|
||||
Err(Error::Failed("Failed to get all fan curves".to_string()))
|
||||
}
|
||||
|
||||
/// Set this fan-curve data
|
||||
fn set_fan_curve(&self, curve: FanCurve) -> zbus::fdo::Result<()> {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(mut cfg) = ctrl.config.try_lock() {
|
||||
cfg.read();
|
||||
if let Some(curves) = &mut cfg.fan_curves {
|
||||
curves.set_fan_curve(curve);
|
||||
fn set_fan_curve(&self, curve: FanCurveSet) -> zbus::fdo::Result<()> {
|
||||
if let Ok(mut ctrl) = self.inner.try_lock() {
|
||||
ctrl.config.read();
|
||||
if let Some(mut device) = ctrl.get_device() {
|
||||
if let Some(curves) = &mut ctrl.config.fan_curves {
|
||||
curves.set_fan_curve(curve, &mut device);
|
||||
}
|
||||
} else {
|
||||
return Err(Error::Failed(UNSUPPORTED_MSG.to_string()));
|
||||
}
|
||||
|
||||
ctrl.save_config();
|
||||
}
|
||||
|
||||
@@ -139,10 +132,8 @@ impl ProfileZbus {
|
||||
impl ProfileZbus {
|
||||
fn do_notification(&self) {
|
||||
if let Ok(ctrl) = self.inner.try_lock() {
|
||||
if let Ok(cfg) = ctrl.config.clone().try_lock() {
|
||||
self.notify_profile(&cfg.active)
|
||||
.unwrap_or_else(|err| warn!("{}", err));
|
||||
}
|
||||
self.notify_profile(&ctrl.config.active)
|
||||
.unwrap_or_else(|err| warn!("{}", err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user