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
|
// These bytes are in [1] position of the array
|
||||||
const WRITE: u8 = 0xc0;
|
const WRITE: u8 = 0xc0;
|
||||||
const INIT: u8 = 0xc2;
|
const INIT: u8 = 0xc2;
|
||||||
const APPLY: u8 = 0xc3;
|
const SET: u8 = 0xc3;
|
||||||
const SET: u8 = 0xc4;
|
const APPLY: u8 = 0xc4;
|
||||||
|
|
||||||
// Used to turn the panel on and off
|
// Used to turn the panel on and off
|
||||||
// The next byte can be 0x03 for "on" and 0x00 for "off"
|
// The next byte can be 0x03 for "on" and 0x00 for "off"
|
||||||
@@ -25,7 +25,7 @@ use zbus::dbus_interface;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AnimatrixCommand {
|
pub enum AnimatrixCommand {
|
||||||
Apply,
|
Apply,
|
||||||
Set,
|
SetBoot(bool),
|
||||||
Write(Vec<u8>),
|
Write(Vec<u8>),
|
||||||
WriteImage(Vec<Vec<u8>>),
|
WriteImage(Vec<Vec<u8>>),
|
||||||
//ReloadLast,
|
//ReloadLast,
|
||||||
@@ -41,6 +41,8 @@ pub trait Dbus {
|
|||||||
fn set_anime(&mut self, input: Vec<Vec<u8>>);
|
fn set_anime(&mut self, input: Vec<Vec<u8>>);
|
||||||
|
|
||||||
fn set_on_off(&mut self, status: bool);
|
fn set_on_off(&mut self, status: bool);
|
||||||
|
|
||||||
|
fn set_boot_on_off(&mut self, status: bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::ZbusAdd for CtrlAnimeDisplay {
|
impl crate::ZbusAdd for CtrlAnimeDisplay {
|
||||||
@@ -58,28 +60,40 @@ impl crate::ZbusAdd for CtrlAnimeDisplay {
|
|||||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||||
impl Dbus for CtrlAnimeDisplay {
|
impl Dbus for CtrlAnimeDisplay {
|
||||||
fn set_anime(&mut self, input: Vec<Vec<u8>>) {
|
fn set_anime(&mut self, input: Vec<Vec<u8>>) {
|
||||||
|
|
||||||
self.do_command(AnimatrixCommand::WriteImage(input))
|
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) {
|
fn set_on_off(&mut self, status: bool) {
|
||||||
let mut activity : Vec<u8> = vec![0; PACKET_SIZE];
|
let mut flush : Vec<u8> = vec![0; PACKET_SIZE];
|
||||||
activity[0] = DEV_PAGE;
|
flush[0] = DEV_PAGE;
|
||||||
activity[1] = WRITE;
|
flush[1] = WRITE;
|
||||||
activity[2] = ON_OFF;
|
flush[2] = ON_OFF;
|
||||||
|
|
||||||
let status_str;
|
let status_str;
|
||||||
if status {
|
if status {
|
||||||
activity[3] = 0x03;
|
flush[3] = 0x03;
|
||||||
status_str = "on";
|
status_str = "on";
|
||||||
} else {
|
} else {
|
||||||
activity[3] = 0x00;
|
flush[3] = 0x00;
|
||||||
status_str = "off";
|
status_str = "off";
|
||||||
}
|
}
|
||||||
info!("Turning {} the AniMe", status_str);
|
|
||||||
|
|
||||||
self.do_command(AnimatrixCommand::Write(activity))
|
self.do_command(AnimatrixCommand::Write(flush))
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.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 {
|
match command {
|
||||||
AnimatrixCommand::Apply => self.do_apply()?,
|
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::Write(bytes) => self.write_bytes(&bytes)?,
|
||||||
AnimatrixCommand::WriteImage(effect) => self.write_image(effect)?,
|
AnimatrixCommand::WriteImage(effect) => self.write_image(effect)?,
|
||||||
//AnimatrixCommand::ReloadLast => self.reload_last_builtin(&config).await?,
|
//AnimatrixCommand::ReloadLast => self.reload_last_builtin(&config).await?,
|
||||||
@@ -212,12 +227,12 @@ impl CtrlAnimeDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn do_set(&mut self) -> Result<(), AuraError> {
|
fn do_set_boot(&mut self, status: bool) -> Result<(), AuraError> {
|
||||||
let mut flush = [0; PACKET_SIZE];
|
let mut flush = [0; PACKET_SIZE];
|
||||||
flush[0] = DEV_PAGE;
|
flush[0] = DEV_PAGE;
|
||||||
flush[1] = SET;
|
flush[1] = SET;
|
||||||
flush[2] = 0x01;
|
flush[2] = 0x01;
|
||||||
flush[3] = 0x80;
|
flush[3] = if status { 0x00 } else { 0x80 };
|
||||||
|
|
||||||
self.write_bytes(&flush)?;
|
self.write_bytes(&flush)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
use asus_nb::{
|
use asus_nb::{
|
||||||
anime_dbus::AniMeDbusWriter,
|
anime_dbus::AniMeDbusWriter,
|
||||||
cli_options::{AniMeActions, LedBrightness, SetAuraBuiltin},
|
cli_options::{
|
||||||
|
AniMeActions,
|
||||||
|
AniMeStatusValue,
|
||||||
|
LedBrightness,
|
||||||
|
SetAuraBuiltin,
|
||||||
|
},
|
||||||
core_dbus::AuraDbusClient,
|
core_dbus::AuraDbusClient,
|
||||||
profile::{ProfileCommand, ProfileEvent},
|
profile::{ProfileCommand, ProfileEvent},
|
||||||
};
|
};
|
||||||
@@ -70,10 +75,10 @@ struct GraphicsCommand {
|
|||||||
struct AniMeCommand {
|
struct AniMeCommand {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
help: bool,
|
help: bool,
|
||||||
#[options(help = "turn on the panel (and accept write requests)", no_short)]
|
#[options(help = "turn on/off the panel (accept/reject write requests)")]
|
||||||
on: bool,
|
turn: Option<AniMeStatusValue>,
|
||||||
#[options(help = "turn off the panel (and reject write requests)", no_short)]
|
#[options(help = "turn on/off the panel at boot (with Asus effect)")]
|
||||||
off: bool,
|
boot: Option<AniMeStatusValue>,
|
||||||
#[options(command)]
|
#[options(command)]
|
||||||
command: Option<AniMeActions>,
|
command: Option<AniMeActions>,
|
||||||
}
|
}
|
||||||
@@ -102,7 +107,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("source {:?}", err);
|
eprintln!("source {}", err);
|
||||||
std::process::exit(2);
|
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::Graphics(command)) => do_gfx(command, &writer)?,
|
||||||
Some(CliCommand::AniMe(anime)) => {
|
Some(CliCommand::AniMe(anime)) => {
|
||||||
if anime.on {
|
if let Some(anime_turn) = anime.turn {
|
||||||
anime_writer.turn_on()?;
|
anime_writer.turn_on_off(anime_turn.into())?
|
||||||
} else if anime.off {
|
}
|
||||||
anime_writer.turn_off()?;
|
if let Some(anime_boot) = anime.boot {
|
||||||
} else if let Some(action) = anime.command {
|
anime_writer.turn_boot_on_off(anime_boot.into())?
|
||||||
|
}
|
||||||
|
if let Some(action) = anime.command {
|
||||||
match action {
|
match action {
|
||||||
AniMeActions::Leds(anime_leds) => {
|
AniMeActions::Leds(anime_leds) => {
|
||||||
let led_brightness = anime_leds.led_brightness();
|
let led_brightness = anime_leds.led_brightness();
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ impl AniMeDbusWriter {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn thread_sleep(&self) {
|
||||||
|
thread::sleep(Duration::from_millis(self.block_time));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn write_image_to_buf(_buf: &mut AniMePacketType, _image_data: &[u8]) {
|
pub fn write_image_to_buf(_buf: &mut AniMePacketType, _image_data: &[u8]) {
|
||||||
unimplemented!("Image format is in progress of being worked out")
|
unimplemented!("Image format is in progress of being worked out")
|
||||||
}
|
}
|
||||||
@@ -74,7 +78,7 @@ impl AniMeDbusWriter {
|
|||||||
image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX);
|
image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX);
|
||||||
|
|
||||||
proxy.set_anime(vec![image[0].to_vec(), image[1].to_vec()])?;
|
proxy.set_anime(vec![image[0].to_vec(), image[1].to_vec()])?;
|
||||||
thread::sleep(Duration::from_millis(self.block_time));
|
self.thread_sleep();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -90,24 +94,24 @@ impl AniMeDbusWriter {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn turn_on_off(&self, status : bool) -> Result<(), Box<dyn Error>> {
|
#[inline]
|
||||||
|
pub fn turn_on_off(&self, status: bool) -> Result<(), Box<dyn Error>> {
|
||||||
let proxy = self.new_proxy();
|
let proxy = self.new_proxy();
|
||||||
|
|
||||||
proxy.set_on_off(status)?;
|
proxy.set_on_off(status)?;
|
||||||
thread::sleep(Duration::from_millis(self.block_time));
|
self.thread_sleep();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn turn_on(&self) -> Result<(), Box<dyn Error>> {
|
pub fn turn_boot_on_off(&self, status: bool)
|
||||||
self.turn_on_off(true)?;
|
-> Result<(), Box<dyn Error>> {
|
||||||
Ok(())
|
let proxy = self.new_proxy();
|
||||||
}
|
|
||||||
|
proxy.set_boot_on_off(status)?;
|
||||||
|
self.thread_sleep();
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn turn_off(&self) -> Result<(), Box<dyn Error>> {
|
|
||||||
self.turn_on_off(false)?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,6 +231,37 @@ impl Default for SetAuraBuiltin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
pub enum AniMeStatusValue {
|
||||||
|
On,
|
||||||
|
Off,
|
||||||
|
}
|
||||||
|
impl FromStr for AniMeStatusValue {
|
||||||
|
type Err = AuraError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
let s = s.to_lowercase();
|
||||||
|
match s.as_str() {
|
||||||
|
"on" => Ok(AniMeStatusValue::On),
|
||||||
|
"off" => Ok(AniMeStatusValue::Off),
|
||||||
|
_ => {
|
||||||
|
print!("{}\n{}\n",
|
||||||
|
"Invalid argument, must be one of:",
|
||||||
|
"on, off");
|
||||||
|
Err(AuraError::ParseAnime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<AniMeStatusValue> for bool {
|
||||||
|
fn from(value: AniMeStatusValue) -> Self {
|
||||||
|
match value {
|
||||||
|
AniMeStatusValue::On => true,
|
||||||
|
AniMeStatusValue::Off => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Options)]
|
#[derive(Options)]
|
||||||
pub struct AniMeLeds {
|
pub struct AniMeLeds {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
@@ -240,7 +271,6 @@ pub struct AniMeLeds {
|
|||||||
help = "set all leds brightness value")]
|
help = "set all leds brightness value")]
|
||||||
led_brightness: u8,
|
led_brightness: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AniMeLeds {
|
impl AniMeLeds {
|
||||||
pub fn led_brightness(&self) -> u8 {
|
pub fn led_brightness(&self) -> u8 {
|
||||||
self.led_brightness
|
self.led_brightness
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use dbus::blocking;
|
|||||||
pub trait OrgAsuslinuxDaemon {
|
pub trait OrgAsuslinuxDaemon {
|
||||||
fn set_anime(&self, input: Vec<Vec<u8>>) -> Result<(), dbus::Error>;
|
fn set_anime(&self, input: Vec<Vec<u8>>) -> Result<(), dbus::Error>;
|
||||||
fn set_on_off(&self, status: bool) -> Result<(), dbus::Error>;
|
fn set_on_off(&self, status: bool) -> Result<(), dbus::Error>;
|
||||||
|
fn set_boot_on_off(&self, status: bool) -> Result<(), dbus::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslinuxDaemon for blocking::Proxy<'a, C> {
|
impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslinuxDaemon for blocking::Proxy<'a, C> {
|
||||||
@@ -18,4 +19,8 @@ impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslin
|
|||||||
fn set_on_off(&self, status: bool) -> Result<(), dbus::Error> {
|
fn set_on_off(&self, status: bool) -> Result<(), dbus::Error> {
|
||||||
self.method_call("org.asuslinux.Daemon", "SetOnOff", (status, ))
|
self.method_call("org.asuslinux.Daemon", "SetOnOff", (status, ))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_boot_on_off(&self, status: bool) -> Result<(), dbus::Error> {
|
||||||
|
self.method_call("org.asuslinux.Daemon", "SetBootOnOff", (status, ))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user