mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fix profile controller not detecting if platform_profile is changed
Closes #313
This commit is contained in:
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- ROGCC: Add CLI opt for loading a keyboard layout for testing, with live-reload on file change
|
- ROGCC: Add CLI opt for loading a keyboard layout for testing, with live-reload on file change
|
||||||
- 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
|
||||||
### 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:
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::{info, warn};
|
use log::{error, info, warn};
|
||||||
use rog_profiles::fan_curve_set::{CurveData, FanCurveSet};
|
use rog_profiles::fan_curve_set::{CurveData, FanCurveSet};
|
||||||
use rog_profiles::{FanCurveProfiles, Profile};
|
use rog_profiles::{FanCurveProfiles, Profile};
|
||||||
use zbus::export::futures_util::lock::Mutex;
|
use zbus::export::futures_util::lock::Mutex;
|
||||||
@@ -200,6 +201,7 @@ impl CtrlTask for ProfileZbus {
|
|||||||
|
|
||||||
async fn create_tasks(&self, signal_ctxt: SignalContext<'static>) -> Result<(), RogError> {
|
async fn create_tasks(&self, signal_ctxt: SignalContext<'static>) -> Result<(), RogError> {
|
||||||
let ctrl = self.0.clone();
|
let ctrl = self.0.clone();
|
||||||
|
let sig_ctx = signal_ctxt.clone();
|
||||||
let mut watch = self
|
let mut watch = self
|
||||||
.0
|
.0
|
||||||
.lock()
|
.lock()
|
||||||
@@ -209,25 +211,73 @@ impl CtrlTask for ProfileZbus {
|
|||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut buffer = [0; 32];
|
let mut buffer = [0; 32];
|
||||||
watch
|
if let Ok(stream) = watch.event_stream(&mut buffer) {
|
||||||
.event_stream(&mut buffer)
|
stream
|
||||||
.unwrap()
|
.for_each(|_| async {
|
||||||
.for_each(|_| async {
|
let mut lock = ctrl.lock().await;
|
||||||
let mut lock = ctrl.lock().await;
|
if let Ok(profile) =
|
||||||
let new_thermal = lock.platform.get_throttle_thermal_policy().unwrap();
|
lock.platform.get_throttle_thermal_policy().map_err(|e| {
|
||||||
let new_profile = Profile::from_throttle_thermal_policy(new_thermal);
|
error!("get_throttle_thermal_policy error: {e}");
|
||||||
if new_profile != lock.profile_config.active_profile {
|
})
|
||||||
info!("throttle_thermal_policy changed to {new_profile}");
|
{
|
||||||
lock.profile_config.active_profile = new_profile;
|
let new_profile = Profile::from_throttle_thermal_policy(profile);
|
||||||
lock.write_profile_curve_to_platform().unwrap();
|
if new_profile != lock.profile_config.active_profile {
|
||||||
lock.save_config();
|
info!("platform_profile changed to {new_profile}");
|
||||||
Profile::set_profile(lock.profile_config.active_profile).unwrap();
|
lock.profile_config.active_profile = new_profile;
|
||||||
}
|
lock.write_profile_curve_to_platform().unwrap();
|
||||||
Self::notify_profile(&signal_ctxt, lock.profile_config.active_profile)
|
lock.save_config();
|
||||||
.await
|
Profile::set_profile(lock.profile_config.active_profile)
|
||||||
.ok();
|
.map_err(|e| {
|
||||||
})
|
error!("Profile::set_profile() error: {e}");
|
||||||
.await;
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
Self::notify_profile(&sig_ctx, lock.profile_config.active_profile)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let ctrl = self.0.clone();
|
||||||
|
let mut watch = self.0.lock().await.platform.monitor_platform_profile()?;
|
||||||
|
|
||||||
|
tokio::spawn(async move {
|
||||||
|
let mut buffer = [0; 32];
|
||||||
|
if let Ok(stream) = watch.event_stream(&mut buffer) {
|
||||||
|
stream
|
||||||
|
.for_each(|_| async {
|
||||||
|
let mut lock = ctrl.lock().await;
|
||||||
|
if let Ok(profile) = lock.platform.get_platform_profile().map_err(|e| {
|
||||||
|
error!("get_platform_profile error: {e}");
|
||||||
|
}) {
|
||||||
|
if let Ok(new_profile) = Profile::from_str(&profile).map_err(|e| {
|
||||||
|
error!("Profile::from_str(&profile) error: {e}");
|
||||||
|
}) {
|
||||||
|
if new_profile != lock.profile_config.active_profile {
|
||||||
|
info!("platform_profile changed to {new_profile}");
|
||||||
|
lock.profile_config.active_profile = new_profile;
|
||||||
|
lock.write_profile_curve_to_platform().unwrap();
|
||||||
|
lock.save_config();
|
||||||
|
Profile::set_profile(lock.profile_config.active_profile)
|
||||||
|
.map_err(|e| {
|
||||||
|
error!("Profile::set_profile() error: {e}");
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
Self::notify_profile(
|
||||||
|
&signal_ctxt,
|
||||||
|
lock.profile_config.active_profile,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -82,6 +82,21 @@ pub fn write_attr_u8_array(device: &mut Device, attr: &str, values: &[u8]) -> Re
|
|||||||
.map_err(|e| PlatformError::IoPath(attr.into(), e))
|
.map_err(|e| PlatformError::IoPath(attr.into(), e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn read_attr_string(device: &Device, attr_name: &str) -> Result<String> {
|
||||||
|
if let Some(value) = device.attribute_value(attr_name) {
|
||||||
|
let tmp = value.to_string_lossy().to_string();
|
||||||
|
return Ok(tmp);
|
||||||
|
}
|
||||||
|
Err(PlatformError::AttrNotFound(attr_name.to_owned()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_attr_string(device: &mut Device, attr: &str, value: &str) -> Result<()> {
|
||||||
|
let tmp = value.trim();
|
||||||
|
device
|
||||||
|
.set_attribute_value(attr, tmp)
|
||||||
|
.map_err(|e| PlatformError::IoPath(attr.into(), e))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -141,3 +141,37 @@ macro_rules! attr_u8_array {
|
|||||||
$crate::watch_attr!($attr_name $item);
|
$crate::watch_attr!($attr_name $item);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! get_attr_string {
|
||||||
|
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
|
||||||
|
concat_idents::concat_idents!(fn_name = get_, $attr_name {
|
||||||
|
$(#[$doc_comment])*
|
||||||
|
pub fn fn_name(&self) -> Result<String> {
|
||||||
|
$crate::read_attr_string(&to_device(&self.$item)?, $attr_name)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! set_attr_string {
|
||||||
|
($(#[$doc_comment:meta])? $attr_name:literal $item:ident) => {
|
||||||
|
concat_idents::concat_idents!(fn_name = set_, $attr_name {
|
||||||
|
$(#[$doc_comment])*
|
||||||
|
pub fn fn_name(&self, values: &str) -> Result<()> {
|
||||||
|
$crate::write_attr_string(&mut to_device(&self.$item)?, $attr_name, values)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! attr_string {
|
||||||
|
($attr_name:literal, $item:ident) => {
|
||||||
|
$crate::has_attr!($attr_name $item);
|
||||||
|
$crate::get_attr_string!($attr_name $item);
|
||||||
|
$crate::set_attr_string!($attr_name $item);
|
||||||
|
$crate::watch_attr!($attr_name $item);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use zbus::zvariant::Type;
|
use zbus::zvariant::Type;
|
||||||
|
|
||||||
use crate::error::{PlatformError, Result};
|
use crate::error::{PlatformError, Result};
|
||||||
use crate::{attr_bool, attr_u8, to_device};
|
use crate::{attr_bool, attr_string, attr_u8, to_device};
|
||||||
|
|
||||||
/// The "platform" device provides access to things like:
|
/// The "platform" device provides access to things like:
|
||||||
/// - `dgpu_disable`
|
/// - `dgpu_disable`
|
||||||
@@ -36,7 +36,7 @@ impl AsusPlatform {
|
|||||||
attr_u8!("throttle_thermal_policy", path);
|
attr_u8!("throttle_thermal_policy", path);
|
||||||
|
|
||||||
// The acpi platform_profile support
|
// The acpi platform_profile support
|
||||||
attr_u8!("platform_profile", pp_path);
|
attr_string!("platform_profile", pp_path);
|
||||||
|
|
||||||
pub fn new() -> Result<Self> {
|
pub fn new() -> Result<Self> {
|
||||||
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
||||||
|
|||||||
Reference in New Issue
Block a user