From 90b711c7b965fc0658e9cc859724c1d7fa5ec44f Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sat, 7 Jan 2023 20:46:00 +1300 Subject: [PATCH] Break config-traits out in to crate --- Cargo.lock | 13 +++- Cargo.toml | 2 +- MANUAL.md | 63 ++++--------------- README.md | 4 +- config-traits/Cargo.toml | 14 +++++ .../src/lib.rs | 8 +-- daemon/Cargo.toml | 2 +- daemon/src/config.rs | 7 ++- daemon/src/ctrl_anime/config.rs | 7 ++- daemon/src/ctrl_anime/trait_impls.rs | 2 +- daemon/src/ctrl_aura/config.rs | 7 ++- daemon/src/ctrl_aura/controller.rs | 2 +- daemon/src/ctrl_aura/trait_impls.rs | 2 +- daemon/src/ctrl_platform.rs | 2 +- daemon/src/ctrl_power.rs | 2 +- daemon/src/ctrl_profiles/config.rs | 53 ++++++++++++++-- daemon/src/ctrl_profiles/controller.rs | 18 +++--- daemon/src/ctrl_profiles/trait_impls.rs | 22 ++++--- daemon/src/daemon.rs | 2 +- daemon/src/lib.rs | 4 +- rog-aura/src/effects/base.rs | 6 +- rog-aura/src/effects/breathe.rs | 4 +- rog-aura/src/effects/doom.rs | 8 +-- rog-aura/src/effects/mod.rs | 4 +- rog-aura/src/effects/static_.rs | 7 ++- rog-profiles/src/lib.rs | 6 +- 26 files changed, 161 insertions(+), 110 deletions(-) create mode 100644 config-traits/Cargo.toml rename daemon/src/config_traits.rs => config-traits/src/lib.rs (96%) diff --git a/Cargo.lock b/Cargo.lock index ba35b021..33f1add9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -657,6 +657,17 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "config-traits" +version = "0.1.0" +dependencies = [ + "log", + "ron", + "serde", + "serde_derive", + "serde_json", +] + [[package]] name = "core-foundation" version = "0.9.3" @@ -782,6 +793,7 @@ version = "4.5.8" dependencies = [ "async-trait", "concat-idents", + "config-traits", "env_logger", "log", "logind-zbus", @@ -797,7 +809,6 @@ dependencies = [ "sysfs-class", "systemd-zbus", "tokio", - "toml", "zbus", ] diff --git a/Cargo.toml b/Cargo.toml index 42218fcc..775e02be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["asusctl", "daemon", "daemon-user", "rog-platform", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles", "rog-control-center"] +members = ["asusctl", "config-traits", "daemon", "daemon-user", "rog-platform", "rog-dbus", "rog-anime", "rog-aura", "rog-profiles", "rog-control-center"] [workspace.package] version = "4.5.8" diff --git a/MANUAL.md b/MANUAL.md index 113c040e..cc2ae35c 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -47,35 +47,7 @@ The LED controller (e.g, aura) enables setting many of the factory modes availab #### Supported laptops -Models GA401, GA502, GU502 support LED brightness change only (no RGB). However the GA401Q model can actually use three modes; static, breathe, and pulse, plus also use red to control the LED brightness intensity. - -All models that have any form of LED mode control need to be enabled via the config file at `/etc/asusd/asusd-ledmodes.toml`. Unfortunately ASUS doesn't provide any easy way to find all the supported modes for all laptops (not even through Armory Crate and its various files, that progrma downloads only the required settings for the laptop it runs on) so each model must be added as needed. - -#### Config options - -The defaults are located at `/etc/asusd/asusd-ledmodes.toml`, and on `asusd` start it creates `/etc/asusd/aura.conf` whcih stores the per-mode settings. If you edit the defaults file you must remove `/etc/asusd/aura.conf` and restart `asusd.service` with `systemctl restart asusd`. - -##### /etc/asusd/asusd-ledmodes.toml - -Example: -```toml -[[led_data]] -prod_family = "Strix" -board_names = ["GL504G"] -standard = ["Static", "Breathe", "Strobe", "Rainbow", "Pulse"] -multizone = ["Key1", "Key2", "Key3", "Key4", "Logo", "BarLeft", "BarRight"] -per_key = false -``` - -1. `prod_family`: you can find this in `journalctl -b -u asusd`, or `cat /sys/class/dmi/id/product_name`. It should be copied as written. There can be multiple `led-data` groups of the same `prod_family` with differing `board_names`. -2. `board_names`: is an array of board names in this product family. Find this in the journal as above or by `cat /sys/class/dmi/id/board_name`. -3. `standard` are the factory preset modes, the names should corrospond to Armory Crate names -4. `multizone`: some models have 4 to 7 zones of LED control as shown in the example. If the laptop has no zones then an empty array will suffice. -5. `per_key`: enable per-key RGB effects. The keyboard must support this or it has no effect. - -##### /etc/asusd/aura.conf - -This file can be manually edited if desired, but the `asusctl` CLI tool, or dbus methods are the preferred method. Any manual changes to this file mean that the `asusd.service` will need to be restarted, or you need to cycle between modes to force a reload. +There are over 60 supported laptops as of 01-01-2023. Please see [the rog-aura crate readme for further details](/rog-aura/README.md). ### Charge control @@ -199,33 +171,20 @@ An Aura config itself is a file with contents: If your laptop supports multizone, `"led_type"` can also be `"Zone": ` - `"None"` -- `"KeyboardLeft"` -- `"KeyboardCenterLeft"` -- `"KeyboardCenterRight"` -- `"KeyboardRight"` -- `"LightbarRight"` -- `"LightbarRightCorner"` -- `"LightbarRightBottom"` -- `"LightbarLeftBottom"` -- `"LightbarLeftCorner"` -- `"LightbarLeft"` +- `ZonedKbLeft` // keyboard left +- `ZonedKbLeftMid` // keyboard left-middle +- `ZonedKbRightMid` // etc +- `ZonedKbRight` +- `LightbarRight` +- `LightbarRightCorner` +- `LightbarRightBottom` +- `LightbarLeftBottom` +- `LightbarLeftCorner` +- `LightbarLeft` At the moment there are only three effects available as shown in the example. More will come in the future but this may take me some time. -**Aura layouts**: `asusd-user` does its best to find a suitable layout to use based on `/sys/class/dmi/id/board_name`. -It looks at each of the files in `/usr/share/rog-gui/layouts/` and matches against the toml block looking like: -```toml -matches = [ - 'GX502', - 'GU502', -] -``` - -My laptop is a `GX502GW`, so `GX502` is a match. Note that these layouts are the physical representation of -the keyboard and are used in the GUI also. The config that tells if per-key is supported is located in -`/etc/asusd/asusd-ledmodes.toml` - #### Config options: AniMe `~/.config/rog/rog-user.cfg` contains a setting `"active_anime": ""` where `` is the name of the AniMe config to use, located in the same directory and without the file postfix, e.g, `"active_anime": "anime-doom"` diff --git a/README.md b/README.md index 9c778eee..83f869ed 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Now includes a GUI, `rog-control-center`. **The minimum supported kernel version is 5.17** +**For TUF laptops, the minimum supported kernel version is 6.1** + ## Goals 1. To provide an interface for rootless control of some system functions most users wish to control such as fan speeds, keyboard LEDs, graphics modes. @@ -43,8 +45,6 @@ Bus 001 Device 002: ID 0b05:1866 ASUSTek Computer, Inc. N-KEY Device then it may work without tweaks. Technically all other functions except the LED and AniMe parts should work regardless of your latop make. -**TUF Laptops**: now supported provided the kernel is patched. These patches are submitted upstream and will be in version 6.1.x of the kernel (or thereabouts). See the blog on asus-linux.org for more info. - ## Implemented - [X] System daemon diff --git a/config-traits/Cargo.toml b/config-traits/Cargo.toml new file mode 100644 index 00000000..a9de8d4f --- /dev/null +++ b/config-traits/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "config-traits" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde.workspace = true +serde_derive.workspace = true +serde_json.workspace = true +ron.workspace = true + +log.workspace = true \ No newline at end of file diff --git a/daemon/src/config_traits.rs b/config-traits/src/lib.rs similarity index 96% rename from daemon/src/config_traits.rs rename to config-traits/src/lib.rs index fad109d7..6f8f6115 100644 --- a/daemon/src/config_traits.rs +++ b/config-traits/src/lib.rs @@ -7,8 +7,6 @@ use ron::ser::PrettyConfig; use serde::de::DeserializeOwned; use serde::Serialize; -const CONFIG_PATH_BASE: &str = "/etc/asusd/"; - /// Config file helper traits. Only `new()` and `file_name()` are required to be /// implemented, the rest are intended to be free methods. pub trait StdConfig @@ -19,11 +17,13 @@ where fn file_name() -> &'static str; + fn config_dir() -> PathBuf; + fn file_path() -> PathBuf { - let mut config = PathBuf::from(CONFIG_PATH_BASE); + let mut config = Self::config_dir(); if !config.exists() { create_dir(config.as_path()) - .unwrap_or_else(|e| panic!("Could not create {CONFIG_PATH_BASE} {e}")); + .unwrap_or_else(|e| panic!("Could not create {:?} {e}", Self::config_dir())); } config.push(Self::file_name()); config diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index 13f02d68..f5580976 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -18,6 +18,7 @@ name = "asusd" path = "src/daemon.rs" [dependencies] +config-traits = { path = "../config-traits" } rog_anime = { path = "../rog-anime", features = ["dbus"] } rog_aura = { path = "../rog-aura", features = ["dbus"] } rog_platform = { path = "../rog-platform" } @@ -38,7 +39,6 @@ logind-zbus.workspace = true serde.workspace = true serde_derive.workspace = true serde_json.workspace = true -toml.workspace = true ron.workspace = true # Device control diff --git a/daemon/src/config.rs b/daemon/src/config.rs index 70c02bd3..fb9d055f 100644 --- a/daemon/src/config.rs +++ b/daemon/src/config.rs @@ -1,7 +1,6 @@ +use config_traits::{StdConfig, StdConfigLoad3}; use serde_derive::{Deserialize, Serialize}; -use crate::config_traits::{StdConfig, StdConfigLoad3}; - const CONFIG_FILE: &str = "asusd.conf"; #[derive(Deserialize, Serialize, Default)] @@ -25,6 +24,10 @@ impl StdConfig for Config { } } + fn config_dir() -> std::path::PathBuf { + std::path::PathBuf::from(crate::CONFIG_PATH_BASE) + } + fn file_name() -> &'static str { CONFIG_FILE } diff --git a/daemon/src/ctrl_anime/config.rs b/daemon/src/ctrl_anime/config.rs index 3d03fdd3..6f801e55 100644 --- a/daemon/src/ctrl_anime/config.rs +++ b/daemon/src/ctrl_anime/config.rs @@ -1,11 +1,10 @@ use std::time::Duration; +use config_traits::{StdConfig, StdConfigLoad3}; use rog_anime::error::AnimeError; use rog_anime::{ActionData, ActionLoader, AnimTime, AnimeType, Fade, Vec2}; use serde_derive::{Deserialize, Serialize}; -use crate::config_traits::{StdConfig, StdConfigLoad3}; - const CONFIG_FILE: &str = "anime.conf"; #[derive(Deserialize, Serialize)] @@ -141,6 +140,10 @@ impl StdConfig for AnimeConfig { Self::create_default() } + fn config_dir() -> std::path::PathBuf { + std::path::PathBuf::from(crate::CONFIG_PATH_BASE) + } + fn file_name() -> &'static str { CONFIG_FILE } diff --git a/daemon/src/ctrl_anime/trait_impls.rs b/daemon/src/ctrl_anime/trait_impls.rs index f43ace2b..05711dd3 100644 --- a/daemon/src/ctrl_anime/trait_impls.rs +++ b/daemon/src/ctrl_anime/trait_impls.rs @@ -2,6 +2,7 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use async_trait::async_trait; +use config_traits::StdConfig; use log::{info, warn}; use rog_anime::usb::{pkt_for_apply, pkt_for_set_boot, pkt_for_set_on}; use rog_anime::{AnimeDataBuffer, AnimePowerStates}; @@ -9,7 +10,6 @@ use zbus::export::futures_util::lock::{Mutex, MutexGuard}; use zbus::{dbus_interface, Connection, SignalContext}; use super::CtrlAnime; -use crate::config_traits::StdConfig; use crate::error::RogError; pub(super) const ZBUS_PATH: &str = "/org/asuslinux/Anime"; diff --git a/daemon/src/ctrl_aura/config.rs b/daemon/src/ctrl_aura/config.rs index 453317ea..c160ec3c 100644 --- a/daemon/src/ctrl_aura/config.rs +++ b/daemon/src/ctrl_aura/config.rs @@ -1,5 +1,6 @@ use std::collections::{BTreeMap, HashSet}; +use config_traits::{StdConfig, StdConfigLoad1}; use rog_aura::aura_detection::{LaptopLedData, ASUS_KEYBOARD_DEVICES}; use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraDevTuf, AuraDevice, AuraPowerDev}; use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT}; @@ -7,8 +8,6 @@ use rog_platform::hid_raw::HidRaw; use rog_platform::keyboard_led::KeyboardLed; use serde_derive::{Deserialize, Serialize}; -use crate::config_traits::{StdConfig, StdConfigLoad1}; - const CONFIG_FILE: &str = "aura.conf"; /// Enable/disable LED control in various states such as @@ -191,6 +190,10 @@ impl StdConfig for AuraConfig { Self::create_default(&LaptopLedData::get_data()) } + fn config_dir() -> std::path::PathBuf { + std::path::PathBuf::from(crate::CONFIG_PATH_BASE) + } + fn file_name() -> &'static str { CONFIG_FILE } diff --git a/daemon/src/ctrl_aura/controller.rs b/daemon/src/ctrl_aura/controller.rs index 7d43904a..bf65016f 100644 --- a/daemon/src/ctrl_aura/controller.rs +++ b/daemon/src/ctrl_aura/controller.rs @@ -1,5 +1,6 @@ use std::collections::BTreeMap; +use config_traits::StdConfig; use log::{info, warn}; use rog_aura::advanced::{LedUsbPackets, UsbPackets}; use rog_aura::aura_detection::{LaptopLedData, ASUS_KEYBOARD_DEVICES}; @@ -10,7 +11,6 @@ use rog_platform::keyboard_led::KeyboardLed; use rog_platform::supported::LedSupportedFunctions; use super::config::{AuraConfig, AuraPowerConfig}; -use crate::config_traits::StdConfig; use crate::error::RogError; use crate::GetSupported; diff --git a/daemon/src/ctrl_aura/trait_impls.rs b/daemon/src/ctrl_aura/trait_impls.rs index 3985afe8..5eef5187 100644 --- a/daemon/src/ctrl_aura/trait_impls.rs +++ b/daemon/src/ctrl_aura/trait_impls.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use std::sync::Arc; use async_trait::async_trait; +use config_traits::StdConfig; use log::{error, info, warn}; use rog_aura::advanced::UsbPackets; use rog_aura::usb::AuraPowerDev; @@ -11,7 +12,6 @@ use zbus::export::futures_util::StreamExt; use zbus::{dbus_interface, Connection, SignalContext}; use super::controller::CtrlKbdLed; -use crate::config_traits::StdConfig; use crate::error::RogError; use crate::CtrlTask; diff --git a/daemon/src/ctrl_platform.rs b/daemon/src/ctrl_platform.rs index 904d343f..e9c81e36 100644 --- a/daemon/src/ctrl_platform.rs +++ b/daemon/src/ctrl_platform.rs @@ -5,6 +5,7 @@ use std::process::Command; use std::sync::Arc; use async_trait::async_trait; +use config_traits::StdConfig; use log::{info, warn}; use rog_platform::platform::{AsusPlatform, GpuMode}; use rog_platform::supported::RogBiosSupportedFunctions; @@ -12,7 +13,6 @@ use zbus::export::futures_util::lock::Mutex; use zbus::{dbus_interface, Connection, SignalContext}; use crate::config::Config; -use crate::config_traits::StdConfig; use crate::error::RogError; use crate::{task_watch_item, CtrlTask, GetSupported}; diff --git a/daemon/src/ctrl_power.rs b/daemon/src/ctrl_power.rs index b78c7ecb..df8b6814 100644 --- a/daemon/src/ctrl_power.rs +++ b/daemon/src/ctrl_power.rs @@ -3,6 +3,7 @@ use std::sync::Arc; use std::time::Duration; use async_trait::async_trait; +use config_traits::StdConfig; use log::{error, info, warn}; use rog_platform::power::AsusPower; use rog_platform::supported::ChargeSupportedFunctions; @@ -12,7 +13,6 @@ use zbus::export::futures_util::lock::Mutex; use zbus::{dbus_interface, Connection, SignalContext}; use crate::config::Config; -use crate::config_traits::StdConfig; use crate::error::RogError; use crate::{task_watch_item, CtrlTask, GetSupported}; diff --git a/daemon/src/ctrl_profiles/config.rs b/daemon/src/ctrl_profiles/config.rs index 0bb1e25c..c683a7a0 100644 --- a/daemon/src/ctrl_profiles/config.rs +++ b/daemon/src/ctrl_profiles/config.rs @@ -1,7 +1,11 @@ +use std::path::PathBuf; + +use config_traits::{StdConfig, StdConfigLoad1}; +use rog_profiles::fan_curve_set::FanCurveSet; use rog_profiles::{FanCurveProfiles, Profile}; use serde_derive::{Deserialize, Serialize}; -use crate::config_traits::{StdConfig, StdConfigLoad1}; +use crate::CONFIG_PATH_BASE; const CONFIG_FILE: &str = "profile.conf"; const CONFIG_FAN_FILE: &str = "fan_curves.conf"; @@ -19,6 +23,10 @@ impl StdConfig for ProfileConfig { } } + fn config_dir() -> std::path::PathBuf { + PathBuf::from(CONFIG_PATH_BASE) + } + fn file_name() -> &'static str { CONFIG_FILE } @@ -26,9 +34,46 @@ impl StdConfig for ProfileConfig { impl StdConfigLoad1 for ProfileConfig {} -impl StdConfig for FanCurveProfiles { +#[derive(Deserialize, Serialize, Debug, Default)] +pub struct FanCurveConfig { + balanced: FanCurveSet, + performance: FanCurveSet, + quiet: FanCurveSet, + #[serde(skip)] + device: FanCurveProfiles, +} + +impl FanCurveConfig { + pub fn update_device_config(&mut self) { + self.balanced = self.device.balanced.clone(); + self.performance = self.device.performance.clone(); + self.quiet = self.device.quiet.clone(); + } + + pub fn update_config(&mut self) { + self.balanced = self.device.balanced.clone(); + self.performance = self.device.performance.clone(); + self.quiet = self.device.quiet.clone(); + } + + pub fn device(&self) -> &FanCurveProfiles { + &self.device + } + + pub fn device_mut(&mut self) -> &mut FanCurveProfiles { + &mut self.device + } +} + +impl StdConfig for FanCurveConfig { fn new() -> Self { - Self::default() + let mut tmp = Self::default(); + tmp.update_device_config(); + tmp + } + + fn config_dir() -> std::path::PathBuf { + PathBuf::from(CONFIG_PATH_BASE) } fn file_name() -> &'static str { @@ -36,4 +81,4 @@ impl StdConfig for FanCurveProfiles { } } -impl StdConfigLoad1 for FanCurveProfiles {} +impl StdConfigLoad1 for FanCurveConfig {} diff --git a/daemon/src/ctrl_profiles/controller.rs b/daemon/src/ctrl_profiles/controller.rs index 3a8f0af9..ef15ceb3 100644 --- a/daemon/src/ctrl_profiles/controller.rs +++ b/daemon/src/ctrl_profiles/controller.rs @@ -1,17 +1,17 @@ +use config_traits::StdConfig; use log::{info, warn}; use rog_platform::platform::AsusPlatform; use rog_platform::supported::PlatformProfileFunctions; use rog_profiles::error::ProfileError; use rog_profiles::{FanCurveProfiles, Profile}; -use super::config::ProfileConfig; -use crate::config_traits::StdConfig; +use super::config::{FanCurveConfig, ProfileConfig}; use crate::error::RogError; use crate::GetSupported; pub struct CtrlPlatformProfile { pub profile_config: ProfileConfig, - pub fan_config: Option, + pub fan_config: Option, pub platform: AsusPlatform, } @@ -69,7 +69,7 @@ impl CtrlPlatformProfile { if let Some(curves) = controller.fan_config.as_ref() { info!( "{active:?}: {}", - String::from(curves.get_fan_curves_for(active)) + String::from(curves.device().get_fan_curves_for(active)) ); curves.write(); } @@ -83,9 +83,10 @@ impl CtrlPlatformProfile { Err(ProfileError::NotSupported.into()) } - pub fn save_config(&self) { + pub fn save_config(&mut self) { self.profile_config.write(); - if let Some(fans) = self.fan_config.as_ref() { + if let Some(fans) = self.fan_config.as_mut() { + fans.update_config(); fans.write(); } } @@ -116,7 +117,7 @@ impl CtrlPlatformProfile { pub(super) fn write_profile_curve_to_platform(&mut self) -> Result<(), RogError> { if let Some(curves) = &mut self.fan_config { if let Ok(mut device) = FanCurveProfiles::get_device() { - curves.write_profile_curve_to_platform( + curves.device_mut().write_profile_curve_to_platform( self.profile_config.active_profile, &mut device, )?; @@ -128,10 +129,11 @@ impl CtrlPlatformProfile { pub(super) fn set_active_curve_to_defaults(&mut self) -> Result<(), RogError> { if let Some(curves) = self.fan_config.as_mut() { if let Ok(mut device) = FanCurveProfiles::get_device() { - curves.set_active_curve_to_defaults( + curves.device_mut().set_active_curve_to_defaults( self.profile_config.active_profile, &mut device, )?; + curves.update_config(); } } Ok(()) diff --git a/daemon/src/ctrl_profiles/trait_impls.rs b/daemon/src/ctrl_profiles/trait_impls.rs index 018f0785..84865e02 100644 --- a/daemon/src/ctrl_profiles/trait_impls.rs +++ b/daemon/src/ctrl_profiles/trait_impls.rs @@ -2,6 +2,7 @@ use std::str::FromStr; use std::sync::Arc; use async_trait::async_trait; +use config_traits::StdConfig; use log::{error, info, warn}; use rog_profiles::fan_curve_set::{CurveData, FanCurveSet}; use rog_profiles::{FanCurveProfiles, Profile}; @@ -11,7 +12,6 @@ use zbus::fdo::Error; use zbus::{dbus_interface, Connection, SignalContext}; use super::controller::CtrlPlatformProfile; -use crate::config_traits::StdConfig; use crate::error::RogError; use crate::CtrlTask; @@ -82,8 +82,8 @@ impl ProfileZbus { async fn enabled_fan_profiles(&mut self) -> zbus::fdo::Result> { let mut ctrl = self.0.lock().await; ctrl.profile_config.read(); - if let Some(curves) = &ctrl.fan_config { - return Ok(curves.get_enabled_curve_profiles()); + if let Some(curves) = &mut ctrl.fan_config { + return Ok(curves.device().get_enabled_curve_profiles()); } Err(Error::Failed(UNSUPPORTED_MSG.to_owned())) } @@ -98,7 +98,10 @@ impl ProfileZbus { let mut ctrl = self.0.lock().await; ctrl.profile_config.read(); if let Some(curves) = &mut ctrl.fan_config { - curves.set_profile_curve_enabled(profile, enabled); + curves + .device_mut() + .set_profile_curve_enabled(profile, enabled); + curves.update_config(); ctrl.write_profile_curve_to_platform() .map_err(|e| warn!("write_profile_curve_to_platform, {}", e)) @@ -115,8 +118,8 @@ impl ProfileZbus { async fn fan_curve_data(&mut self, profile: Profile) -> zbus::fdo::Result { let mut ctrl = self.0.lock().await; ctrl.profile_config.read(); - if let Some(curves) = &ctrl.fan_config { - let curve = curves.get_fan_curves_for(profile); + if let Some(curves) = &mut ctrl.fan_config { + let curve = curves.device().get_fan_curves_for(profile); return Ok(curve.clone()); } Err(Error::Failed(UNSUPPORTED_MSG.to_owned())) @@ -129,8 +132,10 @@ impl ProfileZbus { ctrl.profile_config.read(); if let Some(curves) = &mut ctrl.fan_config { curves + .device_mut() .save_fan_curve(curve, profile) .map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?; + curves.update_config(); } else { return Err(Error::Failed(UNSUPPORTED_MSG.to_owned())); } @@ -295,7 +300,10 @@ impl crate::Reloadable for ProfileZbus { // There is a possibility that the curve was default zeroed, so this call // initialises the data from system read and we need to save it // after - curves.write_profile_curve_to_platform(active, &mut device)?; + curves + .device_mut() + .write_profile_curve_to_platform(active, &mut device)?; + curves.update_config(); ctrl.profile_config.write(); } } diff --git a/daemon/src/daemon.rs b/daemon/src/daemon.rs index 8ddfff80..428c5b59 100644 --- a/daemon/src/daemon.rs +++ b/daemon/src/daemon.rs @@ -6,8 +6,8 @@ use std::time::Duration; use ::zbus::export::futures_util::lock::Mutex; use ::zbus::Connection; +use config_traits::{StdConfigLoad1, StdConfigLoad3}; use daemon::config::Config; -use daemon::config_traits::{StdConfigLoad1, StdConfigLoad3}; use daemon::ctrl_anime::config::AnimeConfig; use daemon::ctrl_anime::trait_impls::CtrlAnimeZbus; use daemon::ctrl_anime::CtrlAnime; diff --git a/daemon/src/lib.rs b/daemon/src/lib.rs index 2cde6dac..d752acfa 100644 --- a/daemon/src/lib.rs +++ b/daemon/src/lib.rs @@ -1,8 +1,6 @@ #![deny(unused_must_use)] /// Configuration loading, saving pub mod config; -/// Base traits for configuration file loading -pub mod config_traits; /// Control of anime matrix display pub mod ctrl_anime; /// Keyboard LED brightness control, RGB, and LED display modes @@ -30,6 +28,8 @@ use zbus::{Connection, SignalContext}; use crate::error::RogError; +const CONFIG_PATH_BASE: &str = "/etc/asusd/"; + /// This macro adds a function which spawns an `inotify` task on the passed in /// `Executor`. /// diff --git a/rog-aura/src/effects/base.rs b/rog-aura/src/effects/base.rs index dd57116f..32aae496 100644 --- a/rog-aura/src/effects/base.rs +++ b/rog-aura/src/effects/base.rs @@ -3,7 +3,7 @@ use crate::advanced::LedCode; use crate::Colour; pub struct InputBased { - address: LedCode, + led: LedCode, colour: Colour, /// - audio /// - cpu freq @@ -24,10 +24,10 @@ impl EffectState for InputBased { } fn get_led(&self) -> LedCode { - self.address + self.led } fn set_led(&mut self, address: LedCode) { - self.address = address + self.led = address } } diff --git a/rog-aura/src/effects/breathe.rs b/rog-aura/src/effects/breathe.rs index 8b74f1c4..e2f00fca 100644 --- a/rog-aura/src/effects/breathe.rs +++ b/rog-aura/src/effects/breathe.rs @@ -7,7 +7,7 @@ use crate::{effect_state_impl, Colour, Speed}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Breathe { - address: LedCode, + led: LedCode, /// The starting colour start_colour1: Colour, /// The secondary starting colour @@ -26,7 +26,7 @@ pub struct Breathe { impl Breathe { pub fn new(address: LedCode, colour1: Colour, colour2: Colour, speed: Speed) -> Self { Self { - address, + led: address, start_colour1: colour1, start_colour2: colour2, speed, diff --git a/rog-aura/src/effects/doom.rs b/rog-aura/src/effects/doom.rs index ab23efc3..e0bf73a7 100644 --- a/rog-aura/src/effects/doom.rs +++ b/rog-aura/src/effects/doom.rs @@ -7,7 +7,7 @@ use crate::{effect_state_impl, Colour}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct DoomFlicker { - address: LedCode, + led: LedCode, start_colour: Colour, max_percentage: u8, min_percentage: u8, @@ -20,7 +20,7 @@ pub struct DoomFlicker { impl DoomFlicker { pub fn new(address: LedCode, colour: Colour, max_percentage: u8, min_percentage: u8) -> Self { Self { - address, + led: address, colour, count: 4, max_percentage, @@ -94,7 +94,7 @@ pub struct LightFlash { #[derive(Debug, Clone, Deserialize, Serialize)] pub struct DoomLightFlash { - address: LedCode, + led: LedCode, start_colour: Colour, max_percentage: u8, min_percentage: u8, @@ -111,7 +111,7 @@ pub struct DoomLightFlash { impl DoomLightFlash { pub fn new(address: LedCode, colour: Colour, max_percentage: u8, min_percentage: u8) -> Self { Self { - address, + led: address, colour, count: 4, max_percentage, diff --git a/rog-aura/src/effects/mod.rs b/rog-aura/src/effects/mod.rs index f479518d..88a53b3a 100644 --- a/rog-aura/src/effects/mod.rs +++ b/rog-aura/src/effects/mod.rs @@ -133,12 +133,12 @@ macro_rules! effect_state_impl { } fn get_led(&self) -> $crate::advanced::LedCode { - self.address.clone() + self.led.clone() } /// Change the led type fn set_led(&mut self, address: $crate::advanced::LedCode) { - self.address = address; + self.led = address; } }; } diff --git a/rog-aura/src/effects/static_.rs b/rog-aura/src/effects/static_.rs index 18925a83..8e2b4bd9 100644 --- a/rog-aura/src/effects/static_.rs +++ b/rog-aura/src/effects/static_.rs @@ -7,14 +7,17 @@ use crate::{effect_state_impl, Colour}; #[derive(Debug, Clone, Deserialize, Serialize)] pub struct Static { - address: LedCode, + led: LedCode, /// The starting colour colour: Colour, } impl Static { pub fn new(address: LedCode, colour: Colour) -> Self { - Self { address, colour } + Self { + led: address, + colour, + } } } diff --git a/rog-profiles/src/lib.rs b/rog-profiles/src/lib.rs index aaf8f030..269c2fa0 100644 --- a/rog-profiles/src/lib.rs +++ b/rog-profiles/src/lib.rs @@ -162,9 +162,9 @@ impl Default for FanCurvePU { #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Deserialize, Serialize, Debug, Default)] pub struct FanCurveProfiles { - balanced: FanCurveSet, - performance: FanCurveSet, - quiet: FanCurveSet, + pub balanced: FanCurveSet, + pub performance: FanCurveSet, + pub quiet: FanCurveSet, } impl FanCurveProfiles {