mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Better anime options & gumdrop error Display
This commit is contained in:
@@ -6,8 +6,8 @@ const DEV_PAGE: u8 = 0x5e;
|
||||
// These bytes are in [1] position of the array
|
||||
const WRITE: u8 = 0xc0;
|
||||
const INIT: u8 = 0xc2;
|
||||
const APPLY: u8 = 0xc3;
|
||||
const SET: u8 = 0xc4;
|
||||
const SET: u8 = 0xc3;
|
||||
const APPLY: u8 = 0xc4;
|
||||
|
||||
// Used to turn the panel on and off
|
||||
// The next byte can be 0x03 for "on" and 0x00 for "off"
|
||||
@@ -25,7 +25,7 @@ use zbus::dbus_interface;
|
||||
#[derive(Debug)]
|
||||
pub enum AnimatrixCommand {
|
||||
Apply,
|
||||
Set,
|
||||
SetBoot(bool),
|
||||
Write(Vec<u8>),
|
||||
WriteImage(Vec<Vec<u8>>),
|
||||
//ReloadLast,
|
||||
@@ -41,6 +41,8 @@ pub trait Dbus {
|
||||
fn set_anime(&mut self, input: Vec<Vec<u8>>);
|
||||
|
||||
fn set_on_off(&mut self, status: bool);
|
||||
|
||||
fn set_boot_on_off(&mut self, status: bool);
|
||||
}
|
||||
|
||||
impl crate::ZbusAdd for CtrlAnimeDisplay {
|
||||
@@ -58,28 +60,40 @@ impl crate::ZbusAdd for CtrlAnimeDisplay {
|
||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||
impl Dbus for CtrlAnimeDisplay {
|
||||
fn set_anime(&mut self, input: Vec<Vec<u8>>) {
|
||||
|
||||
self.do_command(AnimatrixCommand::WriteImage(input))
|
||||
.unwrap_or_else(|err| warn!("{}", err));
|
||||
.map_or_else(|err| warn!("{}", err),
|
||||
|()| info!("Writing image to Anime"));
|
||||
}
|
||||
|
||||
fn set_on_off(&mut self, status: bool) {
|
||||
let mut activity : Vec<u8> = vec![0; PACKET_SIZE];
|
||||
activity[0] = DEV_PAGE;
|
||||
activity[1] = WRITE;
|
||||
activity[2] = ON_OFF;
|
||||
let mut flush : Vec<u8> = vec![0; PACKET_SIZE];
|
||||
flush[0] = DEV_PAGE;
|
||||
flush[1] = WRITE;
|
||||
flush[2] = ON_OFF;
|
||||
|
||||
let status_str;
|
||||
if status {
|
||||
activity[3] = 0x03;
|
||||
flush[3] = 0x03;
|
||||
status_str = "on";
|
||||
} else {
|
||||
activity[3] = 0x00;
|
||||
flush[3] = 0x00;
|
||||
status_str = "off";
|
||||
}
|
||||
info!("Turning {} the AniMe", status_str);
|
||||
|
||||
self.do_command(AnimatrixCommand::Write(activity))
|
||||
.unwrap_or_else(|err| warn!("{}", err));
|
||||
self.do_command(AnimatrixCommand::Write(flush))
|
||||
.map_or_else(|err| warn!("{}", err),
|
||||
|()| info!("Turning {} the AniMe", status_str));
|
||||
}
|
||||
|
||||
fn set_boot_on_off(&mut self, status: bool) {
|
||||
let status_str = if status { "on" } else { "off" };
|
||||
|
||||
self.do_command(AnimatrixCommand::SetBoot(status))
|
||||
.and_then(|()| self.do_command(AnimatrixCommand::Apply))
|
||||
.map_or_else(|err| warn!("{}", err),
|
||||
|()| info!("Turning {} the AniMe at boot/shutdown",
|
||||
status_str));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +141,8 @@ impl CtrlAnimeDisplay {
|
||||
|
||||
match command {
|
||||
AnimatrixCommand::Apply => self.do_apply()?,
|
||||
AnimatrixCommand::Set => self.do_set()?,
|
||||
//AnimatrixCommand::Set => self.do_set_boot()?,
|
||||
AnimatrixCommand::SetBoot(status) => self.do_set_boot(status)?,
|
||||
AnimatrixCommand::Write(bytes) => self.write_bytes(&bytes)?,
|
||||
AnimatrixCommand::WriteImage(effect) => self.write_image(effect)?,
|
||||
//AnimatrixCommand::ReloadLast => self.reload_last_builtin(&config).await?,
|
||||
@@ -212,12 +227,12 @@ impl CtrlAnimeDisplay {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn do_set(&mut self) -> Result<(), AuraError> {
|
||||
fn do_set_boot(&mut self, status: bool) -> Result<(), AuraError> {
|
||||
let mut flush = [0; PACKET_SIZE];
|
||||
flush[0] = DEV_PAGE;
|
||||
flush[1] = SET;
|
||||
flush[2] = 0x01;
|
||||
flush[3] = 0x80;
|
||||
flush[3] = if status { 0x00 } else { 0x80 };
|
||||
|
||||
self.write_bytes(&flush)?;
|
||||
Ok(())
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
use asus_nb::{
|
||||
anime_dbus::AniMeDbusWriter,
|
||||
cli_options::{AniMeActions, LedBrightness, SetAuraBuiltin},
|
||||
cli_options::{
|
||||
AniMeActions,
|
||||
AniMeStatusValue,
|
||||
LedBrightness,
|
||||
SetAuraBuiltin,
|
||||
},
|
||||
core_dbus::AuraDbusClient,
|
||||
profile::{ProfileCommand, ProfileEvent},
|
||||
};
|
||||
@@ -70,10 +75,10 @@ struct GraphicsCommand {
|
||||
struct AniMeCommand {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
#[options(help = "turn on the panel (and accept write requests)", no_short)]
|
||||
on: bool,
|
||||
#[options(help = "turn off the panel (and reject write requests)", no_short)]
|
||||
off: bool,
|
||||
#[options(help = "turn on/off the panel (accept/reject write requests)")]
|
||||
turn: Option<AniMeStatusValue>,
|
||||
#[options(help = "turn on/off the panel at boot (with Asus effect)")]
|
||||
boot: Option<AniMeStatusValue>,
|
||||
#[options(command)]
|
||||
command: Option<AniMeActions>,
|
||||
}
|
||||
@@ -102,7 +107,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
};
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("source {:?}", err);
|
||||
eprintln!("source {}", err);
|
||||
std::process::exit(2);
|
||||
}
|
||||
}
|
||||
@@ -142,11 +147,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
Some(CliCommand::Graphics(command)) => do_gfx(command, &writer)?,
|
||||
Some(CliCommand::AniMe(anime)) => {
|
||||
if anime.on {
|
||||
anime_writer.turn_on()?;
|
||||
} else if anime.off {
|
||||
anime_writer.turn_off()?;
|
||||
} else if let Some(action) = anime.command {
|
||||
if let Some(anime_turn) = anime.turn {
|
||||
anime_writer.turn_on_off(anime_turn.into())?
|
||||
}
|
||||
if let Some(anime_boot) = anime.boot {
|
||||
anime_writer.turn_boot_on_off(anime_boot.into())?
|
||||
}
|
||||
if let Some(action) = anime.command {
|
||||
match action {
|
||||
AniMeActions::Leds(anime_leds) => {
|
||||
let led_brightness = anime_leds.led_brightness();
|
||||
|
||||
Reference in New Issue
Block a user