Anime: add dbus methods

This commit is contained in:
Luke D. Jones
2023-11-15 17:16:05 +13:00
parent f5b3f0bc38
commit e470d3acc0
5 changed files with 89 additions and 16 deletions

View File

@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for G513RW LED modes - Support for G513RW LED modes
- Support Rog Ally LED modes (basic) - Support Rog Ally LED modes (basic)
- Add on_lid_closed and on_external_power_changed events for running certain tasks - Add on_lid_closed and on_external_power_changed events for running certain tasks
- Anime dbus: add:
- SetOffWhenUnplugged
- SetOffWhenSuspended
- SetOffWhenLidClosed
### Changed ### Changed
- asusd: remove set_image_brightness for anime - asusd: remove set_image_brightness for anime

View File

@@ -3,7 +3,9 @@ use std::time::Duration;
use config_traits::{StdConfig, StdConfigLoad2}; use config_traits::{StdConfig, StdConfigLoad2};
use rog_anime::error::AnimeError; use rog_anime::error::AnimeError;
use rog_anime::usb::Brightness; 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}; use serde_derive::{Deserialize, Serialize};
const CONFIG_FILE: &str = "anime.ron"; const CONFIG_FILE: &str = "anime.ron";

View File

@@ -33,7 +33,8 @@ impl crate::ZbusRun for CtrlAnimeZbus {
// grab it until we finish. // grab it until we finish.
#[dbus_interface(name = "org.asuslinux.Daemon")] #[dbus_interface(name = "org.asuslinux.Daemon")]
impl CtrlAnimeZbus { 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<()> { async fn write(&self, input: AnimeDataBuffer) -> zbus::fdo::Result<()> {
let lock = self.0.lock().await; let lock = self.0.lock().await;
lock.thread_exit.store(true, Ordering::SeqCst); lock.thread_exit.store(true, Ordering::SeqCst);
@@ -169,6 +170,48 @@ impl CtrlAnimeZbus {
.ok(); .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 main loop is the base system set action if the user isn't running
/// the user daemon /// the user daemon
async fn run_main_loop(&self, start: bool) { async fn run_main_loop(&self, start: bool) {

View File

@@ -2,18 +2,11 @@
<node> <node>
<interface name="org.asuslinux.Daemon"> <interface name="org.asuslinux.Daemon">
<!-- <!--
Writes a data stream of length. Will force system thread to exit until Writes a data stream of length. Will force system thread to exit until it is restarted
it is restarted
--> -->
<method name="Write"> <method name="Write">
<arg name="input" type="(ays)" direction="in"/> <arg name="input" type="(ays)" direction="in"/>
</method> </method>
<!--
Set the global AniMe brightness
-->
<method name="SetImageBrightness">
<arg name="bright" type="d" direction="in"/>
</method>
<!-- <!--
Set base brightness level Set base brightness level
--> -->
@@ -21,7 +14,8 @@
<arg name="brightness" type="s" direction="in"/> <arg name="brightness" type="s" direction="in"/>
</method> </method>
<!-- <!--
Enable the builtin animations or not Enable the builtin animations or not. This is quivalent to "Powersave
animations" in Armory crate
--> -->
<method name="SetBuiltinsEnabled"> <method name="SetBuiltinsEnabled">
<arg name="enabled" type="b" direction="in"/> <arg name="enabled" type="b" direction="in"/>
@@ -41,6 +35,24 @@
<method name="SetEnableDisplay"> <method name="SetEnableDisplay">
<arg name="enabled" type="b" direction="in"/> <arg name="enabled" type="b" direction="in"/>
</method> </method>
<!--
Set if to turn the AniMe Matrix off when external power is unplugged
-->
<method name="SetOffWhenUnplugged">
<arg name="enabled" type="b" direction="in"/>
</method>
<!--
Set if to turn the AniMe Matrix off when the laptop is suspended
-->
<method name="SetOffWhenSuspended">
<arg name="enabled" type="b" direction="in"/>
</method>
<!--
Set if to turn the AniMe Matrix off when the lid is closed
-->
<method name="SetOffWhenLidClosed">
<arg name="enabled" type="b" direction="in"/>
</method>
<!-- <!--
The main loop is the base system set action if the user isn't running The main loop is the base system set action if the user isn't running
the user daemon the user daemon
@@ -52,14 +64,14 @@
Get the device state as stored by asusd Get the device state as stored by asusd
--> -->
<method name="DeviceState"> <method name="DeviceState">
<arg type="bsb(ssss)" direction="out"/> <arg type="bsb(ssss)bbb" direction="out"/>
</method> </method>
<!-- <!--
Notify listeners of the status of AniMe LED power and factory Notify listeners of the status of AniMe LED power and factory
system-status animations system-status animations
--> -->
<signal name="NotifyDeviceState"> <signal name="NotifyDeviceState">
<arg name="data" type="(bsb(ssss))"/> <arg name="data" type="(bsb(ssss)bbb)"/>
</signal> </signal>
</interface> </interface>
</node> </node>

View File

@@ -4,6 +4,7 @@ use zbus::dbus_proxy;
#[dbus_proxy( #[dbus_proxy(
interface = "org.asuslinux.Daemon", interface = "org.asuslinux.Daemon",
default_service = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Anime" default_path = "/org/asuslinux/Anime"
)] )]
trait Anime { trait Anime {
@@ -25,6 +26,15 @@ trait Anime {
/// Set whether the AniMe is displaying images/data /// Set whether the AniMe is displaying images/data
fn set_enable_display(&self, status: bool) -> zbus::Result<()>; 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 /// Writes a data stream of length. Will force system thread to exit until
/// it is restarted /// it is restarted
fn write(&self, input: AnimeDataBuffer) -> zbus::Result<()>; fn write(&self, input: AnimeDataBuffer) -> zbus::Result<()>;
@@ -32,8 +42,10 @@ trait Anime {
// #[dbus_proxy(property)] // #[dbus_proxy(property)]
fn device_state(&self) -> zbus::Result<AnimeDeviceState>; fn device_state(&self) -> zbus::Result<AnimeDeviceState>;
/// Notify listeners of the status of AniMe LED power and factory /// NotifyDeviceState signal
/// system-status animations
#[dbus_proxy(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<()>;
} }