mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
Anime: Enabled setting builtin animations
This commit is contained in:
@@ -8,6 +8,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use zbus::zvariant::Type;
|
||||
|
||||
use crate::error::{AnimeError, Result};
|
||||
use crate::usb::{AnimAwake, AnimBooting, AnimShutdown, AnimSleeping, Brightness};
|
||||
use crate::{AnimTime, AnimeGif};
|
||||
|
||||
/// The first 7 bytes of a USB packet are accounted for by `USB_PREFIX1` and
|
||||
@@ -25,12 +26,22 @@ pub const USB_PREFIX2: [u8; 7] = [0x5e, 0xc0, 0x02, 0x74, 0x02, 0x73, 0x02];
|
||||
/// Third packet is for GA402 matrix
|
||||
pub const USB_PREFIX3: [u8; 7] = [0x5e, 0xc0, 0x02, 0xe7, 0x04, 0x73, 0x02];
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Default, Deserialize, PartialEq, Eq, Clone, Copy, Serialize, Debug)]
|
||||
pub struct Animations {
|
||||
pub boot: AnimBooting,
|
||||
pub awake: AnimAwake,
|
||||
pub sleep: AnimSleeping,
|
||||
pub shutdown: AnimShutdown,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
pub struct AnimePowerStates {
|
||||
pub brightness: u8,
|
||||
pub enabled: bool,
|
||||
pub boot_anim_enabled: bool,
|
||||
pub struct DeviceState {
|
||||
pub display_enabled: bool,
|
||||
pub display_brightness: Brightness,
|
||||
pub builtin_anims_enabled: bool,
|
||||
pub builtin_anims: Animations,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
|
||||
@@ -24,12 +24,14 @@ pub enum AnimeError {
|
||||
DataBufferLength,
|
||||
PixelGifWidth(usize),
|
||||
PixelGifHeight(usize),
|
||||
ParseError(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for AnimeError {
|
||||
#[inline]
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
AnimeError::ParseError(e) => write!(f, "Could not parse {e}"),
|
||||
AnimeError::NoFrames => write!(f, "No frames in PNG"),
|
||||
AnimeError::Io(e) => write!(f, "Could not open: {}", e),
|
||||
AnimeError::Png(e) => write!(f, "PNG error: {}", e),
|
||||
|
||||
@@ -23,11 +23,12 @@ pub const VENDOR_ID: u16 = 0x0b05;
|
||||
pub const PROD_ID: u16 = 0x193b;
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
/// Base LED brightness of the display
|
||||
pub enum Brightness {
|
||||
Off,
|
||||
Low,
|
||||
#[default]
|
||||
Med,
|
||||
High,
|
||||
}
|
||||
@@ -46,6 +47,97 @@ impl FromStr for Brightness {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u8> for Brightness {
|
||||
fn from(v: u8) -> Brightness {
|
||||
match v {
|
||||
0 => Brightness::Off,
|
||||
2 => Brightness::Low,
|
||||
3 => Brightness::High,
|
||||
_ => Brightness::Med,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
pub enum AnimBooting {
|
||||
#[default]
|
||||
GlitchConstruction,
|
||||
StaticEmergence,
|
||||
}
|
||||
|
||||
impl FromStr for AnimBooting {
|
||||
type Err = AnimeError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"GlitchConstruction" => Ok(Self::GlitchConstruction),
|
||||
"StaticEmergence" => Ok(Self::StaticEmergence),
|
||||
_ => Err(AnimeError::ParseError(s.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
pub enum AnimAwake {
|
||||
#[default]
|
||||
BinaryBannerScroll,
|
||||
RogLogoGlitch,
|
||||
}
|
||||
|
||||
impl FromStr for AnimAwake {
|
||||
type Err = AnimeError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"BinaryBannerScroll" => Ok(Self::BinaryBannerScroll),
|
||||
"RogLogoGlitch" => Ok(Self::RogLogoGlitch),
|
||||
_ => Err(AnimeError::ParseError(s.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
pub enum AnimSleeping {
|
||||
#[default]
|
||||
BannerSwipe,
|
||||
Starfield,
|
||||
}
|
||||
|
||||
impl FromStr for AnimSleeping {
|
||||
type Err = AnimeError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"BannerSwipe" => Ok(Self::BannerSwipe),
|
||||
"Starfield" => Ok(Self::Starfield),
|
||||
_ => Err(AnimeError::ParseError(s.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, Default, PartialEq, Eq, Copy, Clone, Deserialize, Serialize)]
|
||||
pub enum AnimShutdown {
|
||||
#[default]
|
||||
GlitchOut,
|
||||
SeeYa,
|
||||
}
|
||||
|
||||
impl FromStr for AnimShutdown {
|
||||
type Err = AnimeError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"GlitchOut" => Ok(Self::GlitchOut),
|
||||
"SeeYa" => Ok(Self::SeeYa),
|
||||
_ => Err(AnimeError::ParseError(s.to_owned())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `get_anime_type` is very broad, matching on part of the laptop board name
|
||||
/// only. For this reason `find_node()` must be used also to verify if the USB
|
||||
/// device is available.
|
||||
@@ -89,7 +181,7 @@ pub const fn pkts_for_init() -> [[u8; PACKET_SIZE]; 2] {
|
||||
/// Should be written to the device after writing the two main data packets that
|
||||
/// make up the display data packet
|
||||
#[inline]
|
||||
pub const fn pkt_for_flush() -> [u8; PACKET_SIZE] {
|
||||
pub const fn pkt_flush() -> [u8; PACKET_SIZE] {
|
||||
let mut pkt = [0; PACKET_SIZE];
|
||||
pkt[0] = DEV_PAGE;
|
||||
pkt[1] = 0xc0;
|
||||
@@ -97,23 +189,10 @@ pub const fn pkt_for_flush() -> [u8; PACKET_SIZE] {
|
||||
pkt
|
||||
}
|
||||
|
||||
/// Get the packet required for setting the device to on, on boot. Requires
|
||||
/// Packet for setting the brightness (0-3). Requires
|
||||
/// `pkt_for_apply()` to be written after.
|
||||
#[inline]
|
||||
pub const fn pkt_for_set_boot(status: bool) -> [u8; PACKET_SIZE] {
|
||||
let mut pkt = [0; PACKET_SIZE];
|
||||
pkt[0] = DEV_PAGE;
|
||||
pkt[1] = 0xc3;
|
||||
pkt[2] = 0x01;
|
||||
pkt[3] = if status { 0x00 } else { 0x80 };
|
||||
pkt
|
||||
}
|
||||
|
||||
/// Get the packet required for setting the device to on. Requires
|
||||
/// `pkt_for_apply()` to be written after.
|
||||
// TODO: change the users of this method
|
||||
#[inline]
|
||||
pub const fn pkt_for_set_brightness(brightness: Brightness) -> [u8; PACKET_SIZE] {
|
||||
pub const fn pkt_set_brightness(brightness: Brightness) -> [u8; PACKET_SIZE] {
|
||||
let mut pkt = [0; PACKET_SIZE];
|
||||
pkt[0] = DEV_PAGE;
|
||||
pkt[1] = 0xc0;
|
||||
@@ -122,23 +201,42 @@ pub const fn pkt_for_set_brightness(brightness: Brightness) -> [u8; PACKET_SIZE]
|
||||
pkt
|
||||
}
|
||||
|
||||
/// Enable the display?
|
||||
#[inline]
|
||||
pub const fn pkt_for_set_awake_enabled(enable: bool) -> [u8; PACKET_SIZE] {
|
||||
pub const fn pkt_set_enable_display(status: bool) -> [u8; PACKET_SIZE] {
|
||||
let mut pkt = [0; PACKET_SIZE];
|
||||
pkt[0] = DEV_PAGE;
|
||||
pkt[1] = 0xc3;
|
||||
pkt[2] = 0x01;
|
||||
pkt[3] = if !enable { 0x80 } else { 0x00 };
|
||||
pkt[3] = if status { 0x00 } else { 0x80 };
|
||||
pkt
|
||||
}
|
||||
|
||||
/// Packet required to apply a device setting
|
||||
/// Enable builtin animations?
|
||||
#[inline]
|
||||
pub const fn pkt_for_enable_animation() -> [u8; PACKET_SIZE] {
|
||||
pub const fn pkt_set_enable_powersave_anim(status: bool) -> [u8; PACKET_SIZE] {
|
||||
let mut pkt = [0; PACKET_SIZE];
|
||||
pkt[0] = DEV_PAGE;
|
||||
pkt[1] = 0xc4;
|
||||
pkt[2] = 0x01;
|
||||
pkt[3] = 0x80;
|
||||
pkt[3] = if status { 0x00 } else { 0x80 };
|
||||
pkt
|
||||
}
|
||||
|
||||
/// Set which animations are shown for each stage
|
||||
#[inline]
|
||||
pub const fn pkt_set_builtin_animations(
|
||||
boot: AnimBooting,
|
||||
awake: AnimAwake,
|
||||
sleep: AnimSleeping,
|
||||
shutdown: AnimShutdown,
|
||||
) -> [u8; PACKET_SIZE] {
|
||||
let mut pkt = [0; PACKET_SIZE];
|
||||
pkt[0] = DEV_PAGE;
|
||||
pkt[1] = 0xc5;
|
||||
pkt[2] = (awake as u8)
|
||||
| ((sleep as u8) << 0x01)
|
||||
| ((shutdown as u8) << 0x02)
|
||||
| ((boot as u8) << 0x03);
|
||||
pkt
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user