From bf6bf2e2f16787912e7a3c04edbaad44146a2dc5 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 1 May 2020 22:07:28 +1200 Subject: [PATCH] Big refactor out of Aura LED data structs --- Cargo.lock | 21 +- Cargo.toml | 49 +- Makefile | 2 +- aura/Cargo.toml | 17 + .../examples}/per-key-effect-2.rs | 2 +- aura/src/aura_dbus.rs | 81 ++ aura/src/builtins.rs | 166 +++ {src => aura/src}/cli_options.rs | 0 {src => aura/src}/error.rs | 6 - aura/src/fancy.rs | 265 +++++ aura/src/lib.rs | 233 ++++ rog-core/Cargo.lock | 1016 +++++++++++++++++ rog-core/Cargo.toml | 45 + {src => rog-core/src}/config.rs | 2 +- {src => rog-core/src}/core.rs | 24 +- {src => rog-core/src}/daemon.rs | 6 +- {src => rog-core/src}/laptops/mod.rs | 3 +- {src => rog-core/src}/lib.rs | 4 - {src => rog-core/src}/main.rs | 8 +- {src => rog-core/src}/virt_device.rs | 0 src/aura.rs | 714 ------------ wireshark_data/rog-star-colour.pcapng | Bin 0 -> 2736 bytes wireshark_data/rog-star-random.pcapng | Bin 0 -> 2736 bytes 23 files changed, 1862 insertions(+), 802 deletions(-) create mode 100644 aura/Cargo.toml rename {examples => aura/examples}/per-key-effect-2.rs (95%) create mode 100644 aura/src/aura_dbus.rs create mode 100644 aura/src/builtins.rs rename {src => aura/src}/cli_options.rs (100%) rename {src => aura/src}/error.rs (73%) create mode 100644 aura/src/fancy.rs create mode 100644 aura/src/lib.rs create mode 100644 rog-core/Cargo.lock create mode 100644 rog-core/Cargo.toml rename {src => rog-core/src}/config.rs (98%) rename {src => rog-core/src}/core.rs (97%) rename {src => rog-core/src}/daemon.rs (97%) rename {src => rog-core/src}/laptops/mod.rs (99%) rename {src => rog-core/src}/lib.rs (61%) rename {src => rog-core/src}/main.rs (93%) rename {src => rog-core/src}/virt_device.rs (100%) delete mode 100644 src/aura.rs create mode 100755 wireshark_data/rog-star-colour.pcapng create mode 100755 wireshark_data/rog-star-random.pcapng diff --git a/Cargo.lock b/Cargo.lock index 6de19ede..01aa9050 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -628,9 +628,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +checksum = "4c1f4b0efa5fc5e8ceb705136bfee52cfdb6a4e3509f770b478cd6ed434232a7" dependencies = [ "proc-macro2", ] @@ -665,6 +665,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" +[[package]] +name = "rog-aura" +version = "0.8.0" +dependencies = [ + "dbus", + "gumdrop", + "serde", + "serde_derive", + "thiserror", +] + [[package]] name = "rog-daemon" version = "0.8.0" @@ -675,10 +686,10 @@ dependencies = [ "gumdrop", "intel-pstate", "log", + "rog-aura", "rusb", "serde", "serde_derive", - "thiserror", "tokio", "toml", "uhid-virt", @@ -859,9 +870,9 @@ dependencies = [ [[package]] name = "tokio" -version = "0.2.19" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d9c43f1bb96970e153bcbae39a65e249ccb942bd9d36dbdf086024920417c9c" +checksum = "05c1d570eb1a36f0345a5ce9c6c6e665b70b73d11236912c0b477616aeec47b1" dependencies = [ "bytes", "fnv", diff --git a/Cargo.toml b/Cargo.toml index 1b4a82f9..37e93e63 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,50 +1,5 @@ -[package] -name = "rog-daemon" -version = "0.8.0" -license = "MPL-2.0" -readme = "README.md" -authors = ["Luke "] -repository = "https://github.com/flukejones/rog-core" -homepage = "https://github.com/flukejones/rog-core" -description = "A daemon app for ASUS GX502 and similar laptops to control missing features" -edition = "2018" - -[lib] -name = "daemon" -path = "src/lib.rs" - -[[bin]] -name = "rog-core" -path = "src/main.rs" - -[dependencies] -rusb = "^0.5.5" - -# cli and logging -gumdrop = "^0.8.0" -log = "^0.4.8" -env_logger = "^0.7.1" - -# async -dbus = { version = "^0.8.2", features = ["futures"] } -dbus-tokio = "^0.5.1" -tokio = { version = "0.2.4", features = ["rt-threaded", "macros", "sync"] } - -# serialisation -serde = "1.0" -serde_derive = "1.0" -toml = "0.5" - -# Device control -# sysfs-class = "^0.1.2" # used for backlight control mostly -# cpu power management -intel-pstate = "^0.2.1" -# virtualisation of HID, mainly for outputting consumer key codes -uhid-virt = "^0.0.4" -#keycode = "0.3" - -# -thiserror = "^1.0.15" +[workspace] +members = ["rog-core", "aura"] [profile.release] lto = true diff --git a/Makefile b/Makefile index 09e98b8d..ecf8b03f 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ includedir = $(prefix)/include datarootdir = $(prefix)/share datadir = $(datarootdir) -SRC = Cargo.toml Cargo.lock Makefile $(shell find -type f -wholename '*/src/*.rs') +SRC = Cargo.toml Cargo.lock Makefile $(shell find -type f -wholename '**/src/*.rs') .PHONY: all clean distclean install uninstall update diff --git a/aura/Cargo.toml b/aura/Cargo.toml new file mode 100644 index 00000000..56af6f74 --- /dev/null +++ b/aura/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "rog-aura" +version = "0.8.0" +license = "MPL-2.0" +readme = "README.md" +authors = ["Luke "] +repository = "https://github.com/flukejones/rog-core" +homepage = "https://github.com/flukejones/rog-core" +description = "A small library of effect types and conversions for ROG Aura" +edition = "2018" + +[dependencies] +gumdrop = "^0.8.0" +dbus = { version = "^0.8.2" } +serde = "1.0" +serde_derive = "1.0" +thiserror = "^1.0.15" diff --git a/examples/per-key-effect-2.rs b/aura/examples/per-key-effect-2.rs similarity index 95% rename from examples/per-key-effect-2.rs rename to aura/examples/per-key-effect-2.rs index c5e3f4fc..060cd50e 100644 --- a/examples/per-key-effect-2.rs +++ b/aura/examples/per-key-effect-2.rs @@ -1,4 +1,4 @@ -use daemon::aura::{AuraDbusWriter, Key, KeyColourArray}; +use rog_aura::{AuraDbusWriter, Key, KeyColourArray}; fn main() -> Result<(), Box> { let writer = AuraDbusWriter::new()?; diff --git a/aura/src/aura_dbus.rs b/aura/src/aura_dbus.rs new file mode 100644 index 00000000..b1dadea1 --- /dev/null +++ b/aura/src/aura_dbus.rs @@ -0,0 +1,81 @@ +use super::*; +use dbus::{ffidisp::Connection, Message}; +use std::error::Error; +use std::{thread, time::Duration}; + +/// Simplified way to write a effect block +pub struct AuraDbusWriter { + connection: Connection, + block_time: u64, +} + +impl AuraDbusWriter { + #[inline] + pub fn new() -> Result> { + Ok(AuraDbusWriter { + connection: Connection::new_system()?, + block_time: 10, + }) + } + + /// This method must always be called before the very first write to initialise + /// the keyboard LED EC in the correct mode + #[inline] + pub fn init_effect(&self) -> Result<(), Box> { + let msg = Message::new_method_call(DBUS_NAME, DBUS_PATH, DBUS_IFACE, "ledmessage")? + .append1(KeyColourArray::get_init_msg()); + self.connection.send(msg).unwrap(); + Ok(()) + } + + /// Write a single colour block. + /// + /// Intentionally blocks for 10ms after sending to allow the block to + /// be written to the keyboard EC. This should not be async. + #[inline] + pub fn write_colour_block( + &self, + key_colour_array: &KeyColourArray, + ) -> Result<(), Box> { + let group = key_colour_array.get(); + let msg = Message::new_method_call(DBUS_NAME, DBUS_PATH, DBUS_IFACE, "ledeffect")? + .append1(&group[0].to_vec()) + .append1(&group[1].to_vec()) + .append1(&group[2].to_vec()) + .append1(&group[3].to_vec()) + .append1(&group[4].to_vec()) + .append1(&group[5].to_vec()) + .append1(&group[6].to_vec()) + .append1(&group[7].to_vec()) + .append1(&group[8].to_vec()) + .append1(&group[9].to_vec()); + self.connection.send(msg).unwrap(); + thread::sleep(Duration::from_millis(self.block_time)); + Ok(()) + } + + #[inline] + pub fn write_bytes(&self, bytes: &[u8]) -> Result> { + let msg = Message::new_method_call(DBUS_NAME, DBUS_PATH, DBUS_IFACE, "ledmessage")? + .append1(bytes.to_vec()); + let r = self.connection.send_with_reply_and_block(msg, 5000)?; + if let Some(reply) = r.get1::<&str>() { + return Ok(reply.to_owned()); + } + Err(Box::new(dbus::Error::new_custom("name", "message"))) + } + + #[inline] + pub fn write_builtin_mode( + &self, + mode: &SetAuraBuiltin, + ) -> Result> { + let bytes = <[u8; LED_MSG_LEN]>::from(mode); + self.write_bytes(&bytes) + } + + #[inline] + pub fn write_brightness(&self, level: u8) -> Result> { + self.write_bytes(&aura_brightness_bytes(level)) + } +} diff --git a/aura/src/builtins.rs b/aura/src/builtins.rs new file mode 100644 index 00000000..0d6ab79b --- /dev/null +++ b/aura/src/builtins.rs @@ -0,0 +1,166 @@ +use super::cli_options::*; +use super::LED_MSG_LEN; +use serde_derive::{Deserialize, Serialize}; + +/// Container for the byte strings used in modes. Generally useful for settings +/// and other usecases. +#[derive(Deserialize, Serialize)] +pub struct BuiltInModeBytes { + pub stable: [u8; LED_MSG_LEN], + pub breathe: [u8; LED_MSG_LEN], + pub cycle: [u8; LED_MSG_LEN], + pub rainbow: [u8; LED_MSG_LEN], + pub rain: [u8; LED_MSG_LEN], + pub random: [u8; LED_MSG_LEN], + pub highlight: [u8; LED_MSG_LEN], + pub laser: [u8; LED_MSG_LEN], + pub ripple: [u8; LED_MSG_LEN], + pub pulse: [u8; LED_MSG_LEN], + pub thinzoomy: [u8; LED_MSG_LEN], + pub widezoomy: [u8; LED_MSG_LEN], + pub multi_static: [[u8; LED_MSG_LEN]; 4], +} +impl BuiltInModeBytes { + #[inline] + pub fn set_field_from(&mut self, bytes: &[u8]) { + if bytes[0] == 0x5d && bytes[1] == 0xb3 { + let b = BuiltInModeByte::from(bytes[3]); + match b { + BuiltInModeByte::Single => self.stable.copy_from_slice(bytes), + BuiltInModeByte::Breathing => self.breathe.copy_from_slice(bytes), + BuiltInModeByte::Cycle => self.cycle.copy_from_slice(bytes), + BuiltInModeByte::Rainbow => self.rainbow.copy_from_slice(bytes), + BuiltInModeByte::Rain => self.rain.copy_from_slice(bytes), + BuiltInModeByte::Random => self.random.copy_from_slice(bytes), + BuiltInModeByte::Highlight => self.highlight.copy_from_slice(bytes), + BuiltInModeByte::Laser => self.laser.copy_from_slice(bytes), + BuiltInModeByte::Ripple => self.ripple.copy_from_slice(bytes), + BuiltInModeByte::Pulse => self.pulse.copy_from_slice(bytes), + BuiltInModeByte::ThinZoomy => self.thinzoomy.copy_from_slice(bytes), + BuiltInModeByte::WideZoomy => self.widezoomy.copy_from_slice(bytes), + _ => {} + } + } + } + + #[inline] + pub fn get_field_from(&mut self, byte: u8) -> Option<&[u8]> { + let bytes = match BuiltInModeByte::from(byte) { + BuiltInModeByte::Single => &self.stable, + BuiltInModeByte::Breathing => &self.breathe, + BuiltInModeByte::Cycle => &self.cycle, + BuiltInModeByte::Rainbow => &self.rainbow, + BuiltInModeByte::Rain => &self.rain, + BuiltInModeByte::Random => &self.random, + BuiltInModeByte::Highlight => &self.highlight, + BuiltInModeByte::Laser => &self.laser, + BuiltInModeByte::Ripple => &self.ripple, + BuiltInModeByte::Pulse => &self.pulse, + BuiltInModeByte::ThinZoomy => &self.thinzoomy, + BuiltInModeByte::WideZoomy => &self.widezoomy, + _ => return None, + }; + return Some(bytes); + } +} +impl Default for BuiltInModeBytes { + fn default() -> Self { + BuiltInModeBytes { + stable: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Stable(SingleColour::default())), + breathe: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Breathe(TwoColourSpeed::default())), + cycle: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Cycle(SingleSpeed::default())), + rainbow: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Rainbow( + SingleSpeedDirection::default(), + )), + rain: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Rain(TwoColourSpeed::default())), + random: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Disco(SingleSpeed::default())), + highlight: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Highlight( + SingleColourSpeed::default(), + )), + laser: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Laser(SingleColourSpeed::default())), + ripple: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Ripple(SingleColourSpeed::default())), + pulse: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Pulse(SingleColour::default())), + thinzoomy: <[u8; LED_MSG_LEN]>::from( + SetAuraBuiltin::ThinZoomy(SingleColour::default()), + ), + widezoomy: <[u8; LED_MSG_LEN]>::from( + SetAuraBuiltin::WideZoomy(SingleColour::default()), + ), + multi_static: <[[u8; LED_MSG_LEN]; 4]>::from(SetAuraBuiltin::MultiStatic( + MultiColour::default(), + )), + } + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] +pub enum BuiltInModeByte { + Single = 0x00, + Breathing = 0x01, + Cycle = 0x02, + Rainbow = 0x03, + Rain = 0x04, + Random = 0x05, + Highlight = 0x06, + Laser = 0x07, + Ripple = 0x08, + Pulse = 0x0a, + ThinZoomy = 0x0b, + WideZoomy = 0x0c, + None, +} +impl Default for BuiltInModeByte { + #[inline] + fn default() -> Self { + BuiltInModeByte::Single + } +} + +impl From for BuiltInModeByte { + #[inline] + fn from(byte: u8) -> Self { + match byte { + 0x00 => Self::Single, + 0x01 => Self::Breathing, + 0x02 => Self::Cycle, + 0x03 => Self::Rainbow, + 0x04 => Self::Rain, + 0x05 => Self::Random, + 0x06 => Self::Highlight, + 0x07 => Self::Laser, + 0x08 => Self::Ripple, + 0x0a => Self::Pulse, + 0x0b => Self::ThinZoomy, + 0x0c => Self::WideZoomy, + _ => Self::None, + } + } +} + +impl From<&u8> for BuiltInModeByte { + #[inline] + fn from(byte: &u8) -> Self { + Self::from(*byte) + } +} + +impl From for u8 { + #[inline] + fn from(byte: BuiltInModeByte) -> Self { + match byte { + BuiltInModeByte::Single => 0x00, + BuiltInModeByte::Breathing => 0x01, + BuiltInModeByte::Cycle => 0x02, + BuiltInModeByte::Rainbow => 0x03, + BuiltInModeByte::Rain => 0x04, + BuiltInModeByte::Random => 0x05, + BuiltInModeByte::Highlight => 0x06, + BuiltInModeByte::Laser => 0x07, + BuiltInModeByte::Ripple => 0x08, + BuiltInModeByte::Pulse => 0x0a, + BuiltInModeByte::ThinZoomy => 0x0b, + BuiltInModeByte::WideZoomy => 0x0c, + BuiltInModeByte::None => 0xff, + } + } +} diff --git a/src/cli_options.rs b/aura/src/cli_options.rs similarity index 100% rename from src/cli_options.rs rename to aura/src/cli_options.rs diff --git a/src/error.rs b/aura/src/error.rs similarity index 73% rename from src/error.rs rename to aura/src/error.rs index 3ccc0a79..2fd89237 100644 --- a/src/error.rs +++ b/aura/src/error.rs @@ -15,10 +15,4 @@ pub enum AuraError { PollKeyboard, #[error("mode not supported")] NotSupported, - #[error("USB error")] - UsbError(rusb::Error), - #[error("IO error")] - IOError(#[from] std::io::Error), - #[error("external command failed")] - CommandFailed, } diff --git a/aura/src/fancy.rs b/aura/src/fancy.rs new file mode 100644 index 00000000..af516991 --- /dev/null +++ b/aura/src/fancy.rs @@ -0,0 +1,265 @@ +#[derive(Clone)] +pub struct KeyColourArray([[u8; 64]; 10]); +impl KeyColourArray { + pub fn new() -> Self { + let mut set = [[0u8; 64]; 10]; + for (count, row) in set.iter_mut().enumerate() { + row[0] = 0x5d; // Report ID + row[1] = 0xbc; // Mode = custom??, 0xb3 is builtin + row[2] = 0x00; + row[3] = 0x01; // ?? + row[4] = 0x01; // ??, 4,5,6 are normally RGB for builtin mode colours + row[5] = 0x01; // ?? + row[6] = (count as u8) << 4; // Key group + row[7] = 0x10; // 0b00010000 addressing? flips for group a0 + if count == 9 { + row[7] = 0x08; // 0b00001000 + } + row[8] = 0x00; + } + KeyColourArray(set) + } + + /// Initialise and clear the keyboard for custom effects + #[inline] + pub fn get_init_msg() -> Vec { + let mut init = vec![0u8; 64]; + init[0] = 0x5d; // Report ID + init[1] = 0xbc; // Mode = custom??, 0xb3 is builtin + init + } + + #[inline] + pub fn set(&mut self, key: Key, r: u8, g: u8, b: u8) { + let (rr, gg, bb) = self.key(key); + *rr = r; + *gg = g; + *bb = b; + } + + pub fn key(&mut self, key: Key) -> (&mut u8, &mut u8, &mut u8) { + // Tuples are indexes in to array + let (row, col) = match key { + Key::VolUp => (0, 15), + Key::VolDown => (0, 18), + Key::MicMute => (0, 21), + Key::ROG => (0, 24), + // + Key::Esc => (1, 24), + Key::F1 => (1, 30), + Key::F2 => (1, 33), + Key::F3 => (1, 36), + Key::F4 => (1, 39), + Key::F5 => (1, 45), + Key::F6 => (1, 48), + Key::F7 => (1, 51), + Key::F8 => (1, 54), + // + Key::F9 => (2, 12), + Key::F10 => (2, 15), + Key::F11 => (2, 18), + Key::F12 => (2, 21), + Key::Del => (2, 24), + Key::Tilde => (2, 39), + Key::N1 => (2, 42), + Key::N2 => (2, 45), + Key::N3 => (2, 48), + Key::N4 => (2, 51), + Key::N5 => (2, 54), + // + Key::N6 => (3, 9), + Key::N7 => (3, 12), + Key::N8 => (3, 15), + Key::N9 => (3, 18), + Key::N0 => (3, 21), + Key::Hyphen => (3, 24), + Key::Equals => (3, 27), + Key::BkSpc1 => (3, 30), + Key::BkSpc2 => (3, 33), + Key::BkSpc3 => (3, 36), + Key::Home => (3, 39), + Key::Tab => (3, 54), + // + Key::Q => (4, 9), + Key::W => (4, 12), + Key::E => (4, 15), + Key::R => (4, 18), + Key::T => (4, 21), + Key::Y => (4, 24), + Key::U => (4, 27), + Key::I => (4, 30), + Key::O => (4, 33), + Key::P => (4, 36), + Key::LBracket => (4, 39), + Key::RBracket => (4, 42), + Key::BackSlash => (4, 45), + Key::PgUp => (4, 54), + // + Key::Caps => (5, 21), + Key::A => (5, 24), + Key::S => (5, 27), + Key::D => (5, 30), + Key::F => (5, 33), + Key::G => (5, 36), + Key::H => (5, 39), + Key::J => (5, 42), + Key::K => (5, 45), + Key::L => (5, 48), + Key::SemiColon => (5, 51), + Key::Quote => (5, 54), + // + Key::Ret1 => (6, 12), + Key::Ret2 => (6, 15), + Key::Ret3 => (6, 18), + Key::PgDn => (6, 21), + Key::LShift => (6, 36), + Key::Z => (6, 42), + Key::X => (6, 45), + Key::C => (6, 48), + Key::V => (6, 51), + Key::B => (6, 54), + // + Key::N => (7, 9), + Key::M => (7, 12), + Key::Comma => (7, 15), + Key::Period => (7, 18), + Key::FwdSlash => (7, 21), + Key::Rshift1 => (7, 27), + Key::Rshift2 => (7, 30), + Key::Rshift3 => (7, 33), + Key::End => (7, 36), + Key::LCtrl => (7, 51), + Key::LFn => (7, 54), + // + Key::Meta => (8, 9), + Key::LAlt => (8, 12), + Key::Space1 => (8, 15), + Key::Space2 => (8, 18), + Key::Space3 => (8, 21), + Key::Space4 => (8, 24), + Key::RAlt => (8, 30), + Key::PrtSc => (8, 33), + Key::RCtrl => (8, 36), + Key::Up => (8, 42), + Key::RFn => (8, 51), + // + Key::Left => (9, 54), + // + Key::Down => (10, 9), + Key::Right => (10, 12), + }; + // LOLOLOLOLOLOLOL! Look it's safe okay + unsafe { + ( + &mut *(&mut self.0[row][col] as *mut u8), + &mut *(&mut self.0[row][col + 1] as *mut u8), + &mut *(&mut self.0[row][col + 2] as *mut u8), + ) + } + } + + #[inline] + pub fn get(&self) -> &[[u8; 64]; 10] { + &self.0 + } +} + +pub enum Key { + VolUp, + VolDown, + MicMute, + ROG, + Esc, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + Del, + Tilde, + N1, + N2, + N3, + N4, + N5, + N6, + N7, + N8, + N9, + N0, + Hyphen, + Equals, + BkSpc1, + BkSpc2, + BkSpc3, + Home, + Tab, + Q, + W, + E, + R, + T, + Y, + U, + I, + O, + P, + LBracket, + RBracket, + BackSlash, + PgUp, + Caps, + A, + S, + D, + F, + G, + H, + J, + K, + L, + SemiColon, + Quote, + Ret1, + Ret2, + Ret3, + PgDn, + LShift, + Z, + X, + C, + V, + B, + N, + M, + Comma, + Period, + FwdSlash, + Rshift1, + Rshift2, + Rshift3, + End, + LCtrl, + LFn, + Meta, + LAlt, + Space1, + Space2, + Space3, + Space4, + RAlt, + PrtSc, + RCtrl, + Up, + Down, + Left, + Right, + RFn, +} diff --git a/aura/src/lib.rs b/aura/src/lib.rs new file mode 100644 index 00000000..d1ba0d5b --- /dev/null +++ b/aura/src/lib.rs @@ -0,0 +1,233 @@ +pub static DBUS_NAME: &'static str = "org.rogcore.Daemon"; +pub static DBUS_PATH: &'static str = "/org/rogcore/Daemon"; +pub static DBUS_IFACE: &'static str = "org.rogcore.Daemon"; +pub const LED_MSG_LEN: usize = 17; + +mod builtins; +pub use builtins::*; + +/// Contains mostly only what is required for parsing CLI options +pub mod cli_options; +mod fancy; + +mod aura_dbus; +pub use aura_dbus::*; + +pub use fancy::*; + +pub mod error; +use crate::cli_options::*; + +/// Writes aout the correct byte string for brightness +/// +/// The HID descriptor looks like: +/// +/// ``` +/// 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined 0xFF31) +/// 0x09, 0x76, // Usage (0x76) +/// 0xA1, 0x01, // Collection (Application) +/// 0x85, 0x5A, // Report ID (90) +/// 0x19, 0x00, // Usage Minimum (0x00) +/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) +/// 0x15, 0x00, // Logical Minimum (0) +/// 0x26, 0xFF, 0x00, // Logical Maximum (255) +/// 0x75, 0x08, // Report Size (8) +/// 0x95, 0x05, // Report Count (5) +/// 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) +/// 0x19, 0x00, // Usage Minimum (0x00) +/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) +/// 0x15, 0x00, // Logical Minimum (0) +/// 0x26, 0xFF, 0x00, // Logical Maximum (255) +/// 0x75, 0x08, // Report Size (8) +/// 0x95, 0x3F, // Report Count (63) +/// 0xB1, 0x00, // Feature (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) +/// 0xC0, // End Collection +/// ``` +pub fn aura_brightness_bytes(brightness: u8) -> [u8; 17] { + // TODO: check brightness range + [ + 0x5A, 0xBA, 0xC5, 0xC4, brightness, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ] +} + +/// Parses `SetAuraBuiltin` in to packet data +/// +/// Byte structure: +/// +/// ``` +/// | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| +/// |---|---|---|---|---|---|---|---|---|---|---|---|---| +/// |5d |b3 |00 |03 |ff |00 |00 |00 |00 |00 |00 |ff |00 | +/// ``` +/// +/// Bytes 0 and 1 should always be 5d, b3 +/// +/// On multizone laptops byte 2 is the zone number, RGB in usual +/// place, byte 3 set to zero +/// +/// Byte 3 sets the mode type: +/// - 00 = static +/// - 01 = breathe (can set two colours) +/// - 02 = cycle (through all colours) +/// - 03 = rainbow +/// - 04 = rain (byte 9 sets random colour) +/// - 05 = random keys, red, white, turquoise +/// - 06 = pressed keys light up and fade +/// - 07 = pressed key emits laser +/// - 08 = pressed key emits water ripple +/// - 09 = no effect/not used +/// - 0a fast pulse (no speed setting) +/// - 0b vertical line racing to right (no speed setting) +/// - 0c wider vertical line racing to right (no speed setting) +/// +/// Bytes 4, 5, 6 are Red, Green, Blue +/// +/// Byte 7 sets speed from +/// - 0x00 = Off +/// - 0xe1 = Slow +/// - 0xeb = Medium +/// - 0xf5 = Fast +/// +/// Byte 8 sets rainbow direction: +/// - 0x00 = rightwards +/// - 0x01 = leftwards +/// - 0x02 = upwards +/// - 0x03 = downwards +/// +/// Bytes 10, 11, 12 are Red, Green, Blue for second colour if mode supports it +/// +/// The HID descriptor looks like: +/// ``` +/// 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined 0xFF31) +/// 0x09, 0x79, // Usage (0x79) +/// 0xA1, 0x01, // Collection (Application) +/// 0x85, 0x5D, // Report ID (93) +/// 0x19, 0x00, // Usage Minimum (0x00) +/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) +/// 0x15, 0x00, // Logical Minimum (0) +/// 0x26, 0xFF, 0x00, // Logical Maximum (255) +/// 0x75, 0x08, // Report Size (8) +/// 0x95, 0x1F, // Report Count (31) +/// 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) +/// 0x19, 0x00, // Usage Minimum (0x00) +/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) +/// 0x15, 0x00, // Logical Minimum (0) +/// 0x26, 0xFF, 0x00, // Logical Maximum (255) +/// 0x75, 0x08, // Report Size (8) +/// 0x95, 0x3F, // Report Count (63) +/// 0x91, 0x00, // Output (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) +/// 0x19, 0x00, // Usage Minimum (0x00) +/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) +/// 0x15, 0x00, // Logical Minimum (0) +/// 0x26, 0xFF, 0x00, // Logical Maximum (255) +/// 0x75, 0x08, // Report Size (8) +/// 0x95, 0x3F, // Report Count (63) +/// 0xB1, 0x00, // Feature (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) +/// 0xC0, // End Collection +/// ``` +/// +/// This descriptor is also used for the per-key LED settings +impl From<&SetAuraBuiltin> for [u8; LED_MSG_LEN] { + fn from(mode: &SetAuraBuiltin) -> Self { + let mut msg = [0u8; LED_MSG_LEN]; + msg[0] = 0x5d; + msg[1] = 0xb3; + match mode { + SetAuraBuiltin::Stable(_) => msg[3] = 0x00, + SetAuraBuiltin::Breathe(_) => msg[3] = 0x01, + SetAuraBuiltin::Cycle(_) => msg[3] = 0x02, + SetAuraBuiltin::Rainbow(_) => msg[3] = 0x03, + SetAuraBuiltin::Rain(_) => msg[3] = 0x04, + SetAuraBuiltin::Disco(_) => msg[3] = 0x05, + SetAuraBuiltin::Highlight(_) => msg[3] = 0x06, + SetAuraBuiltin::Laser(_) => msg[3] = 0x07, + SetAuraBuiltin::Ripple(_) => msg[3] = 0x08, + SetAuraBuiltin::Pulse(_) => msg[3] = 0x0a, + SetAuraBuiltin::ThinZoomy(_) => msg[3] = 0x0b, + SetAuraBuiltin::WideZoomy(_) => msg[3] = 0x0c, + _ => panic!("Mode not convertable to array"), + } + + match mode { + SetAuraBuiltin::Rainbow(settings) => { + msg[7] = settings.speed as u8; + msg[8] = settings.direction as u8; + } + SetAuraBuiltin::Rain(settings) => { + msg[4] = settings.colour.0; + msg[5] = settings.colour.1; + msg[6] = settings.colour.2; + msg[7] = settings.speed as u8; + msg[9] = settings.colour2.2; + } + SetAuraBuiltin::Breathe(settings) => { + msg[4] = settings.colour.0; + msg[5] = settings.colour.1; + msg[6] = settings.colour.2; + msg[7] = settings.speed as u8; + msg[10] = settings.colour2.0; + msg[11] = settings.colour2.1; + msg[12] = settings.colour2.2; + } + SetAuraBuiltin::Cycle(settings) | SetAuraBuiltin::Disco(settings) => { + msg[7] = settings.speed as u8; + } + SetAuraBuiltin::Highlight(settings) + | SetAuraBuiltin::Laser(settings) + | SetAuraBuiltin::Ripple(settings) => { + msg[4] = settings.colour.0; + msg[5] = settings.colour.1; + msg[6] = settings.colour.2; + msg[7] = settings.speed as u8; + } + SetAuraBuiltin::Stable(settings) + | SetAuraBuiltin::Pulse(settings) + | SetAuraBuiltin::ThinZoomy(settings) + | SetAuraBuiltin::WideZoomy(settings) => { + msg[4] = settings.colour.0; + msg[5] = settings.colour.1; + msg[6] = settings.colour.2; + } + _ => panic!("Mode not convertable to array"), + } + msg + } +} + +impl From for [u8; LED_MSG_LEN] { + #[inline] + fn from(mode: SetAuraBuiltin) -> Self { + <[u8; LED_MSG_LEN]>::from(&mode) + } +} + +impl From for [[u8; LED_MSG_LEN]; 4] { + #[inline] + fn from(mode: SetAuraBuiltin) -> Self { + let mut msg = [[0u8; LED_MSG_LEN]; 4]; + for i in 0..4 { + msg[i][0] = 0x5d; + msg[i][1] = 0xb3; + msg[i][2] = i as u8 + 1; + } + + match mode { + SetAuraBuiltin::MultiStatic(settings) => { + msg[0][4] = settings.colour1.0; + msg[0][5] = settings.colour1.1; + msg[0][6] = settings.colour1.2; + msg[1][4] = settings.colour2.0; + msg[1][5] = settings.colour2.1; + msg[1][6] = settings.colour2.2; + msg[2][4] = settings.colour3.0; + msg[2][5] = settings.colour3.1; + msg[2][6] = settings.colour3.2; + msg[3][4] = settings.colour4.0; + msg[3][5] = settings.colour4.1; + msg[3][6] = settings.colour4.2; + } + _ => panic!("Mode not convertable to array"), + } + msg + } +} diff --git a/rog-core/Cargo.lock b/rog-core/Cargo.lock new file mode 100644 index 00000000..6de19ede --- /dev/null +++ b/rog-core/Cargo.lock @@ -0,0 +1,1016 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d2e7343e7fc9de883d1b0341e0b13970f764c14101234857d2ddafa1cb1cac2" + +[[package]] +name = "aho-corasick" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +dependencies = [ + "memchr", +] + +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi 0.3.8", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.8", +] + +[[package]] +name = "bindgen" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb26d6a69a335b8cb0e7c7e9775cd5666611dc50a37177c3f2cedcfc040e8c8" +dependencies = [ + "bitflags", + "cexpr", + "cfg-if", + "clang-sys", + "clap", + "env_logger", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "which", +] + +[[package]] +name = "bit-set" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e84c238982c4b1e1ee668d136c510c67a13465279c0cb367ea6baf6310620a80" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f59bbe95d4e52a6398ec21238d31577f2b28a9d86807f06ca59d191d8440d0bb" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "bytes" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "130aac562c0dd69c56b3b1cc8ffd2e17be31d0b6c25b61c96b76231aa23e39e1" + +[[package]] +name = "cc" +version = "1.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d" + +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "clang-sys" +version = "0.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6837df1d5cba2397b835c8530f51723267e16abbf83892e9e5af4f0e5dd10a" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "2.33.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "dbus" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f8875bb7afbc20dec12db09e18af3dcbd672b08592d2932950326a6437c616" +dependencies = [ + "futures", + "libc", + "libdbus-sys", +] + +[[package]] +name = "dbus-tokio" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "641f98f32585b8a8cc5d88c6c55a8f6cdf60740baab17c57d59b9b662c73f522" +dependencies = [ + "dbus", + "mio", + "tokio", +] + +[[package]] +name = "enumflags2" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c8d82922337cd23a15f88b70d8e4ef5f11da38dd7cdb55e84dd5de99695da0" +dependencies = [ + "enumflags2_derive", +] + +[[package]] +name = "enumflags2_derive" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "err-derive" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22deed3a8124cff5fa835713fa105621e43bbdc46690c3a6b68328a012d350d4" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "rustversion", + "syn", + "synstructure", +] + +[[package]] +name = "filetime" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f59efc38004c988e4201d11d263b8171f49a2e7ec0bdbb71773433f271504a5e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "winapi 0.3.8", +] + +[[package]] +name = "fnv" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +dependencies = [ + "bitflags", + "fuchsia-zircon-sys", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" + +[[package]] +name = "futures" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" + +[[package]] +name = "futures-executor" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" + +[[package]] +name = "futures-macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6" + +[[package]] +name = "futures-task" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" + +[[package]] +name = "futures-util" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + +[[package]] +name = "gumdrop" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46571f5d540478cf70d2a42dd0d6d8e9f4b9cc7531544b93311e657b86568a0b" +dependencies = [ + "gumdrop_derive", +] + +[[package]] +name = "gumdrop_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915ef07c710d84733522461de2a734d4d62a3fd39a4d4f404c2f385ef8618d05" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "hermit-abi" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4" +dependencies = [ + "libc", +] + +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + +[[package]] +name = "intel-pstate" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0e7f68d8a6d149a5b2195ab645923c63ee35928fff58895b3c1d21541afe90c" +dependencies = [ + "err-derive", + "smart-default", +] + +[[package]] +name = "iovec" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" +dependencies = [ + "libc", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lazycell" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" + +[[package]] +name = "libc" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005" + +[[package]] +name = "libdbus-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc12a3bc971424edbbf7edaf6e5740483444db63aa8e23d3751ff12a30f306f0" +dependencies = [ + "pkg-config", +] + +[[package]] +name = "libflate" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9135df43b1f5d0e333385cb6e7897ecd1a43d7d11b91ac003f4d2c2d2401fdd" +dependencies = [ + "adler32", + "crc32fast", + "rle-decode-fast", + "take_mut", +] + +[[package]] +name = "libloading" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b111a074963af1d37a139918ac6d49ad1d0d5e47f72fd55388619691a7d753" +dependencies = [ + "cc", + "winapi 0.3.8", +] + +[[package]] +name = "libusb1-sys" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0318f131edc8211a9a3e40133be6fc93f0b686e14f59c6115eab4e7bd794b34" +dependencies = [ + "cc", + "libc", + "libflate", + "pkg-config", + "tar", + "vcpkg", +] + +[[package]] +name = "log" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" + +[[package]] +name = "mio" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302dec22bcf6bae6dfb69c647187f4b4d0fb6f535521f7bc022430ce8e12008f" +dependencies = [ + "cfg-if", + "fuchsia-zircon", + "fuchsia-zircon-sys", + "iovec", + "kernel32-sys", + "libc", + "log", + "miow", + "net2", + "slab", + "winapi 0.2.8", +] + +[[package]] +name = "miow" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +dependencies = [ + "kernel32-sys", + "net2", + "winapi 0.2.8", + "ws2_32-sys", +] + +[[package]] +name = "net2" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +dependencies = [ + "cfg-if", + "libc", + "winapi 0.3.8", +] + +[[package]] +name = "nom" +version = "5.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b471253da97532da4b61552249c521e01e736071f71c1a4f7ebbfbf0a06aad6" +dependencies = [ + "memchr", + "version_check", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "pin-project-lite" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "237844750cfbb86f67afe27eee600dfbbcb6188d734139b534cbfbf4f96792ae" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" + +[[package]] +name = "proc-macro-error" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "syn-mid", + "version_check", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d659fe7c6d27f25e9d80a1a094c223f5246f6a6596453e09d7229bf42750b63" + +[[package]] +name = "proc-macro-nested" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e946095f9d3ed29ec38de908c22f95d9ac008e424c7bcae54c75a79c527c694" + +[[package]] +name = "proc-macro2" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df246d292ff63439fea9bc8c0a270bed0e390d5ebd4db4ba15aba81111b5abe3" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" + +[[package]] +name = "regex" +version = "1.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae" + +[[package]] +name = "rle-decode-fast" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cabe4fa914dec5870285fa7f71f602645da47c486e68486d2b4ceb4a343e90ac" + +[[package]] +name = "rog-daemon" +version = "0.8.0" +dependencies = [ + "dbus", + "dbus-tokio", + "env_logger", + "gumdrop", + "intel-pstate", + "log", + "rusb", + "serde", + "serde_derive", + "thiserror", + "tokio", + "toml", + "uhid-virt", +] + +[[package]] +name = "rusb" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d10caa3e5fc7ad1879a679bf16d3304ea10614b8f2f1a1386be4ec942d44062a" +dependencies = [ + "bit-set", + "libc", + "libusb1-sys", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustversion" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3bba175698996010c4f6dce5e7f173b6eb781fce25d2cfc45e27091ce0b79f6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399" + +[[package]] +name = "serde_derive" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" + +[[package]] +name = "smart-default" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "syn" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "syn-mid" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "synstructure" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + +[[package]] +name = "take_mut" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" + +[[package]] +name = "tar" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3" +dependencies = [ + "filetime", + "libc", + "redox_syscall", + "xattr", +] + +[[package]] +name = "termcolor" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "thiserror" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d12a1dae4add0f0d568eebc7bf142f145ba1aa2544cafb195c76f0f409091b60" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f34e0c1caaa462fd840ec6b768946ea1e7842620d94fe29d5b847138f521269" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tokio" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d9c43f1bb96970e153bcbae39a65e249ccb942bd9d36dbdf086024920417c9c" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "lazy_static", + "mio", + "num_cpus", + "pin-project-lite", + "slab", + "tokio-macros", +] + +[[package]] +name = "tokio-macros" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c3acc6aa564495a0f2e1d59fab677cd7f81a19994cfc7f3ad0e64301560389" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "toml" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +dependencies = [ + "serde", +] + +[[package]] +name = "uhid-virt" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057ecb2608f960fd97c220557339335bf7cef77ae77b71fb342d9555e396c00c" +dependencies = [ + "enumflags2", + "libc", + "uhidrs-sys", +] + +[[package]] +name = "uhidrs-sys" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78b2a68a0769dc3b501bcc9127f561220ff54b485b3dd9aa97718fda91dbdaa" +dependencies = [ + "bindgen", +] + +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" + +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" + +[[package]] +name = "vcpkg" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" + +[[package]] +name = "vec_map" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" + +[[package]] +name = "version_check" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" + +[[package]] +name = "which" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +dependencies = [ + "libc", +] + +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.8", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" +dependencies = [ + "winapi 0.2.8", + "winapi-build", +] + +[[package]] +name = "xattr" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" +dependencies = [ + "libc", +] diff --git a/rog-core/Cargo.toml b/rog-core/Cargo.toml new file mode 100644 index 00000000..4208ef00 --- /dev/null +++ b/rog-core/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "rog-daemon" +version = "0.8.0" +license = "MPL-2.0" +readme = "README.md" +authors = ["Luke "] +repository = "https://github.com/flukejones/rog-core" +homepage = "https://github.com/flukejones/rog-core" +description = "A daemon app for ASUS GX502 and similar laptops to control missing features" +edition = "2018" + +[lib] +name = "daemon" +path = "src/lib.rs" + +[[bin]] +name = "rog-core" +path = "src/main.rs" + +[dependencies] +rog-aura = { path = "../aura" } +rusb = "^0.5.5" + +# cli and logging +gumdrop = "^0.8.0" +log = "^0.4.8" +env_logger = "^0.7.1" + +# async +dbus = { version = "^0.8.2", features = ["futures"] } +dbus-tokio = "^0.5.1" +tokio = { version = "0.2.4", features = ["rt-threaded", "macros", "sync"] } + +# serialisation +serde = "1.0" +serde_derive = "1.0" +toml = "0.5" + +# Device control +# sysfs-class = "^0.1.2" # used for backlight control mostly +# cpu power management +intel-pstate = "^0.2.1" +# virtualisation of HID, mainly for outputting consumer key codes +uhid-virt = "^0.0.4" +#keycode = "0.3" diff --git a/src/config.rs b/rog-core/src/config.rs similarity index 98% rename from src/config.rs rename to rog-core/src/config.rs index f2ecd120..c3100fcf 100644 --- a/src/config.rs +++ b/rog-core/src/config.rs @@ -1,4 +1,4 @@ -use crate::aura::BuiltInModeBytes; +use rog_aura::BuiltInModeBytes; use serde_derive::{Deserialize, Serialize}; use std::fs::{File, OpenOptions}; use std::io::{Read, Write}; diff --git a/src/core.rs b/rog-core/src/core.rs similarity index 97% rename from src/core.rs rename to rog-core/src/core.rs index 522c6b42..18516346 100644 --- a/src/core.rs +++ b/rog-core/src/core.rs @@ -1,13 +1,9 @@ // Return show-stopping errors, otherwise map error to a log level -use crate::{ - aura::{aura_brightness_bytes, BuiltInModeByte}, - config::Config, - error::AuraError, - virt_device::VirtKeys, -}; +use crate::{config::Config, virt_device::VirtKeys}; use gumdrop::Options; use log::{debug, error, info, warn}; +use rog_aura::{aura_brightness_bytes, error::AuraError, BuiltInModeByte}; use rusb::DeviceHandle; use std::error::Error; use std::fs::OpenOptions; @@ -48,7 +44,11 @@ pub(crate) struct RogCore { } impl RogCore { - pub(crate) fn new(vendor: u16, product: u16, led_endpoint: u8) -> Result { + pub(crate) fn new( + vendor: u16, + product: u16, + led_endpoint: u8, + ) -> Result> { let mut dev_handle = RogCore::get_device(vendor, product)?; dev_handle.set_active_configuration(0).unwrap_or(()); @@ -72,9 +72,7 @@ impl RogCore { } dev_handle.set_auto_detach_kernel_driver(true).unwrap(); - dev_handle - .claim_interface(interface) - .map_err(AuraError::UsbError)?; + dev_handle.claim_interface(interface)?; Ok(RogCore { handle: dev_handle, @@ -115,14 +113,14 @@ impl RogCore { fn get_device( vendor: u16, product: u16, - ) -> Result, AuraError> { + ) -> Result, rusb::Error> { for device in rusb::devices().unwrap().iter() { let device_desc = device.device_descriptor().unwrap(); if device_desc.vendor_id() == vendor && device_desc.product_id() == product { - return device.open().map_err(|err| AuraError::UsbError(err)); + return device.open(); } } - Err(AuraError::UsbError(rusb::Error::NoDevice)) + Err(rusb::Error::NoDevice) } pub(crate) fn fan_mode_step(&mut self, config: &mut Config) -> Result<(), Box> { diff --git a/src/daemon.rs b/rog-core/src/daemon.rs similarity index 97% rename from src/daemon.rs rename to rog-core/src/daemon.rs index 0489a9b1..a79f961d 100644 --- a/src/daemon.rs +++ b/rog-core/src/daemon.rs @@ -1,11 +1,11 @@ -use crate::{aura::*, config::Config, core::*, laptops::match_laptop}; +use crate::{config::Config, core::*, laptops::match_laptop}; use dbus::{ nonblock::Process, tree::{Factory, MTSync, Method, MethodErr, Tree}, }; use dbus_tokio::connection; - use log::{error, info, warn}; +use rog_aura::{DBUS_IFACE, DBUS_PATH}; use std::error::Error; use std::sync::Arc; use std::time::{Duration, Instant}; @@ -134,6 +134,8 @@ pub async fn start_daemon() -> Result<(), Box> { std::thread::sleep(Duration::from_millis(200)); } else if now.duration_since(time_mark).as_millis() > 100 { std::thread::sleep(Duration::from_millis(50)); + } else { + std::thread::sleep(Duration::from_micros(300)); } } }); diff --git a/src/laptops/mod.rs b/rog-core/src/laptops/mod.rs similarity index 99% rename from src/laptops/mod.rs rename to rog-core/src/laptops/mod.rs index 99652dd9..acf901b2 100644 --- a/src/laptops/mod.rs +++ b/rog-core/src/laptops/mod.rs @@ -1,7 +1,6 @@ -use crate::aura::BuiltInModeByte; use crate::config::Config; use crate::core::{LedWriter, RogCore}; -use crate::error::AuraError; +use rog_aura::{error::AuraError, BuiltInModeByte}; //use keycode::{KeyMap, KeyMappingId, KeyState, KeyboardState}; use crate::virt_device::ConsumerKeys; use log::{info, warn}; diff --git a/src/lib.rs b/rog-core/src/lib.rs similarity index 61% rename from src/lib.rs rename to rog-core/src/lib.rs index 2b644c23..ee59efc0 100644 --- a/src/lib.rs +++ b/rog-core/src/lib.rs @@ -1,11 +1,7 @@ -pub mod aura; -/// Contains mostly only what is required for parsing CLI options -pub mod cli_options; mod config; /// The core module which allows writing to LEDs or polling the /// laptop keyboard attached devices pub mod core; pub mod daemon; -mod error; pub mod laptops; mod virt_device; diff --git a/src/main.rs b/rog-core/src/main.rs similarity index 93% rename from src/main.rs rename to rog-core/src/main.rs index 8ae2600a..18c5e886 100644 --- a/src/main.rs +++ b/rog-core/src/main.rs @@ -1,12 +1,8 @@ -use daemon::{ - aura::{AuraDbusWriter, LED_MSG_LEN}, - cli_options::SetAuraBuiltin, - core::LedBrightness, - daemon::start_daemon, -}; +use daemon::{core::LedBrightness, daemon::start_daemon}; use env_logger::{Builder, Target}; use gumdrop::Options; use log::LevelFilter; +use rog_aura::{cli_options::SetAuraBuiltin, AuraDbusWriter, LED_MSG_LEN}; static VERSION: &'static str = "0.8.0"; diff --git a/src/virt_device.rs b/rog-core/src/virt_device.rs similarity index 100% rename from src/virt_device.rs rename to rog-core/src/virt_device.rs diff --git a/src/aura.rs b/src/aura.rs deleted file mode 100644 index cf61d301..00000000 --- a/src/aura.rs +++ /dev/null @@ -1,714 +0,0 @@ -pub static DBUS_NAME: &'static str = "org.rogcore.Daemon"; -pub static DBUS_PATH: &'static str = "/org/rogcore/Daemon"; -pub static DBUS_IFACE: &'static str = "org.rogcore.Daemon"; -pub const LED_MSG_LEN: usize = 17; - -use crate::cli_options::*; -use serde_derive::{Deserialize, Serialize}; - -/// Writes aout the correct byte string for brightness -/// -/// The HID descriptor looks like: -/// -/// ``` -/// 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined 0xFF31) -/// 0x09, 0x76, // Usage (0x76) -/// 0xA1, 0x01, // Collection (Application) -/// 0x85, 0x5A, // Report ID (90) -/// 0x19, 0x00, // Usage Minimum (0x00) -/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) -/// 0x15, 0x00, // Logical Minimum (0) -/// 0x26, 0xFF, 0x00, // Logical Maximum (255) -/// 0x75, 0x08, // Report Size (8) -/// 0x95, 0x05, // Report Count (5) -/// 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) -/// 0x19, 0x00, // Usage Minimum (0x00) -/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) -/// 0x15, 0x00, // Logical Minimum (0) -/// 0x26, 0xFF, 0x00, // Logical Maximum (255) -/// 0x75, 0x08, // Report Size (8) -/// 0x95, 0x3F, // Report Count (63) -/// 0xB1, 0x00, // Feature (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) -/// 0xC0, // End Collection -/// ``` -pub fn aura_brightness_bytes(brightness: u8) -> [u8; 17] { - // TODO: check brightness range - [ - 0x5A, 0xBA, 0xC5, 0xC4, brightness, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - ] -} - -/// Parses `SetAuraBuiltin` in to packet data -/// -/// Byte structure: -/// -/// ``` -/// | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12| -/// |---|---|---|---|---|---|---|---|---|---|---|---|---| -/// |5d |b3 |00 |03 |ff |00 |00 |00 |00 |00 |00 |ff |00 | -/// ``` -/// -/// Bytes 0 and 1 should always be 5d, b3 -/// -/// On multizone laptops byte 2 is the zone number, RGB in usual -/// place, byte 3 set to zero -/// -/// Byte 3 sets the mode type: -/// - 00 = static -/// - 01 = breathe (can set two colours) -/// - 02 = cycle (through all colours) -/// - 03 = rainbow -/// - 04 = rain (byte 9 sets random colour) -/// - 05 = random keys, red, white, turquoise -/// - 06 = pressed keys light up and fade -/// - 07 = pressed key emits laser -/// - 08 = pressed key emits water ripple -/// - 09 = no effect/not used -/// - 0a fast pulse (no speed setting) -/// - 0b vertical line racing to right (no speed setting) -/// - 0c wider vertical line racing to right (no speed setting) -/// -/// Bytes 4, 5, 6 are Red, Green, Blue -/// -/// Byte 7 sets speed from -/// - 0x00 = Off -/// - 0xe1 = Slow -/// - 0xeb = Medium -/// - 0xf5 = Fast -/// -/// Byte 8 sets rainbow direction: -/// - 0x00 = rightwards -/// - 0x01 = leftwards -/// - 0x02 = upwards -/// - 0x03 = downwards -/// -/// Bytes 10, 11, 12 are Red, Green, Blue for second colour if mode supports it -/// -/// The HID descriptor looks like: -/// ``` -/// 0x06, 0x31, 0xFF, // Usage Page (Vendor Defined 0xFF31) -/// 0x09, 0x79, // Usage (0x79) -/// 0xA1, 0x01, // Collection (Application) -/// 0x85, 0x5D, // Report ID (93) -/// 0x19, 0x00, // Usage Minimum (0x00) -/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) -/// 0x15, 0x00, // Logical Minimum (0) -/// 0x26, 0xFF, 0x00, // Logical Maximum (255) -/// 0x75, 0x08, // Report Size (8) -/// 0x95, 0x1F, // Report Count (31) -/// 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) -/// 0x19, 0x00, // Usage Minimum (0x00) -/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) -/// 0x15, 0x00, // Logical Minimum (0) -/// 0x26, 0xFF, 0x00, // Logical Maximum (255) -/// 0x75, 0x08, // Report Size (8) -/// 0x95, 0x3F, // Report Count (63) -/// 0x91, 0x00, // Output (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) -/// 0x19, 0x00, // Usage Minimum (0x00) -/// 0x2A, 0xFF, 0x00, // Usage Maximum (0xFF) -/// 0x15, 0x00, // Logical Minimum (0) -/// 0x26, 0xFF, 0x00, // Logical Maximum (255) -/// 0x75, 0x08, // Report Size (8) -/// 0x95, 0x3F, // Report Count (63) -/// 0xB1, 0x00, // Feature (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) -/// 0xC0, // End Collection -/// ``` -/// -/// This descriptor is also used for the per-key LED settings -impl From<&SetAuraBuiltin> for [u8; LED_MSG_LEN] { - fn from(mode: &SetAuraBuiltin) -> Self { - let mut msg = [0u8; LED_MSG_LEN]; - msg[0] = 0x5d; - msg[1] = 0xb3; - match mode { - SetAuraBuiltin::Stable(_) => msg[3] = 0x00, - SetAuraBuiltin::Breathe(_) => msg[3] = 0x01, - SetAuraBuiltin::Cycle(_) => msg[3] = 0x02, - SetAuraBuiltin::Rainbow(_) => msg[3] = 0x03, - SetAuraBuiltin::Rain(_) => msg[3] = 0x04, - SetAuraBuiltin::Disco(_) => msg[3] = 0x05, - SetAuraBuiltin::Highlight(_) => msg[3] = 0x06, - SetAuraBuiltin::Laser(_) => msg[3] = 0x07, - SetAuraBuiltin::Ripple(_) => msg[3] = 0x08, - SetAuraBuiltin::Pulse(_) => msg[3] = 0x0a, - SetAuraBuiltin::ThinZoomy(_) => msg[3] = 0x0b, - SetAuraBuiltin::WideZoomy(_) => msg[3] = 0x0c, - _ => panic!("Mode not convertable to array"), - } - - match mode { - SetAuraBuiltin::Rainbow(settings) => { - msg[7] = settings.speed as u8; - msg[8] = settings.direction as u8; - } - SetAuraBuiltin::Rain(settings) => { - msg[4] = settings.colour.0; - msg[5] = settings.colour.1; - msg[6] = settings.colour.2; - msg[7] = settings.speed as u8; - msg[9] = settings.colour2.2; - } - SetAuraBuiltin::Breathe(settings) => { - msg[4] = settings.colour.0; - msg[5] = settings.colour.1; - msg[6] = settings.colour.2; - msg[7] = settings.speed as u8; - msg[10] = settings.colour2.0; - msg[11] = settings.colour2.1; - msg[12] = settings.colour2.2; - } - SetAuraBuiltin::Cycle(settings) | SetAuraBuiltin::Disco(settings) => { - msg[7] = settings.speed as u8; - } - SetAuraBuiltin::Highlight(settings) - | SetAuraBuiltin::Laser(settings) - | SetAuraBuiltin::Ripple(settings) => { - msg[4] = settings.colour.0; - msg[5] = settings.colour.1; - msg[6] = settings.colour.2; - msg[7] = settings.speed as u8; - } - SetAuraBuiltin::Stable(settings) - | SetAuraBuiltin::Pulse(settings) - | SetAuraBuiltin::ThinZoomy(settings) - | SetAuraBuiltin::WideZoomy(settings) => { - msg[4] = settings.colour.0; - msg[5] = settings.colour.1; - msg[6] = settings.colour.2; - } - _ => panic!("Mode not convertable to array"), - } - msg - } -} - -impl From for [u8; LED_MSG_LEN] { - fn from(mode: SetAuraBuiltin) -> Self { - <[u8; LED_MSG_LEN]>::from(&mode) - } -} - -impl From for [[u8; LED_MSG_LEN]; 4] { - fn from(mode: SetAuraBuiltin) -> Self { - let mut msg = [[0u8; LED_MSG_LEN]; 4]; - for i in 0..4 { - msg[i][0] = 0x5d; - msg[i][1] = 0xb3; - msg[i][2] = i as u8 + 1; - } - - match mode { - SetAuraBuiltin::MultiStatic(settings) => { - msg[0][4] = settings.colour1.0; - msg[0][5] = settings.colour1.1; - msg[0][6] = settings.colour1.2; - msg[1][4] = settings.colour2.0; - msg[1][5] = settings.colour2.1; - msg[1][6] = settings.colour2.2; - msg[2][4] = settings.colour3.0; - msg[2][5] = settings.colour3.1; - msg[2][6] = settings.colour3.2; - msg[3][4] = settings.colour4.0; - msg[3][5] = settings.colour4.1; - msg[3][6] = settings.colour4.2; - } - _ => panic!("Mode not convertable to array"), - } - msg - } -} - -/// Container for the byte strings used in modes. Generally useful for settings -/// and other usecases. -#[derive(Deserialize, Serialize)] -pub struct BuiltInModeBytes { - pub stable: [u8; LED_MSG_LEN], - pub breathe: [u8; LED_MSG_LEN], - pub cycle: [u8; LED_MSG_LEN], - pub rainbow: [u8; LED_MSG_LEN], - pub rain: [u8; LED_MSG_LEN], - pub random: [u8; LED_MSG_LEN], - pub highlight: [u8; LED_MSG_LEN], - pub laser: [u8; LED_MSG_LEN], - pub ripple: [u8; LED_MSG_LEN], - pub pulse: [u8; LED_MSG_LEN], - pub thinzoomy: [u8; LED_MSG_LEN], - pub widezoomy: [u8; LED_MSG_LEN], - pub multi_static: [[u8; LED_MSG_LEN]; 4], -} -impl BuiltInModeBytes { - pub fn set_field_from(&mut self, bytes: &[u8]) { - if bytes[0] == 0x5d && bytes[1] == 0xb3 { - let b = BuiltInModeByte::from(bytes[3]); - match b { - BuiltInModeByte::Single => self.stable.copy_from_slice(bytes), - BuiltInModeByte::Breathing => self.breathe.copy_from_slice(bytes), - BuiltInModeByte::Cycle => self.cycle.copy_from_slice(bytes), - BuiltInModeByte::Rainbow => self.rainbow.copy_from_slice(bytes), - BuiltInModeByte::Rain => self.rain.copy_from_slice(bytes), - BuiltInModeByte::Random => self.random.copy_from_slice(bytes), - BuiltInModeByte::Highlight => self.highlight.copy_from_slice(bytes), - BuiltInModeByte::Laser => self.laser.copy_from_slice(bytes), - BuiltInModeByte::Ripple => self.ripple.copy_from_slice(bytes), - BuiltInModeByte::Pulse => self.pulse.copy_from_slice(bytes), - BuiltInModeByte::ThinZoomy => self.thinzoomy.copy_from_slice(bytes), - BuiltInModeByte::WideZoomy => self.widezoomy.copy_from_slice(bytes), - _ => {} - } - } - } - - pub fn get_field_from(&mut self, byte: u8) -> Option<&[u8]> { - let bytes = match BuiltInModeByte::from(byte) { - BuiltInModeByte::Single => &self.stable, - BuiltInModeByte::Breathing => &self.breathe, - BuiltInModeByte::Cycle => &self.cycle, - BuiltInModeByte::Rainbow => &self.rainbow, - BuiltInModeByte::Rain => &self.rain, - BuiltInModeByte::Random => &self.random, - BuiltInModeByte::Highlight => &self.highlight, - BuiltInModeByte::Laser => &self.laser, - BuiltInModeByte::Ripple => &self.ripple, - BuiltInModeByte::Pulse => &self.pulse, - BuiltInModeByte::ThinZoomy => &self.thinzoomy, - BuiltInModeByte::WideZoomy => &self.widezoomy, - _ => return None, - }; - return Some(bytes); - } -} -impl Default for BuiltInModeBytes { - fn default() -> Self { - BuiltInModeBytes { - stable: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Stable(SingleColour::default())), - breathe: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Breathe(TwoColourSpeed::default())), - cycle: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Cycle(SingleSpeed::default())), - rainbow: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Rainbow( - SingleSpeedDirection::default(), - )), - rain: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Rain(TwoColourSpeed::default())), - random: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Disco(SingleSpeed::default())), - highlight: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Highlight( - SingleColourSpeed::default(), - )), - laser: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Laser(SingleColourSpeed::default())), - ripple: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Ripple(SingleColourSpeed::default())), - pulse: <[u8; LED_MSG_LEN]>::from(SetAuraBuiltin::Pulse(SingleColour::default())), - thinzoomy: <[u8; LED_MSG_LEN]>::from( - SetAuraBuiltin::ThinZoomy(SingleColour::default()), - ), - widezoomy: <[u8; LED_MSG_LEN]>::from( - SetAuraBuiltin::WideZoomy(SingleColour::default()), - ), - multi_static: <[[u8; LED_MSG_LEN]; 4]>::from(SetAuraBuiltin::MultiStatic( - MultiColour::default(), - )), - } - } -} - -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] -pub enum BuiltInModeByte { - Single = 0x00, - Breathing = 0x01, - Cycle = 0x02, - Rainbow = 0x03, - Rain = 0x04, - Random = 0x05, - Highlight = 0x06, - Laser = 0x07, - Ripple = 0x08, - Pulse = 0x0a, - ThinZoomy = 0x0b, - WideZoomy = 0x0c, - None, -} -impl Default for BuiltInModeByte { - fn default() -> Self { - BuiltInModeByte::Single - } -} - -impl From for BuiltInModeByte { - fn from(byte: u8) -> Self { - match byte { - 0x00 => Self::Single, - 0x01 => Self::Breathing, - 0x02 => Self::Cycle, - 0x03 => Self::Rainbow, - 0x04 => Self::Rain, - 0x05 => Self::Random, - 0x06 => Self::Highlight, - 0x07 => Self::Laser, - 0x08 => Self::Ripple, - 0x0a => Self::Pulse, - 0x0b => Self::ThinZoomy, - 0x0c => Self::WideZoomy, - _ => Self::None, - } - } -} - -impl From<&u8> for BuiltInModeByte { - fn from(byte: &u8) -> Self { - Self::from(*byte) - } -} - -impl From for u8 { - fn from(byte: BuiltInModeByte) -> Self { - match byte { - BuiltInModeByte::Single => 0x00, - BuiltInModeByte::Breathing => 0x01, - BuiltInModeByte::Cycle => 0x02, - BuiltInModeByte::Rainbow => 0x03, - BuiltInModeByte::Rain => 0x04, - BuiltInModeByte::Random => 0x05, - BuiltInModeByte::Highlight => 0x06, - BuiltInModeByte::Laser => 0x07, - BuiltInModeByte::Ripple => 0x08, - BuiltInModeByte::Pulse => 0x0a, - BuiltInModeByte::ThinZoomy => 0x0b, - BuiltInModeByte::WideZoomy => 0x0c, - BuiltInModeByte::None => 0xff, - } - } -} - -#[derive(Clone)] -pub struct KeyColourArray([[u8; 64]; 10]); -impl KeyColourArray { - pub fn new() -> Self { - let mut set = [[0u8; 64]; 10]; - for (count, row) in set.iter_mut().enumerate() { - row[0] = 0x5d; // Report ID - row[1] = 0xbc; // Mode = custom??, 0xb3 is builtin - row[2] = 0x00; - row[3] = 0x01; // ?? - row[4] = 0x01; // ??, 4,5,6 are normally RGB for builtin mode colours - row[5] = 0x01; // ?? - row[6] = (count as u8) << 4; // Key group - row[7] = 0x10; // 0b00010000 addressing? flips for group a0 - if count == 9 { - row[7] = 0x08; // 0b00001000 - } - row[8] = 0x00; - } - KeyColourArray(set) - } - - /// Initialise and clear the keyboard for custom effects - pub fn get_init_msg() -> Vec { - let mut init = vec![0u8; 64]; - init[0] = 0x5d; // Report ID - init[1] = 0xbc; // Mode = custom??, 0xb3 is builtin - init - } - - pub fn set(&mut self, key: Key, r: u8, g: u8, b: u8) { - let (rr, gg, bb) = self.key(key); - *rr = r; - *gg = g; - *bb = b; - } - - pub fn key(&mut self, key: Key) -> (&mut u8, &mut u8, &mut u8) { - // Tuples are indexes in to array - let (row, col) = match key { - Key::VolUp => (0, 15), - Key::VolDown => (0, 18), - Key::MicMute => (0, 21), - Key::ROG => (0, 24), - // - Key::Esc => (1, 24), - Key::F1 => (1, 30), - Key::F2 => (1, 33), - Key::F3 => (1, 36), - Key::F4 => (1, 39), - Key::F5 => (1, 45), - Key::F6 => (1, 48), - Key::F7 => (1, 51), - Key::F8 => (1, 54), - // - Key::F9 => (2, 12), - Key::F10 => (2, 15), - Key::F11 => (2, 18), - Key::F12 => (2, 21), - Key::Del => (2, 24), - Key::Tilde => (2, 39), - Key::N1 => (2, 42), - Key::N2 => (2, 45), - Key::N3 => (2, 48), - Key::N4 => (2, 51), - Key::N5 => (2, 54), - // - Key::N6 => (3, 9), - Key::N7 => (3, 12), - Key::N8 => (3, 15), - Key::N9 => (3, 18), - Key::N0 => (3, 21), - Key::Hyphen => (3, 24), - Key::Equals => (3, 27), - Key::BkSpc1 => (3, 30), - Key::BkSpc2 => (3, 33), - Key::BkSpc3 => (3, 36), - Key::Home => (3, 39), - Key::Tab => (3, 54), - // - Key::Q => (4, 9), - Key::W => (4, 12), - Key::E => (4, 15), - Key::R => (4, 18), - Key::T => (4, 21), - Key::Y => (4, 24), - Key::U => (4, 27), - Key::I => (4, 30), - Key::O => (4, 33), - Key::P => (4, 36), - Key::LBracket => (4, 39), - Key::RBracket => (4, 42), - Key::BackSlash => (4, 45), - Key::PgUp => (4, 54), - // - Key::Caps => (5, 21), - Key::A => (5, 24), - Key::S => (5, 27), - Key::D => (5, 30), - Key::F => (5, 33), - Key::G => (5, 36), - Key::H => (5, 39), - Key::J => (5, 42), - Key::K => (5, 45), - Key::L => (5, 48), - Key::SemiColon => (5, 51), - Key::Quote => (5, 54), - // - Key::Ret1 => (6, 12), - Key::Ret2 => (6, 15), - Key::Ret3 => (6, 18), - Key::PgDn => (6, 21), - Key::LShift => (6, 36), - Key::Z => (6, 42), - Key::X => (6, 45), - Key::C => (6, 48), - Key::V => (6, 51), - Key::B => (6, 54), - // - Key::N => (7, 9), - Key::M => (7, 12), - Key::Comma => (7, 15), - Key::Period => (7, 18), - Key::FwdSlash => (7, 21), - Key::Rshift1 => (7, 27), - Key::Rshift2 => (7, 30), - Key::Rshift3 => (7, 33), - Key::End => (7, 36), - Key::LCtrl => (7, 51), - Key::LFn => (7, 54), - // - Key::Meta => (8, 9), - Key::LAlt => (8, 12), - Key::Space1 => (8, 15), - Key::Space2 => (8, 18), - Key::Space3 => (8, 21), - Key::Space4 => (8, 24), - Key::RAlt => (8, 30), - Key::PrtSc => (8, 33), - Key::RCtrl => (8, 36), - Key::Up => (8, 42), - Key::RFn => (8, 51), - // - Key::Left => (9, 54), - // - Key::Down => (10, 9), - Key::Right => (10, 12), - }; - // LOLOLOLOLOLOLOL! Look it's safe okay - unsafe { - ( - &mut *(&mut self.0[row][col] as *mut u8), - &mut *(&mut self.0[row][col + 1] as *mut u8), - &mut *(&mut self.0[row][col + 2] as *mut u8), - ) - } - } - - pub fn get(&self) -> &[[u8; 64]; 10] { - &self.0 - } -} - -pub enum Key { - VolUp, - VolDown, - MicMute, - ROG, - Esc, - F1, - F2, - F3, - F4, - F5, - F6, - F7, - F8, - F9, - F10, - F11, - F12, - Del, - Tilde, - N1, - N2, - N3, - N4, - N5, - N6, - N7, - N8, - N9, - N0, - Hyphen, - Equals, - BkSpc1, - BkSpc2, - BkSpc3, - Home, - Tab, - Q, - W, - E, - R, - T, - Y, - U, - I, - O, - P, - LBracket, - RBracket, - BackSlash, - PgUp, - Caps, - A, - S, - D, - F, - G, - H, - J, - K, - L, - SemiColon, - Quote, - Ret1, - Ret2, - Ret3, - PgDn, - LShift, - Z, - X, - C, - V, - B, - N, - M, - Comma, - Period, - FwdSlash, - Rshift1, - Rshift2, - Rshift3, - End, - LCtrl, - LFn, - Meta, - LAlt, - Space1, - Space2, - Space3, - Space4, - RAlt, - PrtSc, - RCtrl, - Up, - Down, - Left, - Right, - RFn, -} - -use dbus::{ffidisp::Connection, Message}; -use std::error::Error; -use std::{thread, time::Duration}; - -/// Simplified way to write a effect block -pub struct AuraDbusWriter { - connection: Connection, - block_time: u64, -} - -impl AuraDbusWriter { - pub fn new() -> Result> { - Ok(AuraDbusWriter { - connection: Connection::new_system()?, - block_time: 10, - }) - } - - /// This method must always be called before the very first write to initialise - /// the keyboard LED EC in the correct mode - pub fn init_effect(&self) -> Result<(), Box> { - let msg = Message::new_method_call(DBUS_NAME, DBUS_PATH, DBUS_IFACE, "ledmessage")? - .append1(KeyColourArray::get_init_msg()); - self.connection.send(msg).unwrap(); - Ok(()) - } - - /// Write a single colour block. - /// - /// Intentionally blocks for 10ms after sending to allow the block to - /// be written to the keyboard EC. This should not be async. - pub fn write_colour_block( - &self, - key_colour_array: &KeyColourArray, - ) -> Result<(), Box> { - let group = key_colour_array.get(); - let msg = Message::new_method_call(DBUS_NAME, DBUS_PATH, DBUS_IFACE, "ledeffect")? - .append1(&group[0].to_vec()) - .append1(&group[1].to_vec()) - .append1(&group[2].to_vec()) - .append1(&group[3].to_vec()) - .append1(&group[4].to_vec()) - .append1(&group[5].to_vec()) - .append1(&group[6].to_vec()) - .append1(&group[7].to_vec()) - .append1(&group[8].to_vec()) - .append1(&group[9].to_vec()); - self.connection.send(msg).unwrap(); - thread::sleep(Duration::from_millis(self.block_time)); - Ok(()) - } - - pub fn write_bytes(&self, bytes: &[u8]) -> Result> { - let msg = Message::new_method_call(DBUS_NAME, DBUS_PATH, DBUS_IFACE, "ledmessage")? - .append1(bytes.to_vec()); - let r = self.connection.send_with_reply_and_block(msg, 5000)?; - if let Some(reply) = r.get1::<&str>() { - return Ok(reply.to_owned()); - } - Err(Box::new(dbus::Error::new_custom("name", "message"))) - } - - pub fn write_builtin_mode( - &self, - mode: &SetAuraBuiltin, - ) -> Result> { - let bytes = <[u8; LED_MSG_LEN]>::from(mode); - self.write_bytes(&bytes) - } - - pub fn write_brightness(&self, level: u8) -> Result> { - self.write_bytes(&aura_brightness_bytes(level)) - } -} diff --git a/wireshark_data/rog-star-colour.pcapng b/wireshark_data/rog-star-colour.pcapng new file mode 100755 index 0000000000000000000000000000000000000000..37493a84d945353e582540b87f7170ca0febf82c GIT binary patch literal 2736 zcmb_cO=uHQ5T4yl(k8XEDHZxBY^B8nP1tN=Lor~a73-l;TBS%W_9v;0*0!{%k)lu= z#G_ZwA_yKtte(77JlLan5j^$aO+haTJ;nKUvzy(xZDQ)c?Bvb7`QA4(@5R^H=-Vcu z;l#-ffo-8EBK6V5#cX;ZFdCExmR8b%OT$4q6A$&rPb)+6z{q7eDXZZ=<-*Xq9LQy| z^YYl(`B+#D5=qoceX-C?CM%C;7E?>PRXL)_0aa0A!Bg_gT4o_7NBWgmgwJ!4N`q^+ zmS?Az<-mAmCA~U7y>c@sN5g8Eb8c%kq=c@gm2@gLJ2xFo#c>8?n-!c>tb4450+C3q zlrvzirSD`JI1*Q5Uf${9JxBh58*kUJkvE71i~p&cK8^nF>EYkdE;vnT00EIU#Co_k zJfPR2&Cd{SHtZHnw_kU&VYg(u+jTb^cDqb>x9(=cZnx=<=x#Rb z_L%Oox|1Db zlDwGQB3FIk=Qjju5}aB7COrOVZzub8wV$oMiQ;83-h`F+6V5I1Zl2n^=gj*}O>9d^ zPP~7$T6x>gcH(`t2#0?Ak4AgX@EY1lFRwgUFY(rL^McHw$?seIJwSk2-p>xk)_eIk zwl+(=2bM%J7qvma>lNo(`uXw0KK*>Hr_}t#ncxln5S;y^&DxXZsrRe<^rXTtfmz-Y zPrJ1zc5J7fBs5k!uNPgmTw70^=8W1PsELl*`Z?9OS*pqUt}2wI10L|jndLP%&Dwa| z&UWIBzCpnI1m{+DKPy}WV3zZW*m&9RzSAtMyx!fg^0Lp-_HHUP)QQ(;#xA`ZJ9as* EKQj(A!T7j9kE@62=_w;3EBp5*rQo^#K4zx$ngr@FSbdW(p9 z+RvSo;EN@bDM?qS^4ZDI^|0D8J(~^P=n1R2)<|1xi`K1n^xjlcYCM|Mu5>S`p+YV{ zuJ-kHC8F^#kwRxFnTU+!@@ju>Dl=V}Q)8MMifdXTd|n-y&rN33SeurJVLu&&>w8-78mdzwa$A+6Tt-J@@76x<9VEn--7Kvm! zMgK5jT9T_c zv{b?L8uVJm=q;@?F`}6B5HYGqGB6sDQW_-S5vBY!W5;FA0FiMH!3lV2i_;5Wv6-9- z_|Ib(PHCi+fSe{pqMdlahXyE;qy!r4B$7^dP^EuaNs$!rVTy!QN?b-_#Yo_6j>KCe zRyk4W_pu}9v-h)MF>6JJ-V~4!FnYxp?fT3<8=uJ>rIhY;y>*#M;hMegulHN|5B+8g ztKU14lzO`Ku9_Qvz&6R#x z)_b?Yj+-tUS=IIE4LHIA(<5 z5U#Momy9qRpMCGW#mQxS$_{_G7z1GT-CE=sjC*kO_F@x1Djq?4zHx2h*?0bq5e2wR zCZCkTWN?#wRmI;wNl$TlpT>KZzlo8d#ik(Q#t`?`-$d!Mm~X<#dmXh7-pb}9cix}( z$+LX98}F`+z+2ecjrTwal=YrR?M2La1nI-AwFR5EUb`x(NDcnl#P2_hG0XLQCGZll z^=>ljKE98_R{k)Y8`rRd|k77Ip38BEl-`@^nCJO&{NpkOV4%G+Iot2NVuOK7r{-> nHv%sa+f7f#VB`Cl{^;Z-_Cnz0A*dU#`@jxjA7hBv<-Gm^R0}&$ literal 0 HcmV?d00001