mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
feat: refactor cli options for leds
This commit is contained in:
@@ -12,16 +12,6 @@ use crate::slash_cli::SlashCommand;
|
|||||||
pub struct CliStart {
|
pub struct CliStart {
|
||||||
#[argh(switch, description = "show supported functions of this laptop")]
|
#[argh(switch, description = "show supported functions of this laptop")]
|
||||||
pub show_supported: bool,
|
pub show_supported: bool,
|
||||||
|
|
||||||
#[argh(option, description = "keyboard brightness <off, low, med, high>")]
|
|
||||||
pub kbd_bright: Option<LedBrightness>,
|
|
||||||
|
|
||||||
#[argh(switch, description = "toggle to next keyboard brightness")]
|
|
||||||
pub next_kbd_bright: bool,
|
|
||||||
|
|
||||||
#[argh(switch, description = "toggle to previous keyboard brightness")]
|
|
||||||
pub prev_kbd_bright: bool,
|
|
||||||
|
|
||||||
#[argh(option, description = "set your battery charge limit <20-100>")]
|
#[argh(option, description = "set your battery charge limit <20-100>")]
|
||||||
pub chg_limit: Option<u8>,
|
pub chg_limit: Option<u8>,
|
||||||
|
|
||||||
@@ -39,6 +29,7 @@ pub enum CliCommand {
|
|||||||
Aura(LedModeCommand),
|
Aura(LedModeCommand),
|
||||||
AuraPowerOld(LedPowerCommand1),
|
AuraPowerOld(LedPowerCommand1),
|
||||||
AuraPower(LedPowerCommand2),
|
AuraPower(LedPowerCommand2),
|
||||||
|
Brightness(BrightnessCommand),
|
||||||
Profile(ProfileCommand),
|
Profile(ProfileCommand),
|
||||||
FanCurve(FanCurveCommand),
|
FanCurve(FanCurveCommand),
|
||||||
Anime(AnimeCommand),
|
Anime(AnimeCommand),
|
||||||
@@ -211,3 +202,60 @@ pub struct BacklightCommand {
|
|||||||
description = "show program version and system info"
|
description = "show program version and system info"
|
||||||
)]
|
)]
|
||||||
pub struct InfoCommand {}
|
pub struct InfoCommand {}
|
||||||
|
|
||||||
|
#[derive(FromArgs, Debug)]
|
||||||
|
#[argh(subcommand, name = "leds", description = "keyboard brightness control")]
|
||||||
|
pub struct BrightnessCommand {
|
||||||
|
#[argh(subcommand)]
|
||||||
|
pub command: BrightnessSubCommand,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs, Debug)]
|
||||||
|
#[argh(subcommand)]
|
||||||
|
pub enum BrightnessSubCommand {
|
||||||
|
Set(BrightnessSetCommand),
|
||||||
|
Get(BrightnessGetCommand),
|
||||||
|
Next(BrightnessNextCommand),
|
||||||
|
Prev(BrightnessPrevCommand),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for BrightnessSubCommand {
|
||||||
|
fn default() -> Self {
|
||||||
|
BrightnessSubCommand::Get(BrightnessGetCommand::default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs, Debug)]
|
||||||
|
#[argh(
|
||||||
|
subcommand,
|
||||||
|
name = "set",
|
||||||
|
description = "set keyboard brightness <off, low, med, high>"
|
||||||
|
)]
|
||||||
|
pub struct BrightnessSetCommand {
|
||||||
|
#[argh(positional, description = "brightness level: off, low, med, high")]
|
||||||
|
pub level: LedBrightness,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(FromArgs, Debug, Default)]
|
||||||
|
#[argh(
|
||||||
|
subcommand,
|
||||||
|
name = "get",
|
||||||
|
description = "get current keyboard brightness"
|
||||||
|
)]
|
||||||
|
pub struct BrightnessGetCommand {}
|
||||||
|
|
||||||
|
#[derive(FromArgs, Debug, Default)]
|
||||||
|
#[argh(
|
||||||
|
subcommand,
|
||||||
|
name = "next",
|
||||||
|
description = "toggle to next keyboard brightness"
|
||||||
|
)]
|
||||||
|
pub struct BrightnessNextCommand {}
|
||||||
|
|
||||||
|
#[derive(FromArgs, Debug, Default)]
|
||||||
|
#[argh(
|
||||||
|
subcommand,
|
||||||
|
name = "prev",
|
||||||
|
description = "toggle to previous keyboard brightness"
|
||||||
|
)]
|
||||||
|
pub struct BrightnessPrevCommand {}
|
||||||
|
|||||||
@@ -190,6 +190,7 @@ fn do_parsed(
|
|||||||
Some(CliCommand::Aura(mode)) => handle_led_mode(mode)?,
|
Some(CliCommand::Aura(mode)) => handle_led_mode(mode)?,
|
||||||
Some(CliCommand::AuraPowerOld(pow)) => handle_led_power1(pow)?,
|
Some(CliCommand::AuraPowerOld(pow)) => handle_led_power1(pow)?,
|
||||||
Some(CliCommand::AuraPower(pow)) => handle_led_power2(pow)?,
|
Some(CliCommand::AuraPower(pow)) => handle_led_power2(pow)?,
|
||||||
|
Some(CliCommand::Brightness(cmd)) => handle_brightness(cmd)?,
|
||||||
Some(CliCommand::Profile(cmd)) => {
|
Some(CliCommand::Profile(cmd)) => {
|
||||||
handle_throttle_profile(&conn, supported_properties, cmd)?
|
handle_throttle_profile(&conn, supported_properties, cmd)?
|
||||||
}
|
}
|
||||||
@@ -207,56 +208,12 @@ fn do_parsed(
|
|||||||
print_info();
|
print_info();
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if !parsed.show_supported
|
if !parsed.show_supported && parsed.chg_limit.is_none() && !parsed.one_shot_chg {
|
||||||
&& parsed.kbd_bright.is_none()
|
|
||||||
&& parsed.chg_limit.is_none()
|
|
||||||
&& !parsed.next_kbd_bright
|
|
||||||
&& !parsed.prev_kbd_bright
|
|
||||||
&& !parsed.one_shot_chg
|
|
||||||
{
|
|
||||||
println!("No command given. Run 'asusctl --help' for usage and 'asusctl <command> --help' for subcommands.");
|
println!("No command given. Run 'asusctl --help' for usage and 'asusctl <command> --help' for subcommands.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(brightness) = &parsed.kbd_bright {
|
|
||||||
if let Ok(aura) = find_iface::<AuraProxyBlocking>("xyz.ljones.Aura") {
|
|
||||||
for aura in aura.iter() {
|
|
||||||
match brightness.level() {
|
|
||||||
None => {
|
|
||||||
let level = aura.brightness()?;
|
|
||||||
println!("Current keyboard led brightness: {level:?}");
|
|
||||||
}
|
|
||||||
Some(level) => aura.set_brightness(rog_aura::LedBrightness::from(level))?,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("No aura interface found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if parsed.next_kbd_bright {
|
|
||||||
if let Ok(aura) = find_iface::<AuraProxyBlocking>("xyz.ljones.Aura") {
|
|
||||||
for aura in aura.iter() {
|
|
||||||
let brightness = aura.brightness()?;
|
|
||||||
aura.set_brightness(brightness.next())?;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("No aura interface found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if parsed.prev_kbd_bright {
|
|
||||||
if let Ok(aura) = find_iface::<AuraProxyBlocking>("xyz.ljones.Aura") {
|
|
||||||
for aura in aura.iter() {
|
|
||||||
let brightness = aura.brightness()?;
|
|
||||||
aura.set_brightness(brightness.prev())?;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("No aura interface found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if parsed.show_supported {
|
if parsed.show_supported {
|
||||||
println!("Supported Core Functions:\n{:#?}", supported_interfaces);
|
println!("Supported Core Functions:\n{:#?}", supported_interfaces);
|
||||||
println!(
|
println!(
|
||||||
@@ -328,6 +285,48 @@ fn handle_backlight(cmd: &BacklightCommand) -> Result<(), Box<dyn std::error::Er
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_brightness(cmd: &BrightnessCommand) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let Ok(aura_proxies) = find_iface::<AuraProxyBlocking>("xyz.ljones.Aura") else {
|
||||||
|
println!("No aura interface found");
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
match &cmd.command {
|
||||||
|
BrightnessSubCommand::Set(s) => {
|
||||||
|
for aura in aura_proxies.iter() {
|
||||||
|
if let Some(level) = s.level.level() {
|
||||||
|
aura.set_brightness(rog_aura::LedBrightness::from(level))?;
|
||||||
|
} else {
|
||||||
|
let current = aura.brightness()?;
|
||||||
|
println!("Current keyboard led brightness: {current:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BrightnessSubCommand::Get(_) => {
|
||||||
|
for aura in aura_proxies.iter() {
|
||||||
|
let level = aura.brightness()?;
|
||||||
|
println!("Current keyboard led brightness: {level:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
BrightnessSubCommand::Next(_) => {
|
||||||
|
for aura in aura_proxies.iter() {
|
||||||
|
let brightness = aura.brightness()?;
|
||||||
|
aura.set_brightness(brightness.next())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BrightnessSubCommand::Prev(_) => {
|
||||||
|
for aura in aura_proxies.iter() {
|
||||||
|
let brightness = aura.brightness()?;
|
||||||
|
aura.set_brightness(brightness.prev())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn handle_anime(cmd: &AnimeCommand) -> Result<(), Box<dyn std::error::Error>> {
|
fn handle_anime(cmd: &AnimeCommand) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if cmd.command.is_none()
|
if cmd.command.is_none()
|
||||||
&& cmd.enable_display.is_none()
|
&& cmd.enable_display.is_none()
|
||||||
|
|||||||
Reference in New Issue
Block a user