Try to implement slash bar functionality - part 1

This commit is contained in:
jochen@g14
2024-03-25 01:54:05 +01:00
parent 1366422d96
commit cdc9ca7b58
33 changed files with 887 additions and 367 deletions

View File

@@ -7,6 +7,7 @@ version.workspace = true
[dependencies]
rog_anime = { path = "../rog-anime" }
rog_slash = { path = "../rog-slash" }
rog_aura = { path = "../rog-aura" }
rog_dbus = { path = "../rog-dbus" }
rog_profiles = { path = "../rog-profiles" }

View File

@@ -1,3 +1,4 @@
use std::fmt::Display;
use std::str::FromStr;
use gumdrop::Options;
@@ -87,15 +88,15 @@ impl FromStr for LedBrightness {
}
}
}
impl ToString for LedBrightness {
fn to_string(&self) -> String {
impl Display for LedBrightness {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self.level {
Some(0x00) => "low",
Some(0x01) => "med",
Some(0x02) => "high",
_ => "unknown",
};
s.to_owned()
write!(f, "{}", s.to_owned())
}
}

View File

@@ -4,6 +4,7 @@ use rog_platform::platform::ThrottlePolicy;
use crate::anime_cli::AnimeCommand;
use crate::aura_cli::{LedBrightness, LedPowerCommand1, LedPowerCommand2, SetAuraBuiltin};
use crate::fan_curve_cli::FanCurveCommand;
use crate::slash_cli::SlashCommand;
#[derive(Default, Options)]
pub struct CliStart {
@@ -41,6 +42,8 @@ pub enum CliCommand {
Graphics(GraphicsCommand),
#[options(name = "anime", help = "Manage AniMe Matrix")]
Anime(AnimeCommand),
#[options(name = "slash", help = "Manage Slash Ledbar")]
Slash(SlashCommand),
#[options(help = "Change bios settings")]
Bios(BiosCommand),
}

View File

@@ -19,14 +19,17 @@ use rog_dbus::zbus_aura::AuraProxyBlocking;
use rog_dbus::RogDbusClientBlocking;
use rog_platform::platform::{GpuMode, Properties, ThrottlePolicy};
use rog_profiles::error::ProfileError;
use rog_slash::SlashMode;
use crate::aura_cli::{AuraPowerStates, LedBrightness};
use crate::cli_opts::*;
use crate::slash_cli::{SlashCommand};
mod anime_cli;
mod aura_cli;
mod cli_opts;
mod fan_curve_cli;
mod slash_cli;
fn main() {
let args: Vec<String> = args().skip(1).collect();
@@ -149,6 +152,7 @@ fn do_parsed(
}
Some(CliCommand::Graphics(_)) => do_gfx(),
Some(CliCommand::Anime(cmd)) => handle_anime(dbus, cmd)?,
Some(CliCommand::Slash(cmd)) => handle_slash(dbus, cmd)?,
Some(CliCommand::Bios(cmd)) => handle_platform_properties(dbus, supported_properties, cmd)?,
None => {
if (!parsed.show_supported
@@ -458,6 +462,49 @@ fn verify_brightness(brightness: f32) {
}
}
fn handle_slash(
dbus: &RogDbusClientBlocking<'_>,
cmd: &SlashCommand,
) -> Result<(), Box<dyn std::error::Error>> {
if (
cmd.enable_display.is_none() &&
cmd.brightness.is_none() &&
cmd.interval.is_none() &&
!cmd.list &&
!cmd.next &&
!cmd.prev
) || cmd.help
{
println!("Missing arg or command\n\n{}", cmd.self_usage());
if let Some(lst) = cmd.self_command_list() {
println!("\n{}", lst);
}
}
if let Some(enable) = cmd.enable_display {
dbus.proxies().slash().set_enable_display(enable)?;
}
if let Some(brightness) = cmd.brightness {
dbus.proxies().slash().set_brightness(brightness)?;
}
if let Some(interval) = cmd.interval {
dbus.proxies().slash().set_interval(interval)?;
}
if cmd.next {
dbus.proxies().slash().set_current_mode(SlashMode::Bounce as u8)?;
}
if cmd.prev {
dbus.proxies().slash().set_current_mode(SlashMode::Flow as u8)?;
}
if cmd.list {
let res = SlashMode::list();
for p in &res {
println!("{:?}", p);
}
}
Ok(())
}
fn handle_led_mode(
aura: &AuraProxyBlocking,
mode: &LedModeCommand,

19
asusctl/src/slash_cli.rs Normal file
View File

@@ -0,0 +1,19 @@
use gumdrop::Options;
#[derive(Options)]
pub struct SlashCommand {
#[options(help = "print help message")]
pub help: bool,
#[options(meta = "", help = "enable/disable the display")]
pub enable_display: Option<bool>,
#[options(meta = "", help = "set brightness value <0-255>")]
pub brightness: Option<u8>,
#[options(meta = "", help = "set interval value <0-255>")]
pub interval: Option<u8>,
#[options(help = "toggle to next animation in list")]
pub next: bool,
#[options(help = "toggle to previous animation in list")]
pub prev: bool,
#[options(help = "list available animations")]
pub list: bool,
}