From acf41c1783d869208bdf704221f31ffa6a5aadff Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Mon, 26 Jun 2023 10:44:58 +1200 Subject: [PATCH] Add support for mini_led_mode get/set - asusd get/set, zbus methods - Rog control center notification, tray menu, UI entry --- CHANGELOG.md | 2 + asusd/src/config.rs | 20 ++++++--- asusd/src/ctrl_platform.rs | 45 +++++++++++++++---- rog-control-center/src/system_state.rs | 24 +++++----- rog-control-center/src/tray.rs | 27 ++++++++++- rog-control-center/src/update_and_notify.rs | 16 +++++++ .../src/widgets/app_settings.rs | 6 +++ rog-control-center/src/widgets/rog_bios.rs | 21 ++++++++- rog-dbus/src/zbus_platform.rs | 10 +++++ rog-platform/src/platform.rs | 2 + rog-platform/src/supported.rs | 2 + 11 files changed, 144 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6a6d500..5851cff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Builtin animations - In-progress simulators for GA402, GU604 animatrix, optional build and takes a single arg - Add `model_override` option to anime config, this is handy for forcing a model for "Unknown" anime, and for simulators +- Add `mini_led_mode` support to asusd and zbus crates (requires kernel patch https://lkml.org/lkml/2023/6/19/1264) +- Add `mini_led_mode` toggle to rog-control-center GUI, tray, notifications ### Changed - Move FX506HC to FX506H in arua DB to catch full series of this range - Move FX506LH to FX506L in arua DB to catch full series of this range diff --git a/asusd/src/config.rs b/asusd/src/config.rs index a1669651..0635bf49 100644 --- a/asusd/src/config.rs +++ b/asusd/src/config.rs @@ -8,6 +8,7 @@ pub struct Config { /// Save charge limit for restoring on boot pub bat_charge_limit: u8, pub panel_od: bool, + pub mini_led_mode: bool, pub disable_nvidia_powerd_on_battery: bool, pub ac_command: String, pub bat_command: String, @@ -18,6 +19,7 @@ impl StdConfig for Config { Config { bat_charge_limit: 100, panel_od: false, + mini_led_mode: false, disable_nvidia_powerd_on_battery: true, ac_command: String::new(), bat_command: String::new(), @@ -33,21 +35,24 @@ impl StdConfig for Config { } } -impl StdConfigLoad2 for Config {} +impl StdConfigLoad2 for Config {} -#[derive(Deserialize, Serialize, Default)] -#[serde(default)] -pub struct Config455 { +#[derive(Deserialize, Serialize)] +pub struct Config462 { /// Save charge limit for restoring on boot pub bat_charge_limit: u8, pub panel_od: bool, + pub disable_nvidia_powerd_on_battery: bool, + pub ac_command: String, + pub bat_command: String, } -impl From for Config { - fn from(c: Config455) -> Self { +impl From for Config { + fn from(c: Config462) -> Self { Self { bat_charge_limit: c.bat_charge_limit, panel_od: c.panel_od, + mini_led_mode: false, disable_nvidia_powerd_on_battery: true, ac_command: String::new(), bat_command: String::new(), @@ -55,7 +60,7 @@ impl From for Config { } } -#[derive(Deserialize, Serialize, Default)] +#[derive(Deserialize, Serialize)] pub struct Config458 { /// Save charge limit for restoring on boot pub bat_charge_limit: u8, @@ -69,6 +74,7 @@ impl From for Config { Self { bat_charge_limit: c.bat_charge_limit, panel_od: c.panel_od, + mini_led_mode: false, disable_nvidia_powerd_on_battery: true, ac_command: c.ac_command, bat_command: c.bat_command, diff --git a/asusd/src/ctrl_platform.rs b/asusd/src/ctrl_platform.rs index c6057627..8a7150bd 100644 --- a/asusd/src/ctrl_platform.rs +++ b/asusd/src/ctrl_platform.rs @@ -31,12 +31,14 @@ impl GetSupported for CtrlPlatform { fn get_supported() -> Self::A { let mut panel_overdrive = false; + let mut mini_led_mode = false; let mut dgpu_disable = false; let mut egpu_enable = false; let mut gpu_mux = false; if let Ok(platform) = AsusPlatform::new() { panel_overdrive = platform.has_panel_od(); + mini_led_mode = platform.has_mini_led_mode(); dgpu_disable = platform.has_dgpu_disable(); egpu_enable = platform.has_egpu_enable(); gpu_mux = platform.has_gpu_mux_mode(); @@ -46,6 +48,7 @@ impl GetSupported for CtrlPlatform { post_sound: Path::new(ASUS_POST_LOGO_SOUND).exists(), gpu_mux, panel_overdrive, + mini_led_mode, dgpu_disable, egpu_enable, } @@ -214,25 +217,51 @@ impl CtrlPlatform { /// Get the `panel_od` value from platform. Updates the stored value in /// internal config also. fn panel_od(&self) -> bool { - let od = self - .platform + self.platform .get_panel_od() .map_err(|err| { warn!("CtrlRogBios: get_panel_od {}", err); err }) - .unwrap_or(false); - if let Some(mut lock) = self.config.try_lock() { - lock.panel_od = od; - lock.write(); - } - od + .unwrap_or(false) } #[dbus_interface(signal)] async fn notify_panel_od(signal_ctxt: &SignalContext<'_>, overdrive: bool) -> zbus::Result<()> { } + async fn set_mini_led_mode( + &mut self, + #[zbus(signal_context)] ctxt: SignalContext<'_>, + on: bool, + ) { + match self.platform.set_mini_led_mode(on) { + Ok(_) => { + if let Some(mut lock) = self.config.try_lock() { + lock.mini_led_mode = on; + lock.write(); + } + Self::notify_mini_led_mode(&ctxt, on).await.ok(); + } + Err(err) => warn!("CtrlRogBios: set_mini_led_mode {}", err), + }; + } + + /// Get the `panel_od` value from platform. Updates the stored value in + /// internal config also. + fn mini_led_mode(&self) -> bool { + self.platform + .get_mini_led_mode() + .map_err(|err| { + warn!("CtrlRogBios: get_mini_led_mode {}", err); + err + }) + .unwrap_or(false) + } + + #[dbus_interface(signal)] + async fn notify_mini_led_mode(signal_ctxt: &SignalContext<'_>, on: bool) -> zbus::Result<()> {} + async fn set_dgpu_disable( &mut self, #[zbus(signal_context)] ctxt: SignalContext<'_>, diff --git a/rog-control-center/src/system_state.rs b/rog-control-center/src/system_state.rs index a2ccfd6d..2815390f 100644 --- a/rog-control-center/src/system_state.rs +++ b/rog-control-center/src/system_state.rs @@ -32,6 +32,7 @@ pub struct BiosState { pub post_sound: bool, pub dedicated_gfx: GpuMode, pub panel_overdrive: bool, + pub mini_led_mode: bool, pub dgpu_disable: bool, pub egpu_enable: bool, } @@ -54,6 +55,11 @@ impl BiosState { } else { false }, + mini_led_mode: if supported.rog_bios_ctrl.mini_led_mode { + dbus.proxies().rog_bios().mini_led_mode()? + } else { + false + }, // TODO: needs supergfx dgpu_disable: supported.rog_bios_ctrl.dgpu_disable, egpu_enable: supported.rog_bios_ctrl.egpu_enable, @@ -410,9 +416,7 @@ impl Default for SystemState { bios: BiosState { post_sound: Default::default(), dedicated_gfx: GpuMode::NotSupported, - panel_overdrive: Default::default(), - dgpu_disable: Default::default(), - egpu_enable: Default::default(), + ..Default::default() }, aura: AuraState { current_mode: AuraModeNum::Static, @@ -422,22 +426,14 @@ impl Default for SystemState { x1866: vec![], x19b6: vec![], }, - bright: Default::default(), - wave_red: Default::default(), - wave_green: Default::default(), - wave_blue: Default::default(), + ..Default::default() }, anime: AnimeState::default(), profiles: ProfilesState { - list: Default::default(), - current: Default::default(), + ..Default::default() }, fan_curves: FanCurvesState { - show_curve: Default::default(), - show_graph: Default::default(), - enabled: Default::default(), - curves: Default::default(), - drag_delta: Default::default(), + ..Default::default() }, gfx_state: GfxState { has_supergfx: false, diff --git a/rog-control-center/src/tray.rs b/rog-control-center/src/tray.rs index 0db24cc9..78ab1cb1 100644 --- a/rog-control-center/src/tray.rs +++ b/rog-control-center/src/tray.rs @@ -247,6 +247,21 @@ impl ROGTray { } } + fn menu_add_mini_led_mode(&mut self, supported: &SupportedFunctions, on: bool) { + if supported.rog_bios_ctrl.mini_led_mode { + let bios = self.bios_proxy.clone(); + self.add_check_menu_item("MiniLED mode", on, move |this| { + bios.set_mini_led_mode(this.is_active()) + .map_err(|e| { + error!("ROGTray: set_mini_led_mode: {e}"); + e + }) + .ok(); + }); + debug!("ROGTray: appended miniLED mode menu"); + } + } + fn menu_add_supergfx(&mut self, supported_gfx: &[GfxMode], current_mode: GfxMode) { if !self.gfx_proxy_is_active { trace!("menu_add_supergfx: gfx_proxy_is_active is false"); @@ -386,11 +401,13 @@ impl ROGTray { current_gfx_mode: GfxMode, charge_limit: u8, panel_od: bool, + mini_led: bool, ) { self.menu_clear(); self.menu_add_base(); self.menu_add_charge_limit(supported, charge_limit); self.menu_add_panel_od(supported, panel_od); + self.menu_add_mini_led_mode(supported, mini_led); if self.gfx_proxy_is_active { // Add a supergfxctl specific menu self.menu_add_supergfx(supported_gfx, current_gfx_mode); @@ -453,7 +470,14 @@ pub fn init_tray( Default::default() }; - tray.rebuild_and_update(&supported, &supported_gfx, GfxMode::Hybrid, 100, false); + tray.rebuild_and_update( + &supported, + &supported_gfx, + GfxMode::Hybrid, + 100, + false, + false, + ); tray.set_icon(TRAY_APP_ICON); info!("Started ROGTray"); @@ -475,6 +499,7 @@ pub fn init_tray( current_gpu_mode, lock.power_state.charge_limit, lock.bios.panel_overdrive, + lock.bios.mini_led_mode, ); lock.tray_should_update = false; debug!("ROGTray: rebuilt menus due to state change"); diff --git a/rog-control-center/src/update_and_notify.rs b/rog-control-center/src/update_and_notify.rs index d76afa01..3b4bf437 100644 --- a/rog-control-center/src/update_and_notify.rs +++ b/rog-control-center/src/update_and_notify.rs @@ -1,6 +1,8 @@ //! `update_and_notify` is responsible for both notifications *and* updating //! stored statuses about the system state. This is done through either direct, //! intoify, zbus notifications or similar methods. +//! +//! This module very much functions like a stand-alone app on its own thread. use std::fmt::Display; use std::process::Command; @@ -37,6 +39,7 @@ static mut POWER_BAT_CMD: Option = None; pub struct EnabledNotifications { pub receive_notify_post_boot_sound: bool, pub receive_notify_panel_od: bool, + pub receive_notify_mini_led_mode: bool, pub receive_notify_dgpu_disable: bool, pub receive_notify_egpu_enable: bool, pub receive_notify_gpu_mux_mode: bool, @@ -56,6 +59,7 @@ impl Default for EnabledNotifications { Self { receive_notify_post_boot_sound: false, receive_notify_panel_od: true, + receive_notify_mini_led_mode: true, receive_notify_dgpu_disable: true, receive_notify_egpu_enable: true, receive_notify_gpu_mux_mode: true, @@ -177,6 +181,18 @@ pub fn start_notifications( do_notification ); + recv_notif!( + RogBiosProxy, + receive_notify_mini_led_mode, + last_notification, + enabled_notifications, + page_states, + (bios.mini_led_mode), + (on), + "MiniLED mode enabled:", + do_notification + ); + recv_notif!( RogBiosProxy, receive_notify_dgpu_disable, diff --git a/rog-control-center/src/widgets/app_settings.rs b/rog-control-center/src/widgets/app_settings.rs index d822014d..36b0334b 100644 --- a/rog-control-center/src/widgets/app_settings.rs +++ b/rog-control-center/src/widgets/app_settings.rs @@ -76,6 +76,12 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui) "Enable panel overdrive notification", ) .clicked() + || ui + .checkbox( + &mut enabled_notifications.receive_notify_mini_led_mode, + "Enable MiniLED mode notification", + ) + .clicked() || ui .checkbox( &mut enabled_notifications.receive_notify_post_boot_sound, diff --git a/rog-control-center/src/widgets/rog_bios.rs b/rog-control-center/src/widgets/rog_bios.rs index 7a22039d..aa82821f 100644 --- a/rog-control-center/src/widgets/rog_bios.rs +++ b/rog-control-center/src/widgets/rog_bios.rs @@ -74,7 +74,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState, .ok(); } - if supported.rog_bios_ctrl.post_sound + if supported.rog_bios_ctrl.panel_overdrive && ui .add(egui::Checkbox::new( &mut states.bios.panel_overdrive, @@ -93,6 +93,25 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState, .ok(); } + if supported.rog_bios_ctrl.mini_led_mode + && ui + .add(egui::Checkbox::new( + &mut states.bios.mini_led_mode, + "MiniLED backlight", + )) + .changed() + { + states + .asus_dbus + .proxies() + .rog_bios() + .set_mini_led_mode(states.bios.mini_led_mode) + .map_err(|err| { + states.error = Some(err.to_string()); + }) + .ok(); + } + if supported.rog_bios_ctrl.gpu_mux { let mut changed = false; let mut dedicated_gfx = states.bios.dedicated_gfx; diff --git a/rog-dbus/src/zbus_platform.rs b/rog-dbus/src/zbus_platform.rs index 807eef48..9b485037 100644 --- a/rog-dbus/src/zbus_platform.rs +++ b/rog-dbus/src/zbus_platform.rs @@ -40,6 +40,9 @@ trait RogBios { /// PanelOd method fn panel_od(&self) -> zbus::Result; + /// MiniLedMode method + fn mini_led_mode(&self) -> zbus::Result; + /// PostBootSound method fn post_boot_sound(&self) -> zbus::Result; @@ -55,6 +58,9 @@ trait RogBios { /// SetPanelOd method fn set_panel_od(&self, overdrive: bool) -> zbus::Result<()>; + /// SetminiLedMode + fn set_mini_led_mode(&self, on: bool) -> zbus::Result<()>; + /// SetPostBootSound method fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>; @@ -74,6 +80,10 @@ trait RogBios { #[dbus_proxy(signal)] fn notify_panel_od(&self, overdrive: bool) -> zbus::Result<()>; + /// NotifyMiniLedMode signal + #[dbus_proxy(signal)] + fn notify_mini_led_mode(&self, on: bool) -> zbus::Result<()>; + /// NotifyPostBootSound signal #[inline] #[dbus_proxy(signal)] diff --git a/rog-platform/src/platform.rs b/rog-platform/src/platform.rs index 8c39488b..3ec27d31 100644 --- a/rog-platform/src/platform.rs +++ b/rog-platform/src/platform.rs @@ -29,6 +29,8 @@ impl AsusPlatform { attr_bool!("panel_od", path); + attr_bool!("mini_led_mode", path); + attr_bool!("gpu_mux_mode", path); // This is technically the same as `platform_profile` since both are tied diff --git a/rog-platform/src/supported.rs b/rog-platform/src/supported.rs index 084977bb..77f8a402 100644 --- a/rog-platform/src/supported.rs +++ b/rog-platform/src/supported.rs @@ -62,6 +62,7 @@ pub struct RogBiosSupportedFunctions { pub panel_overdrive: bool, pub dgpu_disable: bool, pub egpu_enable: bool, + pub mini_led_mode: bool, } impl fmt::Display for SupportedFunctions { @@ -112,6 +113,7 @@ impl fmt::Display for RogBiosSupportedFunctions { writeln!(f, "ROG BIOS:")?; writeln!(f, "\tPOST sound switch: {}", self.post_sound)?; writeln!(f, "\tPanel Overdrive: {}", self.panel_overdrive)?; + writeln!(f, "\tMiniLED backlight: {}", self.mini_led_mode)?; writeln!(f, "\tdGPU disable switch: {}", self.dgpu_disable)?; writeln!(f, "\teGPU enable switch: {}", self.egpu_enable)?; writeln!(f, "\tGPU MUX control: {}", self.gpu_mux)?;