diff --git a/Cargo.lock b/Cargo.lock index 28a53c01..7a4d2887 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -278,7 +278,7 @@ dependencies = [ [[package]] name = "daemon" -version = "4.3.0" +version = "4.3.1" dependencies = [ "async-trait", "env_logger", diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index f31d1100..4d391fb1 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -10,7 +10,7 @@ use anime_cli::{AnimeActions, AnimeCommand}; use profiles_cli::{FanCurveCommand, ProfileCommand}; use rog_anime::usb::get_anime_type; use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, Vec2}; -use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraPowerDev}; +use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraDevice, AuraPowerDev}; use rog_aura::{self, AuraEffect}; use rog_dbus::RogDbusClientBlocking; use rog_profiles::error::ProfileError; @@ -159,12 +159,14 @@ fn do_parsed( if let Some(cmdlist) = CliStart::command_list() { let commands: Vec = cmdlist.lines().map(|s| s.to_string()).collect(); for command in commands.iter().filter(|command| { - if supported.keyboard_led.prod_id != "1866" - && command.trim().starts_with("led-pow-1") + if !matches!( + supported.keyboard_led.prod_id, + AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866 + ) && command.trim().starts_with("led-pow-1") { return false; } - if supported.keyboard_led.prod_id != "19b6" + if supported.keyboard_led.prod_id != AuraDevice::X19B6 && command.trim().starts_with("led-pow-2") { return false; @@ -455,7 +457,10 @@ fn handle_led_power1( return Ok(()); } - if supported.prod_id != "1866" { + if !matches!( + supported.prod_id, + AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866 + ) { println!("These options are for keyboards of product ID 0x1866 only"); return Ok(()); } @@ -523,8 +528,8 @@ fn handle_led_power2( return Ok(()); } - if supported.prod_id == "1866" { - println!("This option does not apply to keyboards with product ID 0x1866") + if supported.prod_id != AuraDevice::X19B6 { + println!("This option applies only to keyboards with product ID 0x19b6") } let mut enabled: Vec = Vec::new(); diff --git a/daemon/src/ctrl_aura/controller.rs b/daemon/src/ctrl_aura/controller.rs index 510fa331..1c877c9b 100644 --- a/daemon/src/ctrl_aura/controller.rs +++ b/daemon/src/ctrl_aura/controller.rs @@ -10,7 +10,7 @@ use async_trait::async_trait; use log::{error, info, warn}; use logind_zbus::manager::ManagerProxy; use rog_aura::{ - usb::{LED_APPLY, LED_SET}, + usb::{AuraDevice, LED_APPLY, LED_SET}, AuraEffect, LedBrightness, LED_MSG_LEN, }; use rog_aura::{AuraZone, Direction, Speed, GRADIENT}; @@ -40,16 +40,16 @@ impl GetSupported for CtrlKbdLed { let multizone_led_mode = laptop.multizone; let per_key_led_mode = laptop.per_key; - let mut prod_id = String::new(); + let mut prod_id = ""; for prod in ASUS_KEYBOARD_DEVICES.iter() { if let Ok(_) = Self::find_led_node(prod) { - prod_id = prod.to_string(); + prod_id = *prod; break; } } LedSupportedFunctions { - prod_id, + prod_id: AuraDevice::from(prod_id), brightness_set: CtrlKbdLed::get_kbd_bright_path().is_some(), stock_led_modes, multizone_led_mode, diff --git a/daemon/src/ctrl_aura/zbus.rs b/daemon/src/ctrl_aura/zbus.rs index 5b2915bb..661195d1 100644 --- a/daemon/src/ctrl_aura/zbus.rs +++ b/daemon/src/ctrl_aura/zbus.rs @@ -29,8 +29,21 @@ impl CtrlKbdLedZbus { } /// Set a variety of states, input is array of enum. + /// `enabled` sets if the sent array should be disabled or enabled /// - /// enum AuraControl { + /// ```text + /// pub struct AuraPowerDev { + /// pub x1866: Vec, + /// pub x19b6: Vec, + /// } + /// pub enum AuraDev1866 { + /// Awake, + /// Keyboard, + /// Lightbar, + /// Boot, + /// Sleep, + /// } + /// enum AuraDev19b6 { /// BootLogo, /// BootKeyb, /// AwakeLogo, @@ -44,6 +57,7 @@ impl CtrlKbdLedZbus { /// SleepBar, /// ShutdownBar, /// } + /// ``` async fn set_leds_power( &mut self, #[zbus(signal_context)] ctxt: SignalContext<'_>, diff --git a/rog-aura/src/usb.rs b/rog-aura/src/usb.rs index c53be464..8d995995 100644 --- a/rog-aura/src/usb.rs +++ b/rog-aura/src/usb.rs @@ -20,6 +20,32 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] { ] } +#[cfg_attr(feature = "dbus", derive(Type))] +#[derive(Clone, Debug, PartialEq, PartialOrd, Serialize, Deserialize)] +pub enum AuraDevice { + X1854, + X1869, + X1866, + X19B6, + Unknown, +} + +impl From<&str> for AuraDevice { + fn from(s: &str) -> Self { + match s.to_lowercase().as_str() { + "1866" => AuraDevice::X1866, + "1869" => AuraDevice::X1869, + "1854" => AuraDevice::X1854, + "19b6" => AuraDevice::X19B6, + "0x1866" => AuraDevice::X1866, + "0x1869" => AuraDevice::X1869, + "0x1854" => AuraDevice::X1854, + "0x19b6" => AuraDevice::X19B6, + _ => AuraDevice::Unknown, + } + } +} + /// This struct is intended as a helper to pass args to generic dbus interface #[cfg_attr(feature = "dbus", derive(Type))] #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/rog-supported/src/lib.rs b/rog-supported/src/lib.rs index eb57e7e2..3de9241e 100644 --- a/rog-supported/src/lib.rs +++ b/rog-supported/src/lib.rs @@ -1,6 +1,6 @@ pub static VERSION: &str = env!("CARGO_PKG_VERSION"); -use rog_aura::{AuraModeNum, AuraZone}; +use rog_aura::{usb::AuraDevice, AuraModeNum, AuraZone}; use serde_derive::{Deserialize, Serialize}; use std::fmt; use zvariant_derive::Type; @@ -30,7 +30,7 @@ pub struct PlatformProfileFunctions { #[derive(Serialize, Deserialize, Type, Debug)] pub struct LedSupportedFunctions { - pub prod_id: String, + pub prod_id: AuraDevice, pub brightness_set: bool, pub stock_led_modes: Vec, pub multizone_led_mode: Vec,