mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Rebuild of LED power control
This commit is contained in:
@@ -2,6 +2,53 @@ use gumdrop::Options;
|
||||
use rog_aura::{error::Error, AuraEffect, AuraModeNum, AuraZone, Colour, Direction, Speed};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Options)]
|
||||
pub struct LedPowerCommand {
|
||||
#[options(help = "print help message")]
|
||||
pub help: bool,
|
||||
#[options(command)]
|
||||
pub command: Option<SetAuraEnabled>,
|
||||
}
|
||||
|
||||
#[derive(Options)]
|
||||
pub enum SetAuraEnabled {
|
||||
#[options(help = "set <keyboard, logo, lightbar> to enabled while the device is booting")]
|
||||
Boot(AuraEnabled),
|
||||
#[options(help = "set <keyboard, logo, lightbar> to animate while the device is suspended")]
|
||||
Sleep(AuraEnabled),
|
||||
#[options(help = "set <keyboard, logo, lightbar> to enabled while device is awake")]
|
||||
Awake(AuraEnabled),
|
||||
#[options(help = "set <keyboard, logo, lightbar> to animate while the device is shutdown")]
|
||||
Shutdown(AuraEnabled),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Options)]
|
||||
pub struct AuraEnabled {
|
||||
#[options(help = "print help message")]
|
||||
pub help: bool,
|
||||
#[options(meta = "", help = "<true/false>")]
|
||||
pub keyboard: Option<bool>,
|
||||
#[options(meta = "", help = "<true/false>")]
|
||||
pub logo: Option<bool>,
|
||||
#[options(meta = "", help = "<true/false>")]
|
||||
pub lightbar: Option<bool>,
|
||||
}
|
||||
|
||||
// impl FromStr for AuraEnabled {
|
||||
// type Err = Error;
|
||||
|
||||
// fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
// let s = s.to_lowercase();
|
||||
// dbg!(s);
|
||||
// Ok(Self {
|
||||
// help: false,
|
||||
// keyboard: None,
|
||||
// logo: None,
|
||||
// lightbar: None,
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Options)]
|
||||
pub struct LedBrightness {
|
||||
level: Option<u32>,
|
||||
@@ -57,6 +104,7 @@ pub struct SingleSpeed {
|
||||
)]
|
||||
pub zone: AuraZone,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Options, Default)]
|
||||
pub struct SingleSpeedDirection {
|
||||
#[options(help = "print help message")]
|
||||
@@ -306,7 +354,6 @@ impl From<&SetAuraBuiltin> for AuraEffect {
|
||||
data.mode = AuraModeNum::Flash;
|
||||
data
|
||||
}
|
||||
_ => AuraEffect::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
anime_cli::AnimeCommand,
|
||||
aura_cli::{LedBrightness, SetAuraBuiltin},
|
||||
aura_cli::{LedBrightness, LedPowerCommand, SetAuraBuiltin},
|
||||
profiles_cli::{FanCurveCommand, ProfileCommand},
|
||||
};
|
||||
use gumdrop::Options;
|
||||
@@ -29,6 +29,8 @@ pub struct CliStart {
|
||||
pub enum CliCommand {
|
||||
#[options(help = "Set the keyboard lighting from built-in modes")]
|
||||
LedMode(LedModeCommand),
|
||||
#[options(help = "Set the keyboard lighting from built-in modes")]
|
||||
LedPower(LedPowerCommand),
|
||||
#[options(help = "Set or select platform_profile")]
|
||||
Profile(ProfileCommand),
|
||||
#[options(help = "Set, select, or modify fan curves if supported")]
|
||||
@@ -49,25 +51,6 @@ pub struct LedModeCommand {
|
||||
pub next_mode: bool,
|
||||
#[options(help = "switch to previous aura mode")]
|
||||
pub prev_mode: bool,
|
||||
#[options(
|
||||
meta = "",
|
||||
help = "set the keyboard LED to enabled while the device is awake"
|
||||
)]
|
||||
pub boot_enable: Option<bool>,
|
||||
#[options(
|
||||
meta = "",
|
||||
help = "set the keyboard LED suspend animation to enabled while the device is suspended"
|
||||
)]
|
||||
pub sleep_enable: Option<bool>,
|
||||
#[options(
|
||||
meta = "",
|
||||
help = "set the full keyboard LEDs (keys and side) to enabled"
|
||||
)]
|
||||
pub all_leds_enable: Option<bool>,
|
||||
#[options(meta = "", help = "set the keyboard keys LEDs to enabled")]
|
||||
pub keys_leds_enable: Option<bool>,
|
||||
#[options(meta = "", help = "set the keyboard side LEDs to enabled")]
|
||||
pub side_leds_enable: Option<bool>,
|
||||
#[options(command)]
|
||||
pub command: Option<SetAuraBuiltin>,
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ use std::process::Command;
|
||||
use std::thread::sleep;
|
||||
use std::{env::args, path::Path};
|
||||
|
||||
use aura_cli::LedPowerCommand;
|
||||
use gumdrop::{Opt, Options};
|
||||
|
||||
use anime_cli::{AnimeActions, AnimeCommand};
|
||||
use profiles_cli::{FanCurveCommand, ProfileCommand};
|
||||
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, Vec2};
|
||||
use rog_aura::usb::AuraControl;
|
||||
use rog_aura::{self, AuraEffect};
|
||||
use rog_dbus::RogDbusClientBlocking;
|
||||
use rog_profiles::error::ProfileError;
|
||||
@@ -143,6 +145,7 @@ fn do_parsed(
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match &parsed.command {
|
||||
Some(CliCommand::LedMode(mode)) => handle_led_mode(dbus, &supported.keyboard_led, mode)?,
|
||||
Some(CliCommand::LedPower(pow)) => handle_led_power(dbus, &supported.keyboard_led, pow)?,
|
||||
Some(CliCommand::Profile(cmd)) => handle_profile(dbus, &supported.platform_profile, cmd)?,
|
||||
Some(CliCommand::FanCurve(cmd)) => {
|
||||
handle_fan_curve(dbus, &supported.platform_profile, cmd)?
|
||||
@@ -339,15 +342,7 @@ fn handle_led_mode(
|
||||
supported: &LedSupportedFunctions,
|
||||
mode: &LedModeCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if mode.command.is_none()
|
||||
&& !mode.prev_mode
|
||||
&& !mode.next_mode
|
||||
&& mode.boot_enable.is_none()
|
||||
&& mode.sleep_enable.is_none()
|
||||
&& mode.all_leds_enable.is_none()
|
||||
&& mode.keys_leds_enable.is_none()
|
||||
&& mode.side_leds_enable.is_none()
|
||||
{
|
||||
if mode.command.is_none() && !mode.prev_mode && !mode.next_mode {
|
||||
if !mode.help {
|
||||
println!("Missing arg or command\n");
|
||||
}
|
||||
@@ -396,22 +391,165 @@ fn handle_led_mode(
|
||||
.set_led_mode(&<AuraEffect>::from(mode))?;
|
||||
}
|
||||
|
||||
if let Some(enable) = mode.boot_enable {
|
||||
dbus.proxies().led().set_boot_enabled(enable)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_led_power(
|
||||
dbus: &RogDbusClientBlocking,
|
||||
_supported: &LedSupportedFunctions,
|
||||
power: &LedPowerCommand,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if power.command().is_none() {
|
||||
if !power.help {
|
||||
println!("Missing arg or command\n");
|
||||
}
|
||||
println!("{}\n", power.self_usage());
|
||||
println!("Commands available");
|
||||
|
||||
if let Some(cmdlist) = LedPowerCommand::command_list() {
|
||||
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_string()).collect();
|
||||
for command in commands.iter() {
|
||||
println!("{}", command);
|
||||
}
|
||||
}
|
||||
|
||||
println!("\nHelp can also be requested on commands, e.g: boot --help");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(enable) = mode.sleep_enable {
|
||||
dbus.proxies().led().set_sleep_enabled(enable)?;
|
||||
}
|
||||
if let Some(pow) = power.command.as_ref() {
|
||||
if pow.help_requested() {
|
||||
println!("{}", pow.self_usage());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(enable) = mode.all_leds_enable {
|
||||
dbus.proxies().led().set_all_leds_enabled(enable)?;
|
||||
}
|
||||
if let Some(enable) = mode.keys_leds_enable {
|
||||
dbus.proxies().led().set_keys_leds_enabled(enable)?;
|
||||
}
|
||||
if let Some(enable) = mode.side_leds_enable {
|
||||
dbus.proxies().led().set_side_leds_enabled(enable)?;
|
||||
match pow {
|
||||
// TODO: make this a macro or something
|
||||
aura_cli::SetAuraEnabled::Boot(arg) => {
|
||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
||||
arg.keyboard.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::BootKeyb)
|
||||
} else {
|
||||
disabled.push(AuraControl::BootKeyb)
|
||||
}
|
||||
});
|
||||
arg.logo.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::BootLogo)
|
||||
} else {
|
||||
disabled.push(AuraControl::BootLogo)
|
||||
}
|
||||
});
|
||||
arg.lightbar.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::BootBar)
|
||||
} else {
|
||||
disabled.push(AuraControl::BootBar)
|
||||
}
|
||||
});
|
||||
if !enabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_enabled(enabled)?;
|
||||
}
|
||||
if !disabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_disabled(disabled)?;
|
||||
}
|
||||
}
|
||||
aura_cli::SetAuraEnabled::Sleep(arg) => {
|
||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
||||
arg.keyboard.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::SleepKeyb)
|
||||
} else {
|
||||
disabled.push(AuraControl::SleepKeyb)
|
||||
}
|
||||
});
|
||||
arg.logo.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::SleepLogo)
|
||||
} else {
|
||||
disabled.push(AuraControl::SleepLogo)
|
||||
}
|
||||
});
|
||||
arg.lightbar.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::SleepBar)
|
||||
} else {
|
||||
disabled.push(AuraControl::SleepBar)
|
||||
}
|
||||
});
|
||||
if !enabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_enabled(enabled)?;
|
||||
}
|
||||
if !disabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_disabled(disabled)?;
|
||||
}
|
||||
}
|
||||
aura_cli::SetAuraEnabled::Awake(arg) => {
|
||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
||||
arg.keyboard.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::AwakeKeyb)
|
||||
} else {
|
||||
disabled.push(AuraControl::AwakeKeyb)
|
||||
}
|
||||
});
|
||||
arg.logo.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::AwakeLogo)
|
||||
} else {
|
||||
disabled.push(AuraControl::AwakeLogo)
|
||||
}
|
||||
});
|
||||
arg.lightbar.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::AwakeBar)
|
||||
} else {
|
||||
disabled.push(AuraControl::AwakeBar)
|
||||
}
|
||||
});
|
||||
if !enabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_enabled(enabled)?;
|
||||
}
|
||||
if !disabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_disabled(disabled)?;
|
||||
}
|
||||
}
|
||||
aura_cli::SetAuraEnabled::Shutdown(arg) => {
|
||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
||||
arg.keyboard.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::ShutdownKeyb)
|
||||
} else {
|
||||
disabled.push(AuraControl::ShutdownKeyb)
|
||||
}
|
||||
});
|
||||
arg.logo.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::ShutdownLogo)
|
||||
} else {
|
||||
disabled.push(AuraControl::ShutdownLogo)
|
||||
}
|
||||
});
|
||||
arg.lightbar.map(|v| {
|
||||
if v {
|
||||
enabled.push(AuraControl::ShutdownBar)
|
||||
} else {
|
||||
disabled.push(AuraControl::ShutdownBar)
|
||||
}
|
||||
});
|
||||
if !enabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_enabled(enabled)?;
|
||||
}
|
||||
if !disabled.is_empty() {
|
||||
dbus.proxies().led().set_leds_disabled(disabled)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user