Additional dbus methods

This commit is contained in:
Luke
2020-07-01 10:40:19 +12:00
parent a731361278
commit cff0af76c8
9 changed files with 138 additions and 61 deletions

View File

@@ -14,6 +14,7 @@ pub const RIPPLE: u8 = 0x08;
pub const PULSE: u8 = 0x0a;
pub const COMET: u8 = 0x0b;
pub const FLASH: u8 = 0x0c;
pub const MULTISTATIC: u8 = 0x0d;
#[derive(Clone, Default, Deserialize, Serialize)]
pub struct Colour(pub u8, pub u8, pub u8);
@@ -226,7 +227,7 @@ impl From<&AuraModes> for u8 {
AuraModes::Pulse(_) => PULSE,
AuraModes::Comet(_) => COMET,
AuraModes::Flash(_) => FLASH,
AuraModes::MultiStatic(_) => 0x0d,
AuraModes::MultiStatic(_) => MULTISTATIC,
_ => panic!("Invalid mode"),
}
}
@@ -248,6 +249,7 @@ impl From<u8> for AuraModes {
PULSE => AuraModes::Pulse(SingleColour::default()),
COMET => AuraModes::Comet(SingleColour::default()),
FLASH => AuraModes::Flash(SingleColour::default()),
MULTISTATIC => AuraModes::MultiStatic(MultiColour::default()),
_ => panic!("Invalid mode byte"),
}
}

View File

@@ -26,10 +26,8 @@ impl AuraDbusWriter {
let stopper2 = stop.clone();
let match_rule = dbus::message::MatchRule::new_signal(DBUS_IFACE, "KeyBacklightChanged");
let stop_token = connection.add_match(match_rule, move |_: (), _, msg| {
if let Ok(stop) = msg.read1::<bool>() {
if stop {
stopper2.store(true, Ordering::Relaxed);
}
if msg.read1::<&str>().is_ok() {
stopper2.store(true, Ordering::Relaxed);
}
true
})?;

View File

@@ -210,6 +210,13 @@ impl From<AuraModes> for [u8; LED_MSG_LEN] {
impl From<AuraModes> for [[u8; LED_MSG_LEN]; 4] {
#[inline]
fn from(mode: AuraModes) -> Self {
<[[u8; LED_MSG_LEN]; 4]>::from(&mode)
}
}
impl From<&AuraModes> for [[u8; LED_MSG_LEN]; 4] {
#[inline]
fn from(mode: &AuraModes) -> Self {
let mut msg = [[0u8; LED_MSG_LEN]; 4];
for (i, row) in msg.iter_mut().enumerate() {
row[0] = 0x5d;