Merge branch 'asere/anime_better_options' into 'next'

Better anime options & gumdrop error Display

See merge request asus-linux/asus-nb-ctrl!12
This commit is contained in:
Luke Jones
2020-12-20 21:18:51 +00:00
5 changed files with 99 additions and 38 deletions

View File

@@ -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(())

View File

@@ -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();

View File

@@ -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]) {
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);
proxy.set_anime(vec![image[0].to_vec(), image[1].to_vec()])?;
thread::sleep(Duration::from_millis(self.block_time));
self.thread_sleep();
Ok(())
}
@@ -90,24 +94,24 @@ impl AniMeDbusWriter {
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();
proxy.set_on_off(status)?;
thread::sleep(Duration::from_millis(self.block_time));
self.thread_sleep();
Ok(())
}
#[inline]
pub fn turn_on(&self) -> Result<(), Box<dyn Error>> {
self.turn_on_off(true)?;
Ok(())
}
pub fn turn_boot_on_off(&self, status: bool)
-> Result<(), Box<dyn Error>> {
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(())
}
}

View File

@@ -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)]
pub struct AniMeLeds {
#[options(help = "print help message")]
@@ -240,7 +271,6 @@ pub struct AniMeLeds {
help = "set all leds brightness value")]
led_brightness: u8,
}
impl AniMeLeds {
pub fn led_brightness(&self) -> u8 {
self.led_brightness

View File

@@ -7,6 +7,7 @@ use dbus::blocking;
pub trait OrgAsuslinuxDaemon {
fn set_anime(&self, input: Vec<Vec<u8>>) -> 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> {
@@ -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> {
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, ))
}
}