diff --git a/asusctl/src/cli_opts.rs b/asusctl/src/cli_opts.rs index bfb2089c..dabe37de 100644 --- a/asusctl/src/cli_opts.rs +++ b/asusctl/src/cli_opts.rs @@ -59,6 +59,11 @@ pub struct LedModeCommand { help = "set the keyboard LED suspend animation to enabled while the device is suspended" )] pub sleep_enable: Option, + #[options( + meta = "", + help = "set the keyboard side LEDs to enabled" + )] + pub side_leds_enable: Option, #[options(command)] pub command: Option, } diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 0e8716af..b0ab38d7 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -344,6 +344,7 @@ fn handle_led_mode( && !mode.next_mode && mode.sleep_enable.is_none() && mode.awake_enable.is_none() + && mode.side_leds_enable.is_none() { if !mode.help { println!("Missing arg or command\n"); @@ -407,6 +408,10 @@ fn handle_led_mode( dbus.proxies().led().set_sleep_enabled(enable)?; } + if let Some(enable) = mode.side_leds_enable { + dbus.proxies().led().set_side_leds_enabled(enable)?; + } + Ok(()) } diff --git a/daemon/src/ctrl_aura/config.rs b/daemon/src/ctrl_aura/config.rs index 7087d601..f4b811c8 100644 --- a/daemon/src/ctrl_aura/config.rs +++ b/daemon/src/ctrl_aura/config.rs @@ -25,6 +25,7 @@ impl AuraConfigV320 { multizone: self.multizone, awake_enabled: true, sleep_anim_enabled: true, + side_leds_enabled:true, } } } @@ -46,6 +47,7 @@ impl AuraConfigV352 { multizone: self.multizone, awake_enabled: true, sleep_anim_enabled: true, + side_leds_enabled:true, } } } @@ -58,6 +60,7 @@ pub struct AuraConfig { pub multizone: Option, pub awake_enabled: bool, pub sleep_anim_enabled: bool, + pub side_leds_enabled: bool, } impl Default for AuraConfig { @@ -69,6 +72,7 @@ impl Default for AuraConfig { multizone: None, awake_enabled: true, sleep_anim_enabled: true, + side_leds_enabled:true, } } } diff --git a/daemon/src/ctrl_aura/controller.rs b/daemon/src/ctrl_aura/controller.rs index e08a996f..e9c3ea91 100644 --- a/daemon/src/ctrl_aura/controller.rs +++ b/daemon/src/ctrl_aura/controller.rs @@ -11,7 +11,7 @@ use logind_zbus::ManagerProxy; use rog_aura::{ usb::{ LED_APPLY, LED_AWAKE_OFF_SLEEP_OFF, LED_AWAKE_OFF_SLEEP_ON, LED_AWAKE_ON_SLEEP_OFF, - LED_AWAKE_ON_SLEEP_ON, LED_SET, + LED_AWAKE_ON_SLEEP_ON, LED_SET, SIDE_LEDS_OFF, SIDE_LEDS_ON, }, AuraEffect, LedBrightness, LED_MSG_LEN, }; @@ -148,6 +148,10 @@ impl crate::Reloadable for CtrlKbdLedReloader { ctrl.set_states_enabled(ctrl.config.awake_enabled, ctrl.config.sleep_anim_enabled) .map_err(|err| warn!("{}", err)) .ok(); + + ctrl.set_side_leds_states(ctrl.config.side_leds_enabled) + .map_err(|err| warn!("{}", err)) + .ok(); } Ok(()) } @@ -283,6 +287,19 @@ impl CtrlKbdLed { Ok(()) } + pub(super) fn set_side_leds_states(&self, activated: bool) -> Result<(), RogError> { + let bytes: [u8; LED_MSG_LEN] = if activated { + SIDE_LEDS_ON + } else { + SIDE_LEDS_OFF + }; + self.write_bytes(&bytes)?; + self.write_bytes(&LED_SET)?; + // Changes won't persist unless apply is set + self.write_bytes(&LED_APPLY)?; + Ok(()) + } + fn find_led_node(id_product: &str) -> Result { let mut enumerator = udev::Enumerator::new().map_err(|err| { warn!("{}", err); diff --git a/daemon/src/ctrl_aura/zbus.rs b/daemon/src/ctrl_aura/zbus.rs index eeab2619..3903c90b 100644 --- a/daemon/src/ctrl_aura/zbus.rs +++ b/daemon/src/ctrl_aura/zbus.rs @@ -65,6 +65,19 @@ impl CtrlKbdLedZbus { } } + /// Set the keyboard side LEDs to enabled + fn set_side_leds_enabled(&mut self, enabled: bool) { + if let Ok(mut ctrl) = self.0.try_lock() { + ctrl.set_side_leds_states(enabled) + .map_err(|err| warn!("{}", err)) + .ok(); + ctrl.config.side_leds_enabled = enabled; + ctrl.config.write(); + self.notify_side_leds(ctrl.config.side_leds_enabled) + .unwrap_or_else(|err| warn!("{}", err)) + } + } + fn set_led_mode(&mut self, effect: AuraEffect) { if let Ok(mut ctrl) = self.0.try_lock() { match ctrl.do_command(effect) { @@ -135,6 +148,14 @@ impl CtrlKbdLedZbus { true } + #[dbus_interface(property)] + fn side_leds_enabled(&self) -> bool { + if let Ok(ctrl) = self.0.try_lock() { + return ctrl.config.side_leds_enabled; + } + true + } + /// Return the current mode data #[dbus_interface(property)] fn led_mode(&self) -> String { @@ -174,6 +195,9 @@ impl CtrlKbdLedZbus { #[dbus_interface(signal)] fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>; + #[dbus_interface(signal)] + fn notify_side_leds(&self, data: bool) -> zbus::Result<()>; + #[dbus_interface(signal)] fn notify_power_states(&self, data: &LedPowerStates) -> zbus::Result<()>; } diff --git a/rog-aura/src/usb.rs b/rog-aura/src/usb.rs index 257809df..6b3065cc 100644 --- a/rog-aura/src/usb.rs +++ b/rog-aura/src/usb.rs @@ -30,3 +30,11 @@ pub const LED_AWAKE_OFF_SLEEP_OFF: [u8; 17] = [ pub const LED_AWAKE_OFF_SLEEP_ON: [u8; 17] = [ 0x5d, 0xbd, 0x01, 0xf3, 0x1b, 0x0d, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; + +pub const SIDE_LEDS_OFF: [u8; 17] = [ + 0x5d, 0xbd, 0x01, 0x08, 0x00, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +]; + +pub const SIDE_LEDS_ON: [u8; 17] = [ + 0x5d, 0xbd, 0x01, 0x0c, 0x05, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +]; diff --git a/rog-dbus/src/lib.rs b/rog-dbus/src/lib.rs index f5456af7..48aa54f2 100644 --- a/rog-dbus/src/lib.rs +++ b/rog-dbus/src/lib.rs @@ -83,6 +83,7 @@ impl<'a> DbusProxies<'a> { pub struct Signals { pub profile: Receiver, pub led_mode: Receiver, + pub side_leds: Receiver, pub led_power_state: Receiver, pub anime_power_state: Receiver, pub charge: Receiver, @@ -109,6 +110,11 @@ impl Signals { proxies.led.connect_notify_led(tx)?; rx }, + side_leds: { + let (tx, rx) = channel(); + proxies.led.connect_notify_side_leds(tx)?; + rx + }, led_power_state: { let (tx, rx) = channel(); proxies.led.connect_notify_power_states(tx)?; diff --git a/rog-dbus/src/zbus_led.rs b/rog-dbus/src/zbus_led.rs index 5440961f..a01547d6 100644 --- a/rog-dbus/src/zbus_led.rs +++ b/rog-dbus/src/zbus_led.rs @@ -56,10 +56,16 @@ trait Daemon { /// SetSleepEnabled method fn set_sleep_enabled(&self, enabled: bool) -> zbus::Result<()>; + /// SetSideLedsEnabled method + fn set_side_leds_enabled(&self, enabled: bool) -> Result<()>; + /// NotifyLed signal #[dbus_proxy(signal)] fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>; + #[dbus_proxy(signal)] + fn notify_side_leds(&self, data: bool) -> zbus::Result<()>; + #[dbus_proxy(signal)] fn notify_power_states(&self, data: LedPowerStates) -> zbus::Result<()>; @@ -80,6 +86,9 @@ trait Daemon { #[dbus_proxy(property)] fn sleep_enabled(&self) -> zbus::Result; + + #[dbus_proxy(property)] + fn side_leds_enabled(&self) -> zbus::Result; } pub struct LedProxy<'a>(DaemonProxy<'a>); @@ -120,6 +129,13 @@ impl<'a> LedProxy<'a> { Ok(()) } + /// Set the keyboard side LEDs to enabled + #[inline] + pub fn set_side_leds_enabled(&self, enabled: bool) -> Result<()> { + self.0.set_side_leds_enabled(enabled)?; + Ok(()) + } + #[inline] pub fn next_led_mode(&self) -> Result<()> { self.0.next_led_mode() @@ -155,6 +171,11 @@ impl<'a> LedProxy<'a> { self.0.sleep_enabled() } + #[inline] + pub fn side_leds_enabled(&self) -> Result { + self.0.side_leds_enabled() + } + /// Write a single colour block. /// /// Intentionally blocks for 10ms after sending to allow the block to @@ -196,6 +217,15 @@ impl<'a> LedProxy<'a> { }) } + #[inline] + pub fn connect_notify_side_leds(&self, send: Sender) -> zbus::fdo::Result<()> { + self.0.connect_notify_side_leds(move |data| { + send.send(data) + .map_err(|err| zbus::fdo::Error::Failed(err.to_string()))?; + Ok(()) + }) + } + #[inline] pub fn connect_notify_power_states( &self,