mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
Anime: small cleanup
This commit is contained in:
@@ -3,7 +3,7 @@ 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};
|
||||
use rog_anime::{ActionData, ActionLoader, AnimTime, Animations, AnimeType, Fade, Vec2, DeviceState};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
const CONFIG_FILE: &str = "anime.ron";
|
||||
@@ -168,6 +168,20 @@ impl StdConfig for AnimeConfig {
|
||||
|
||||
impl StdConfigLoad2<AnimeConfigV460, AnimeConfigV472> for AnimeConfig {}
|
||||
|
||||
impl From<&AnimeConfig> for DeviceState {
|
||||
fn from(config: &AnimeConfig) -> Self {
|
||||
DeviceState {
|
||||
display_enabled: config.display_enabled,
|
||||
display_brightness: config.display_brightness,
|
||||
builtin_anims_enabled: config.builtin_anims_enabled,
|
||||
builtin_anims: config.builtin_anims,
|
||||
off_when_unplugged: config.off_when_unplugged,
|
||||
off_when_suspended: config.off_when_suspended,
|
||||
off_when_lid_closed: config.off_when_lid_closed,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AnimeConfig {
|
||||
// fn clamp_config_brightness(mut config: &mut AnimeConfig) {
|
||||
// if config.brightness < 0.0 || config.brightness > 1.0 {
|
||||
|
||||
@@ -33,8 +33,7 @@ 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);
|
||||
@@ -46,7 +45,6 @@ impl CtrlAnimeZbus {
|
||||
}
|
||||
|
||||
/// Set base brightness level
|
||||
// TODO: enum for brightness
|
||||
async fn set_brightness(
|
||||
&self,
|
||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||
@@ -70,20 +68,9 @@ impl CtrlAnimeZbus {
|
||||
lock.config.display_brightness = brightness;
|
||||
lock.config.write();
|
||||
|
||||
Self::notify_device_state(
|
||||
&ctxt,
|
||||
DeviceState {
|
||||
display_enabled: lock.config.display_enabled,
|
||||
display_brightness: lock.config.display_brightness,
|
||||
builtin_anims_enabled: lock.config.builtin_anims_enabled,
|
||||
builtin_anims: lock.config.builtin_anims,
|
||||
off_when_unplugged: lock.config.off_when_unplugged,
|
||||
off_when_suspended: lock.config.off_when_suspended,
|
||||
off_when_lid_closed: lock.config.off_when_lid_closed,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
Self::notify_device_state(&ctxt, DeviceState::from(&lock.config))
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
|
||||
/// Enable the builtin animations or not. This is quivalent to "Powersave
|
||||
@@ -122,20 +109,9 @@ impl CtrlAnimeZbus {
|
||||
lock.thread_exit.store(true, Ordering::Release);
|
||||
}
|
||||
|
||||
Self::notify_device_state(
|
||||
&ctxt,
|
||||
DeviceState {
|
||||
display_enabled: lock.config.display_enabled,
|
||||
display_brightness: lock.config.display_brightness,
|
||||
builtin_anims_enabled: lock.config.builtin_anims_enabled,
|
||||
builtin_anims: lock.config.builtin_anims,
|
||||
off_when_unplugged: lock.config.off_when_unplugged,
|
||||
off_when_suspended: lock.config.off_when_suspended,
|
||||
off_when_lid_closed: lock.config.off_when_lid_closed,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
Self::notify_device_state(&ctxt, DeviceState::from(&lock.config))
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
|
||||
/// Set which builtin animation is used for each stage
|
||||
@@ -167,20 +143,9 @@ impl CtrlAnimeZbus {
|
||||
lock.config.builtin_anims.shutdown = shutdown;
|
||||
lock.config.write();
|
||||
|
||||
Self::notify_device_state(
|
||||
&ctxt,
|
||||
DeviceState {
|
||||
display_enabled: lock.config.display_enabled,
|
||||
display_brightness: lock.config.display_brightness,
|
||||
builtin_anims_enabled: lock.config.builtin_anims_enabled,
|
||||
builtin_anims: lock.config.builtin_anims,
|
||||
off_when_unplugged: lock.config.off_when_unplugged,
|
||||
off_when_suspended: lock.config.off_when_suspended,
|
||||
off_when_lid_closed: lock.config.off_when_lid_closed,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
Self::notify_device_state(&ctxt, DeviceState::from(&lock.config))
|
||||
.await
|
||||
.ok();
|
||||
}
|
||||
|
||||
/// Set whether the AniMe is enabled at all
|
||||
@@ -199,20 +164,9 @@ impl CtrlAnimeZbus {
|
||||
lock.config.display_enabled = enabled;
|
||||
lock.config.write();
|
||||
|
||||
Self::notify_device_state(
|
||||
&ctxt,
|
||||
DeviceState {
|
||||
display_enabled: lock.config.display_enabled,
|
||||
display_brightness: lock.config.display_brightness,
|
||||
builtin_anims_enabled: lock.config.builtin_anims_enabled,
|
||||
builtin_anims: lock.config.builtin_anims,
|
||||
off_when_unplugged: lock.config.off_when_unplugged,
|
||||
off_when_suspended: lock.config.off_when_suspended,
|
||||
off_when_lid_closed: lock.config.off_when_lid_closed,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.ok();
|
||||
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
|
||||
|
||||
@@ -12,6 +12,9 @@ export class AnimeDbus extends DbusBase {
|
||||
sleep: AnimSleeping.BannerSwipe,
|
||||
shutdown: AnimShutdown.GlitchOut
|
||||
},
|
||||
off_when_unplugged: false,
|
||||
off_when_suspended: false,
|
||||
off_when_lid_closed: false,
|
||||
};
|
||||
|
||||
// TODO: interface or something to enforce requirement of "sync()" method
|
||||
@@ -77,7 +80,10 @@ export class AnimeDbus extends DbusBase {
|
||||
this.deviceState.builtin_anims.boot = AnimBooting[data[3][0] as AnimBooting];
|
||||
this.deviceState.builtin_anims.awake = AnimAwake[data[3][1] as AnimAwake];
|
||||
this.deviceState.builtin_anims.sleep = AnimSleeping[data[3][2] as AnimSleeping];
|
||||
this.deviceState.builtin_anims.shutdown = AnimShutdown[data[3][2] as AnimShutdown];
|
||||
this.deviceState.builtin_anims.shutdown = AnimShutdown[data[3][3] as AnimShutdown];
|
||||
this.deviceState.off_when_unplugged = data[4];
|
||||
this.deviceState.off_when_suspended = data[5];
|
||||
this.deviceState.off_when_lid_closed = data[6];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +92,20 @@ export class AnimeDbus extends DbusBase {
|
||||
try {
|
||||
// janky shit going on with DeviceStateSync
|
||||
this._parseData(this.dbus_proxy.DeviceStateSync());
|
||||
//@ts-ignore
|
||||
log("Anime Matrix: display_enabled: " + this.deviceState.display_enabled);
|
||||
//@ts-ignore
|
||||
log("Anime Matrix: display_brightness: " + this.deviceState.display_brightness);
|
||||
//@ts-ignore
|
||||
log("Anime Matrix: builtin_anims_enabled: " + this.deviceState.builtin_anims_enabled);
|
||||
//@ts-ignore
|
||||
log("Anime Matrix: builtin_anims: " + this.deviceState.builtin_anims);
|
||||
//@ts-ignore
|
||||
log("Anime Matrix: off_when_unplugged: " + this.deviceState.off_when_unplugged);
|
||||
//@ts-ignore
|
||||
log("Anime Matrix: off_when_suspended: " + this.deviceState.off_when_suspended);
|
||||
//@ts-ignore
|
||||
log("Anime Matrix: off_when_lid_closed: " + this.deviceState.off_when_lid_closed);
|
||||
} catch (e) {
|
||||
//@ts-ignore
|
||||
log("Failed to fetch DeviceState!", e);
|
||||
|
||||
Reference in New Issue
Block a user