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