AniMe: adding --on and --off options to turn on/off (and accept/reject write requests)

This commit is contained in:
Asere
2020-10-22 14:09:05 +02:00
parent a23c51e5db
commit 5d06c87943
5 changed files with 100 additions and 31 deletions

View File

@@ -9,6 +9,10 @@ const INIT: u8 = 0xc2;
const APPLY: u8 = 0xc3;
const SET: u8 = 0xc4;
// Used to turn the panel on and off
// The next byte can be 0x03 for "on" and 0x00 for "off"
const ON_OFF : u8 = 0x04;
use asus_nb::error::AuraError;
use log::{error, info, warn};
use rusb::{Device, DeviceHandle};
@@ -22,6 +26,7 @@ use zbus::dbus_interface;
pub enum AnimatrixCommand {
Apply,
Set,
Write(Vec<u8>),
WriteImage(Vec<Vec<u8>>),
//ReloadLast,
}
@@ -34,6 +39,8 @@ pub struct CtrlAnimeDisplay {
//AnimatrixWrite
pub trait Dbus {
fn set_anime(&mut self, input: Vec<Vec<u8>>);
fn set_on_off(&mut self, status: bool);
}
impl crate::ZbusAdd for CtrlAnimeDisplay {
@@ -54,6 +61,26 @@ impl Dbus for CtrlAnimeDisplay {
self.do_command(AnimatrixCommand::WriteImage(input))
.unwrap_or_else(|err| warn!("{}", err));
}
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 status_str;
if status {
activity[3] = 0x03;
status_str = "on";
} else {
activity[3] = 0x00;
status_str = "off";
}
info!("Turning {} the AniMe", status_str);
self.do_command(AnimatrixCommand::Write(activity))
.unwrap_or_else(|err| warn!("{}", err));
}
}
impl CtrlAnimeDisplay {
@@ -99,9 +126,10 @@ impl CtrlAnimeDisplay {
}
match command {
AnimatrixCommand::WriteImage(effect) => self.write_image(effect)?,
AnimatrixCommand::Set => self.do_set()?,
AnimatrixCommand::Apply => self.do_apply()?,
AnimatrixCommand::Set => self.do_set()?,
AnimatrixCommand::Write(bytes) => self.write_bytes(&bytes)?,
AnimatrixCommand::WriteImage(effect) => self.write_image(effect)?,
//AnimatrixCommand::ReloadLast => self.reload_last_builtin(&config).await?,
}
Ok(())

View File

@@ -1,5 +1,9 @@
use asus_nb::{
cli_options::{LedBrightness, SetAuraBuiltin, AniMeActions},
cli_options::{
LedBrightness,
SetAuraBuiltin,
AniMeActions,
},
core_dbus::AuraDbusClient,
anime_dbus::AniMeDbusWriter,
profile::{ProfileCommand, ProfileEvent},
@@ -63,11 +67,17 @@ struct GraphicsCommand {
force: bool,
}
#[derive(Debug, Options)]
#[derive(Options)]
struct AniMeCommand {
#[options(help = "print help message")]
help: bool,
#[options(command, required)]
#[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(command)]
command: Option<AniMeActions>,
}
@@ -86,7 +96,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
let writer = AuraDbusClient::new()?;
let anime = AniMeDbusWriter::new()?;
let anime_writer = AniMeDbusWriter::new()?;
match parsed.command {
Some(CliCommand::LedMode(mode)) => {
@@ -98,14 +108,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
writer.write_profile_command(&ProfileEvent::Cli(command))?
}
Some(CliCommand::Graphics(command)) => do_gfx(command, &writer)?,
Some(CliCommand::AniMe(
AniMeCommand {
command: Some(AniMeActions::Leds(anime_leds)), ..
})) => {
anime.set_leds_brightness(anime_leds.led_brightness())?;
},
Some(CliCommand::AniMe(_))
| None => (),
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 {
match action {
AniMeActions::Leds(anime_leds) => {
let led_brightness = anime_leds.led_brightness();
anime_writer.set_leds_brightness(led_brightness)?;
}
}
}
}
None => ()
}
if let Some(brightness) = parsed.kbd_bright {