mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Merge branch 'asere/anime_on_off' into 'next'
AniMe: adding --on and --off options to turn on/off (and accept/reject write requests) See merge request asus-linux/asus-nb-ctrl!11
This commit is contained in:
@@ -9,6 +9,10 @@ const INIT: u8 = 0xc2;
|
|||||||
const APPLY: u8 = 0xc3;
|
const APPLY: u8 = 0xc3;
|
||||||
const SET: u8 = 0xc4;
|
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 asus_nb::error::AuraError;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use rusb::{Device, DeviceHandle};
|
use rusb::{Device, DeviceHandle};
|
||||||
@@ -22,6 +26,7 @@ use zbus::dbus_interface;
|
|||||||
pub enum AnimatrixCommand {
|
pub enum AnimatrixCommand {
|
||||||
Apply,
|
Apply,
|
||||||
Set,
|
Set,
|
||||||
|
Write(Vec<u8>),
|
||||||
WriteImage(Vec<Vec<u8>>),
|
WriteImage(Vec<Vec<u8>>),
|
||||||
//ReloadLast,
|
//ReloadLast,
|
||||||
}
|
}
|
||||||
@@ -34,6 +39,8 @@ pub struct CtrlAnimeDisplay {
|
|||||||
//AnimatrixWrite
|
//AnimatrixWrite
|
||||||
pub trait Dbus {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::ZbusAdd for CtrlAnimeDisplay {
|
impl crate::ZbusAdd for CtrlAnimeDisplay {
|
||||||
@@ -54,6 +61,26 @@ impl Dbus for CtrlAnimeDisplay {
|
|||||||
self.do_command(AnimatrixCommand::WriteImage(input))
|
self.do_command(AnimatrixCommand::WriteImage(input))
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.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 {
|
impl CtrlAnimeDisplay {
|
||||||
@@ -99,9 +126,10 @@ impl CtrlAnimeDisplay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match command {
|
match command {
|
||||||
AnimatrixCommand::WriteImage(effect) => self.write_image(effect)?,
|
|
||||||
AnimatrixCommand::Set => self.do_set()?,
|
|
||||||
AnimatrixCommand::Apply => self.do_apply()?,
|
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?,
|
//AnimatrixCommand::ReloadLast => self.reload_last_builtin(&config).await?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
use asus_nb::{
|
use asus_nb::{
|
||||||
cli_options::{LedBrightness, SetAuraBuiltin, AniMeActions},
|
cli_options::{
|
||||||
|
LedBrightness,
|
||||||
|
SetAuraBuiltin,
|
||||||
|
AniMeActions,
|
||||||
|
},
|
||||||
core_dbus::AuraDbusClient,
|
core_dbus::AuraDbusClient,
|
||||||
anime_dbus::AniMeDbusWriter,
|
anime_dbus::AniMeDbusWriter,
|
||||||
profile::{ProfileCommand, ProfileEvent},
|
profile::{ProfileCommand, ProfileEvent},
|
||||||
@@ -69,11 +73,17 @@ struct GraphicsCommand {
|
|||||||
force: bool,
|
force: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Options)]
|
#[derive(Options)]
|
||||||
struct AniMeCommand {
|
struct AniMeCommand {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
help: bool,
|
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>,
|
command: Option<AniMeActions>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +127,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let writer = AuraDbusClient::new()?;
|
let writer = AuraDbusClient::new()?;
|
||||||
let anime = AniMeDbusWriter::new()?;
|
let anime_writer = AniMeDbusWriter::new()?;
|
||||||
|
|
||||||
match parsed.command {
|
match parsed.command {
|
||||||
Some(CliCommand::LedMode(mode)) => {
|
Some(CliCommand::LedMode(mode)) => {
|
||||||
@@ -129,14 +139,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
writer.write_profile_command(&ProfileEvent::Cli(command))?
|
writer.write_profile_command(&ProfileEvent::Cli(command))?
|
||||||
}
|
}
|
||||||
Some(CliCommand::Graphics(command)) => do_gfx(command, &writer)?,
|
Some(CliCommand::Graphics(command)) => do_gfx(command, &writer)?,
|
||||||
Some(CliCommand::AniMe(
|
Some(CliCommand::AniMe(anime)) => {
|
||||||
AniMeCommand {
|
if anime.on {
|
||||||
command: Some(AniMeActions::Leds(anime_leds)), ..
|
anime_writer.turn_on()?;
|
||||||
})) => {
|
} else if anime.off {
|
||||||
anime.set_leds_brightness(anime_leds.led_brightness())?;
|
anime_writer.turn_off()?;
|
||||||
},
|
} else if let Some(action) = anime.command {
|
||||||
Some(CliCommand::AniMe(_))
|
match action {
|
||||||
| None => (),
|
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 {
|
if let Some(brightness) = parsed.kbd_bright {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ pub const ANIME_PANE2_PREFIX: [u8; 7] =
|
|||||||
|
|
||||||
use crate::anime_matrix::{AniMeMatrix, AniMePacketType};
|
use crate::anime_matrix::{AniMeMatrix, AniMePacketType};
|
||||||
use crate::DBUS_NAME;
|
use crate::DBUS_NAME;
|
||||||
use dbus::blocking::Connection;
|
use dbus::blocking::{Connection, Proxy};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::{thread, time::Duration};
|
use std::{thread, time::Duration};
|
||||||
|
|
||||||
@@ -37,20 +37,13 @@ impl AniMeDbusWriter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create D-Bus proxy and send the message
|
// Create D-Bus proxy
|
||||||
#[inline]
|
fn new_proxy(&self) -> Proxy<&Connection>{
|
||||||
fn write_anime(&self, input: Vec<Vec<u8>>)
|
self.connection.with_proxy(
|
||||||
-> Result<(), Box<dyn Error>> {
|
|
||||||
let proxy = self.connection.with_proxy(
|
|
||||||
DBUS_NAME,
|
DBUS_NAME,
|
||||||
DBUS_ANIME_PATH,
|
DBUS_ANIME_PATH,
|
||||||
Duration::from_millis(200),
|
Duration::from_millis(200),
|
||||||
);
|
)
|
||||||
|
|
||||||
proxy.set_anime(input)?;
|
|
||||||
thread::sleep(Duration::from_millis(self.block_time));
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_image_to_buf(_buf: &mut AniMePacketType, _image_data: &[u8]) {
|
pub fn write_image_to_buf(_buf: &mut AniMePacketType, _image_data: &[u8]) {
|
||||||
@@ -75,9 +68,14 @@ impl AniMeDbusWriter {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn write_image(&self, image: &mut AniMePacketType)
|
pub fn write_image(&self, image: &mut AniMePacketType)
|
||||||
-> Result<(), Box<dyn Error>> {
|
-> Result<(), Box<dyn Error>> {
|
||||||
|
let proxy = self.new_proxy();
|
||||||
|
|
||||||
image[0][..7].copy_from_slice(&ANIME_PANE1_PREFIX);
|
image[0][..7].copy_from_slice(&ANIME_PANE1_PREFIX);
|
||||||
image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX);
|
image[1][..7].copy_from_slice(&ANIME_PANE2_PREFIX);
|
||||||
self.write_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));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +86,28 @@ impl AniMeDbusWriter {
|
|||||||
|
|
||||||
anime_matrix.fill_with(led_brightness);
|
anime_matrix.fill_with(led_brightness);
|
||||||
self.write_image(&mut AniMePacketType::from(anime_matrix))?;
|
self.write_image(&mut AniMePacketType::from(anime_matrix))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn turn_on(&self) -> Result<(), Box<dyn Error>> {
|
||||||
|
self.turn_on_off(true)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn turn_off(&self) -> Result<(), Box<dyn Error>> {
|
||||||
|
self.turn_on_off(false)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,8 +231,7 @@ impl Default for SetAuraBuiltin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Options)]
|
||||||
#[derive(Debug, Options)]
|
|
||||||
pub struct AniMeLeds {
|
pub struct AniMeLeds {
|
||||||
#[options(help = "print help message")]
|
#[options(help = "print help message")]
|
||||||
help: bool,
|
help: bool,
|
||||||
@@ -248,8 +247,8 @@ impl AniMeLeds {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Options)]
|
#[derive(Options)]
|
||||||
pub enum AniMeActions {
|
pub enum AniMeActions {
|
||||||
#[options(help = "change all leds brightness")]
|
#[options(help = "change all leds brightness")]
|
||||||
Leds(AniMeLeds)
|
Leds(AniMeLeds),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,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>;
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
||||||
@@ -13,4 +14,8 @@ impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslin
|
|||||||
fn set_anime(&self, input: Vec<Vec<u8>>) -> Result<(), dbus::Error> {
|
fn set_anime(&self, input: Vec<Vec<u8>>) -> Result<(), dbus::Error> {
|
||||||
self.method_call("org.asuslinux.Daemon", "SetAnime", (input, ))
|
self.method_call("org.asuslinux.Daemon", "SetAnime", (input, ))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_on_off(&self, status: bool) -> Result<(), dbus::Error> {
|
||||||
|
self.method_call("org.asuslinux.Daemon", "SetOnOff", (status, ))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user