From e470d3acc0e3c898d263ce30bb3b6ed383c3fb35 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Wed, 15 Nov 2023 17:16:05 +1300 Subject: [PATCH] Anime: add dbus methods --- CHANGELOG.md | 4 ++ asusd/src/ctrl_anime/config.rs | 4 +- asusd/src/ctrl_anime/trait_impls.rs | 45 ++++++++++++++++++++- bindings/dbus-xml/org-asuslinux-anime-4.xml | 34 +++++++++++----- rog-dbus/src/zbus_anime.rs | 18 +++++++-- 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7712583..d6af5f8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support for G513RW LED modes - Support Rog Ally LED modes (basic) - Add on_lid_closed and on_external_power_changed events for running certain tasks +- Anime dbus: add: + - SetOffWhenUnplugged + - SetOffWhenSuspended + - SetOffWhenLidClosed ### Changed - asusd: remove set_image_brightness for anime diff --git a/asusd/src/ctrl_anime/config.rs b/asusd/src/ctrl_anime/config.rs index 55448343..61342127 100644 --- a/asusd/src/ctrl_anime/config.rs +++ b/asusd/src/ctrl_anime/config.rs @@ -3,7 +3,9 @@ use std::time::Duration; use config_traits::{StdConfig, StdConfigLoad2}; use rog_anime::error::AnimeError; use rog_anime::usb::Brightness; -use rog_anime::{ActionData, ActionLoader, AnimTime, Animations, AnimeType, Fade, Vec2, DeviceState}; +use rog_anime::{ + ActionData, ActionLoader, AnimTime, Animations, AnimeType, DeviceState, Fade, Vec2, +}; use serde_derive::{Deserialize, Serialize}; const CONFIG_FILE: &str = "anime.ron"; diff --git a/asusd/src/ctrl_anime/trait_impls.rs b/asusd/src/ctrl_anime/trait_impls.rs index afe71e1e..30b7f7f4 100644 --- a/asusd/src/ctrl_anime/trait_impls.rs +++ b/asusd/src/ctrl_anime/trait_impls.rs @@ -33,7 +33,8 @@ impl crate::ZbusRun for CtrlAnimeZbus { // grab it until we finish. #[dbus_interface(name = "org.asuslinux.Daemon")] impl CtrlAnimeZbus { - /// Writes a data stream of length. Will force system thread to exit until it is restarted + /// Writes a data stream of length. Will force system thread to exit until + /// it is restarted async fn write(&self, input: AnimeDataBuffer) -> zbus::fdo::Result<()> { let lock = self.0.lock().await; lock.thread_exit.store(true, Ordering::SeqCst); @@ -169,6 +170,48 @@ impl CtrlAnimeZbus { .ok(); } + /// Set if to turn the AniMe Matrix off when external power is unplugged + async fn set_off_when_unplugged( + &self, + #[zbus(signal_context)] ctxt: SignalContext<'_>, + enabled: bool, + ) { + let mut lock = self.0.lock().await; + lock.config.off_when_unplugged = enabled; + lock.config.write(); + Self::notify_device_state(&ctxt, DeviceState::from(&lock.config)) + .await + .ok(); + } + + /// Set if to turn the AniMe Matrix off when the laptop is suspended + async fn set_off_when_suspended( + &self, + #[zbus(signal_context)] ctxt: SignalContext<'_>, + enabled: bool, + ) { + let mut lock = self.0.lock().await; + lock.config.off_when_suspended = enabled; + lock.config.write(); + Self::notify_device_state(&ctxt, DeviceState::from(&lock.config)) + .await + .ok(); + } + + /// Set if to turn the AniMe Matrix off when the lid is closed + async fn set_off_when_lid_closed( + &self, + #[zbus(signal_context)] ctxt: SignalContext<'_>, + enabled: bool, + ) { + let mut lock = self.0.lock().await; + lock.config.off_when_lid_closed = enabled; + lock.config.write(); + Self::notify_device_state(&ctxt, DeviceState::from(&lock.config)) + .await + .ok(); + } + /// The main loop is the base system set action if the user isn't running /// the user daemon async fn run_main_loop(&self, start: bool) { diff --git a/bindings/dbus-xml/org-asuslinux-anime-4.xml b/bindings/dbus-xml/org-asuslinux-anime-4.xml index 044330a5..150d1e61 100644 --- a/bindings/dbus-xml/org-asuslinux-anime-4.xml +++ b/bindings/dbus-xml/org-asuslinux-anime-4.xml @@ -2,18 +2,11 @@ - - - - @@ -21,7 +14,8 @@ @@ -41,6 +35,24 @@ + + + + + + + + + + + + - + - + diff --git a/rog-dbus/src/zbus_anime.rs b/rog-dbus/src/zbus_anime.rs index 8c2de8e5..6f394b0c 100644 --- a/rog-dbus/src/zbus_anime.rs +++ b/rog-dbus/src/zbus_anime.rs @@ -4,6 +4,7 @@ use zbus::dbus_proxy; #[dbus_proxy( interface = "org.asuslinux.Daemon", + default_service = "org.asuslinux.Daemon", default_path = "/org/asuslinux/Anime" )] trait Anime { @@ -25,6 +26,15 @@ trait Anime { /// Set whether the AniMe is displaying images/data fn set_enable_display(&self, status: bool) -> zbus::Result<()>; + /// SetOffWhenLidClosed method + fn set_off_when_lid_closed(&self, enabled: bool) -> zbus::Result<()>; + + /// SetOffWhenSuspended method + fn set_off_when_suspended(&self, enabled: bool) -> zbus::Result<()>; + + /// SetOffWhenUnplugged method + fn set_off_when_unplugged(&self, enabled: bool) -> zbus::Result<()>; + /// Writes a data stream of length. Will force system thread to exit until /// it is restarted fn write(&self, input: AnimeDataBuffer) -> zbus::Result<()>; @@ -32,8 +42,10 @@ trait Anime { // #[dbus_proxy(property)] fn device_state(&self) -> zbus::Result; - /// Notify listeners of the status of AniMe LED power and factory - /// system-status animations + /// NotifyDeviceState signal #[dbus_proxy(signal)] - fn device_state(&self, data: AnimeDeviceState) -> zbus::Result<()>; + fn notify_device_state( + &self, + data: (bool, &str, bool, (&str, &str, &str, &str)), + ) -> zbus::Result<()>; }