adds support to enable/disable side leds

This commit is contained in:
Martin Piffault
2022-05-31 17:00:21 +02:00
parent b6934bbf63
commit c6caafdcb7
8 changed files with 100 additions and 1 deletions

View File

@@ -59,6 +59,11 @@ pub struct LedModeCommand {
help = "set the keyboard LED suspend animation to enabled while the device is suspended" help = "set the keyboard LED suspend animation to enabled while the device is suspended"
)] )]
pub sleep_enable: Option<bool>, pub sleep_enable: Option<bool>,
#[options(
meta = "",
help = "set the keyboard side LEDs to enabled"
)]
pub side_leds_enable: Option<bool>,
#[options(command)] #[options(command)]
pub command: Option<SetAuraBuiltin>, pub command: Option<SetAuraBuiltin>,
} }

View File

@@ -344,6 +344,7 @@ fn handle_led_mode(
&& !mode.next_mode && !mode.next_mode
&& mode.sleep_enable.is_none() && mode.sleep_enable.is_none()
&& mode.awake_enable.is_none() && mode.awake_enable.is_none()
&& mode.side_leds_enable.is_none()
{ {
if !mode.help { if !mode.help {
println!("Missing arg or command\n"); println!("Missing arg or command\n");
@@ -407,6 +408,10 @@ fn handle_led_mode(
dbus.proxies().led().set_sleep_enabled(enable)?; dbus.proxies().led().set_sleep_enabled(enable)?;
} }
if let Some(enable) = mode.side_leds_enable {
dbus.proxies().led().set_side_leds_enabled(enable)?;
}
Ok(()) Ok(())
} }

View File

@@ -25,6 +25,7 @@ impl AuraConfigV320 {
multizone: self.multizone, multizone: self.multizone,
awake_enabled: true, awake_enabled: true,
sleep_anim_enabled: true, sleep_anim_enabled: true,
side_leds_enabled:true,
} }
} }
} }
@@ -46,6 +47,7 @@ impl AuraConfigV352 {
multizone: self.multizone, multizone: self.multizone,
awake_enabled: true, awake_enabled: true,
sleep_anim_enabled: true, sleep_anim_enabled: true,
side_leds_enabled:true,
} }
} }
} }
@@ -58,6 +60,7 @@ pub struct AuraConfig {
pub multizone: Option<AuraMultiZone>, pub multizone: Option<AuraMultiZone>,
pub awake_enabled: bool, pub awake_enabled: bool,
pub sleep_anim_enabled: bool, pub sleep_anim_enabled: bool,
pub side_leds_enabled: bool,
} }
impl Default for AuraConfig { impl Default for AuraConfig {
@@ -69,6 +72,7 @@ impl Default for AuraConfig {
multizone: None, multizone: None,
awake_enabled: true, awake_enabled: true,
sleep_anim_enabled: true, sleep_anim_enabled: true,
side_leds_enabled:true,
} }
} }
} }

View File

@@ -11,7 +11,7 @@ use logind_zbus::ManagerProxy;
use rog_aura::{ use rog_aura::{
usb::{ usb::{
LED_APPLY, LED_AWAKE_OFF_SLEEP_OFF, LED_AWAKE_OFF_SLEEP_ON, LED_AWAKE_ON_SLEEP_OFF, 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, 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) ctrl.set_states_enabled(ctrl.config.awake_enabled, ctrl.config.sleep_anim_enabled)
.map_err(|err| warn!("{}", err)) .map_err(|err| warn!("{}", err))
.ok(); .ok();
ctrl.set_side_leds_states(ctrl.config.side_leds_enabled)
.map_err(|err| warn!("{}", err))
.ok();
} }
Ok(()) Ok(())
} }
@@ -283,6 +287,19 @@ impl CtrlKbdLed {
Ok(()) 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<String, RogError> { fn find_led_node(id_product: &str) -> Result<String, RogError> {
let mut enumerator = udev::Enumerator::new().map_err(|err| { let mut enumerator = udev::Enumerator::new().map_err(|err| {
warn!("{}", err); warn!("{}", err);

View File

@@ -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) { fn set_led_mode(&mut self, effect: AuraEffect) {
if let Ok(mut ctrl) = self.0.try_lock() { if let Ok(mut ctrl) = self.0.try_lock() {
match ctrl.do_command(effect) { match ctrl.do_command(effect) {
@@ -135,6 +148,14 @@ impl CtrlKbdLedZbus {
true 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 /// Return the current mode data
#[dbus_interface(property)] #[dbus_interface(property)]
fn led_mode(&self) -> String { fn led_mode(&self) -> String {
@@ -174,6 +195,9 @@ impl CtrlKbdLedZbus {
#[dbus_interface(signal)] #[dbus_interface(signal)]
fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>; fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>;
#[dbus_interface(signal)]
fn notify_side_leds(&self, data: bool) -> zbus::Result<()>;
#[dbus_interface(signal)] #[dbus_interface(signal)]
fn notify_power_states(&self, data: &LedPowerStates) -> zbus::Result<()>; fn notify_power_states(&self, data: &LedPowerStates) -> zbus::Result<()>;
} }

View File

@@ -30,3 +30,11 @@ pub const LED_AWAKE_OFF_SLEEP_OFF: [u8; 17] = [
pub const LED_AWAKE_OFF_SLEEP_ON: [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, 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,
];

View File

@@ -83,6 +83,7 @@ impl<'a> DbusProxies<'a> {
pub struct Signals { pub struct Signals {
pub profile: Receiver<Profile>, pub profile: Receiver<Profile>,
pub led_mode: Receiver<AuraEffect>, pub led_mode: Receiver<AuraEffect>,
pub side_leds: Receiver<bool>,
pub led_power_state: Receiver<LedPowerStates>, pub led_power_state: Receiver<LedPowerStates>,
pub anime_power_state: Receiver<AnimePowerStates>, pub anime_power_state: Receiver<AnimePowerStates>,
pub charge: Receiver<u8>, pub charge: Receiver<u8>,
@@ -109,6 +110,11 @@ impl Signals {
proxies.led.connect_notify_led(tx)?; proxies.led.connect_notify_led(tx)?;
rx rx
}, },
side_leds: {
let (tx, rx) = channel();
proxies.led.connect_notify_side_leds(tx)?;
rx
},
led_power_state: { led_power_state: {
let (tx, rx) = channel(); let (tx, rx) = channel();
proxies.led.connect_notify_power_states(tx)?; proxies.led.connect_notify_power_states(tx)?;

View File

@@ -56,10 +56,16 @@ trait Daemon {
/// SetSleepEnabled method /// SetSleepEnabled method
fn set_sleep_enabled(&self, enabled: bool) -> zbus::Result<()>; fn set_sleep_enabled(&self, enabled: bool) -> zbus::Result<()>;
/// SetSideLedsEnabled method
fn set_side_leds_enabled(&self, enabled: bool) -> Result<()>;
/// NotifyLed signal /// NotifyLed signal
#[dbus_proxy(signal)] #[dbus_proxy(signal)]
fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>; fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>;
#[dbus_proxy(signal)]
fn notify_side_leds(&self, data: bool) -> zbus::Result<()>;
#[dbus_proxy(signal)] #[dbus_proxy(signal)]
fn notify_power_states(&self, data: LedPowerStates) -> zbus::Result<()>; fn notify_power_states(&self, data: LedPowerStates) -> zbus::Result<()>;
@@ -80,6 +86,9 @@ trait Daemon {
#[dbus_proxy(property)] #[dbus_proxy(property)]
fn sleep_enabled(&self) -> zbus::Result<bool>; fn sleep_enabled(&self) -> zbus::Result<bool>;
#[dbus_proxy(property)]
fn side_leds_enabled(&self) -> zbus::Result<bool>;
} }
pub struct LedProxy<'a>(DaemonProxy<'a>); pub struct LedProxy<'a>(DaemonProxy<'a>);
@@ -120,6 +129,13 @@ impl<'a> LedProxy<'a> {
Ok(()) 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] #[inline]
pub fn next_led_mode(&self) -> Result<()> { pub fn next_led_mode(&self) -> Result<()> {
self.0.next_led_mode() self.0.next_led_mode()
@@ -155,6 +171,11 @@ impl<'a> LedProxy<'a> {
self.0.sleep_enabled() self.0.sleep_enabled()
} }
#[inline]
pub fn side_leds_enabled(&self) -> Result<bool> {
self.0.side_leds_enabled()
}
/// Write a single colour block. /// Write a single colour block.
/// ///
/// Intentionally blocks for 10ms after sending to allow the block to /// 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<bool>) -> 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] #[inline]
pub fn connect_notify_power_states( pub fn connect_notify_power_states(
&self, &self,