From f7456f01447921e00fff501cbdeb6ae4ede39258 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sun, 29 Dec 2024 12:03:50 +1300 Subject: [PATCH] Allow changing of platform values with cli --- asusctl/src/cli_opts.rs | 11 +- asusctl/src/main.rs | 149 ++++++++---------- .../translations/en/rog-control-center.po | 2 +- 3 files changed, 78 insertions(+), 84 deletions(-) diff --git a/asusctl/src/cli_opts.rs b/asusctl/src/cli_opts.rs index 1f21195c..2253f184 100644 --- a/asusctl/src/cli_opts.rs +++ b/asusctl/src/cli_opts.rs @@ -50,9 +50,12 @@ pub enum CliCommand { #[options(name = "scsi", help = "Manage SCSI external drive")] Scsi(ScsiCommand), #[options(help = "Change bios settings")] - Platform(PlatformCommand), - #[options(help = "Change platform settings")] - PlatformNew(PlatformNewCommand), + PlatformOld(PlatformCommand), + #[options( + help = "Change platform settings. This is a new interface exposed by the asus-armoury \ + driver, some of the settings will be the same as the older platform interface" + )] + Armoury(ArmouryCommand), } #[derive(Debug, Clone, Options)] @@ -125,7 +128,7 @@ pub struct PlatformCommand { } #[derive(Options, Debug)] -pub struct PlatformNewCommand { +pub struct ArmouryCommand { #[options(help = "print help message")] pub help: bool, #[options(free)] diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index e2e8b26f..14c42c86 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -186,10 +186,10 @@ fn do_parsed( Some(CliCommand::Anime(cmd)) => handle_anime(cmd)?, Some(CliCommand::Slash(cmd)) => handle_slash(cmd)?, Some(CliCommand::Scsi(cmd)) => handle_scsi(cmd)?, - Some(CliCommand::Platform(cmd)) => { + Some(CliCommand::PlatformOld(cmd)) => { handle_platform_properties(&conn, supported_properties, cmd)? } - Some(CliCommand::PlatformNew(cmd)) => handle_platform_new_properties(&conn, cmd)?, + Some(CliCommand::Armoury(cmd)) => handle_armoury_command(cmd)?, None => { if (!parsed.show_supported && parsed.kbd_bright.is_none() @@ -245,6 +245,12 @@ fn do_parsed( return false; } + if command.trim().starts_with("platform") + && !supported_interfaces.contains(&"xyz.ljones.AsusArmoury".to_string()) + { + return false; + } + if !dev_type.is_old_laptop() && !dev_type.is_tuf_laptop() && command.trim().starts_with("aura-power-old") @@ -1070,10 +1076,60 @@ fn check_systemd_unit_enabled(name: &str) -> bool { false } -fn handle_platform_new_properties( - conn: &Connection, - cmd: &PlatformNewCommand, -) -> Result<(), Box> { +fn print_firmware_attr(attr: &AsusArmouryProxyBlocking) -> Result<(), Box> { + let name = attr.name()?; + println!("{name}:"); + + let attrs = attr.available_attrs()?; + if attrs.contains(&"min_value".to_string()) + && attrs.contains(&"max_value".to_string()) + && attrs.contains(&"current_value".to_string()) + { + let c = attr.current_value()?; + let min = attr.min_value()?; + let max = attr.max_value()?; + println!(" current: {min}..[{c}]..{max}"); + if attrs.contains(&"default_value".to_string()) { + println!(" default: {}\n", attr.default_value()?); + } else { + println!(); + } + } else if attrs.contains(&"possible_values".to_string()) + && attrs.contains(&"current_value".to_string()) + { + let c = attr.current_value()?; + let v = attr.possible_values()?; + for p in v.iter().enumerate() { + if p.0 == 0 { + print!(" current: ["); + } + if *p.1 == c { + print!("({c})"); + } else { + print!("{}", p.1); + } + if p.0 < v.len() - 1 { + print!(","); + } + if p.0 == v.len() - 1 { + print!("]"); + } + } + if attrs.contains(&"default_value".to_string()) { + println!(" default: {}\n", attr.default_value()?); + } else { + println!("\n"); + } + } else if attrs.contains(&"current_value".to_string()) { + let c = attr.current_value()?; + println!(" current: {c}\n"); + } else { + println!(); + } + return Ok(()); +} + +fn handle_armoury_command(cmd: &ArmouryCommand) -> Result<(), Box> { { if cmd.free.is_empty() || cmd.free.len() % 2 != 0 || cmd.help { const USAGE: &str = "Usage: asusctl platform panel_overdrive 1 nv_dynamic_boost 5"; @@ -1089,85 +1145,20 @@ fn handle_platform_new_properties( println!("\n{USAGE}\n"); println!("Available firmware attributes: "); for attr in attr.iter() { - let name = attr.name()?; - println!("{name}:"); - - let attrs = attr.available_attrs()?; - if attrs.contains(&"min_value".to_string()) - && attrs.contains(&"max_value".to_string()) - && attrs.contains(&"current_value".to_string()) - { - let c = attr.current_value()?; - let min = attr.min_value()?; - let max = attr.max_value()?; - println!(" current: {min}..[{c}]..{max}"); - if attrs.contains(&"default_value".to_string()) { - println!(" default: {}\n", attr.default_value()?); - } else { - println!(); - } - } else if attrs.contains(&"possible_values".to_string()) - && attrs.contains(&"current_value".to_string()) - { - let c = attr.current_value()?; - let v = attr.possible_values()?; - for p in v.iter().enumerate() { - if p.0 == 0 { - print!(" current: ["); - } - if *p.1 == c { - print!("({c})"); - } else { - print!("{}", p.1); - } - if p.0 < v.len() - 1 { - print!(","); - } - if p.0 == v.len() - 1 { - print!("]"); - } - } - if attrs.contains(&"default_value".to_string()) { - println!(" default: {}\n", attr.default_value()?); - } else { - println!("\n"); - } - } else if attrs.contains(&"current_value".to_string()) { - let c = attr.current_value()?; - println!(" current: {c}\n"); - } else { - println!(); - } + print_firmware_attr(attr)?; } } return Ok(()); } if let Ok(attr) = find_iface::("xyz.ljones.AsusArmoury") { - for attr in attr.iter() { - let name = attr.name()?; - let attrs = attr.available_attrs()?; - // dbg!(&name, &attrs); - println!("{name}::"); - if attrs.contains(&"current_value".to_string()) { - let v = attr.current_value()?; - println!(" current_value: {v}"); - } - if attrs.contains(&"default_value".to_string()) { - let v = attr.default_value()?; - println!(" default_value: {v:?}"); - } - if attrs.contains(&"min_value".to_string()) { - let v = attr.min_value()?; - println!(" min_value: {v:?}"); - } - if attrs.contains(&"max_value".to_string()) { - let v = attr.max_value()?; - println!(" max_value: {v}"); - } - if attrs.contains(&"possible_values".to_string()) { - let v = attr.possible_values()?; - println!(" possible_values: {v:?}"); + for cmd in cmd.free.chunks(2) { + for attr in attr.iter() { + let name = attr.name()?; + if name == cmd[0] { + attr.set_current_value(cmd[1].parse()?)?; + print_firmware_attr(attr)?; + } } } } diff --git a/rog-control-center/translations/en/rog-control-center.po b/rog-control-center/translations/en/rog-control-center.po index 4f7aac26..d051567c 100644 --- a/rog-control-center/translations/en/rog-control-center.po +++ b/rog-control-center/translations/en/rog-control-center.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2024-12-28 22:36+0000\n" +"POT-Creation-Date: 2024-12-28 22:48+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n"