diff --git a/CHANGELOG.md b/CHANGELOG.md index 01f66fec..f745a373 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- Flip writing order of effect colour blocks every other block write to try + and even out. Previously the bottom rows were always last to be written. ## [0.9.4] - 2020-05-05 ### Changed diff --git a/README.md b/README.md index b53b2d62..fcfa2500 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ captures from others with different ROG laptops then I should be able to add the I'm now looking at the kernel source to see if I can add the inputs correctly so they show up as proper evdev events. -## Requirements +## Requirements for compiling - `rustc` + `cargo` + `make` - `libusb-1.0-0-dev` @@ -58,7 +58,7 @@ I can't guarantee stability of updating via PPA yet. ## Updating Occasionally I might break things for you by tweaking or changing the config file layout. Usually this will mean you -need to remove `/etc/rog-core.toml' and restart the daemon to create a new one. You *can* back up the old one and copy +need to remove `/etc/rog-core.conf' and restart the daemon to create a new one. You *can* back up the old one and copy settings back over (then restart daemon again). ## Use diff --git a/aura/examples/iterate-keys.rs b/aura/examples/iterate-keys.rs new file mode 100644 index 00000000..60cccd9c --- /dev/null +++ b/aura/examples/iterate-keys.rs @@ -0,0 +1,43 @@ +use rog_aura::{AuraDbusWriter, GX502Layout, Key, KeyColourArray, KeyLayout}; + +fn main() -> Result<(), Box> { + let mut writer = AuraDbusWriter::new()?; + + let mut key_colours = KeyColourArray::new(); + let layout = GX502Layout::default(); + + writer.init_effect()?; + let rows = layout.get_rows(); + loop { + for (r, row) in rows.iter().enumerate() { + for (k, key) in row.iter().enumerate() { + *key_colours.key(*key).0 = 254; + // Last key of previous row + if k == 0 { + if r == 0 { + let k = &rows[rows.len() - 1][rows[rows.len() - 1].len() - 1]; + *key_colours.key(*k).0 = 0; + } else { + let k = &rows[r - 1][rows[r - 1].len() - 1]; + *key_colours.key(*k).0 = 0; + } + } else { + let k = &rows[r][k - 1]; + *key_colours.key(*k).0 = 0; + } + *key_colours.key(Key::Up).0 = 255; + *key_colours.key(Key::Left).0 = 255; + *key_colours.key(Key::Right).0 = 255; + *key_colours.key(Key::Down).0 = 255; + + *key_colours.key(Key::W).0 = 255; + *key_colours.key(Key::A).0 = 255; + *key_colours.key(Key::S).0 = 255; + *key_colours.key(Key::D).0 = 255; + + writer.write_colour_block(&key_colours)?; + std::thread::sleep(std::time::Duration::from_millis(100)); + } + } + } +} diff --git a/aura/examples/per-key-effect-2.rs b/aura/examples/per-key-effect-2.rs index e4385f8a..5901a0bb 100644 --- a/aura/examples/per-key-effect-2.rs +++ b/aura/examples/per-key-effect-2.rs @@ -3,37 +3,28 @@ use rog_aura::{AuraDbusWriter, Key, KeyColourArray}; fn main() -> Result<(), Box> { let mut writer = AuraDbusWriter::new()?; - let mut per_key_led = Vec::new(); let mut key_colours = KeyColourArray::new(); - per_key_led.push(key_colours.clone()); - - for _ in 0..49 { - *key_colours.key(Key::ROG).0 += 3; - *key_colours.key(Key::L).0 += 3; - *key_colours.key(Key::I).0 += 3; - *key_colours.key(Key::N).0 += 3; - *key_colours.key(Key::U).0 += 3; - *key_colours.key(Key::X).0 += 3; - per_key_led.push(key_colours.clone()); - } - - for _ in 0..49 { - *key_colours.key(Key::ROG).0 -= 3; - *key_colours.key(Key::L).0 -= 3; - *key_colours.key(Key::I).0 -= 3; - *key_colours.key(Key::N).0 -= 3; - *key_colours.key(Key::U).0 -= 3; - *key_colours.key(Key::X).0 -= 3; - per_key_led.push(key_colours.clone()); - } writer.init_effect()?; loop { - let now = std::time::Instant::now(); - for group in &per_key_led { - writer.write_colour_block(group)?; + let count = 49; + for _ in 0..count { + *key_colours.key(Key::ROG).0 += 5; + *key_colours.key(Key::L).0 += 5; + *key_colours.key(Key::I).0 += 5; + *key_colours.key(Key::N).0 += 5; + *key_colours.key(Key::U).0 += 5; + *key_colours.key(Key::X).0 += 5; + writer.write_colour_block(&key_colours)?; + } + for _ in 0..count { + *key_colours.key(Key::ROG).0 -= 5; + *key_colours.key(Key::L).0 -= 5; + *key_colours.key(Key::I).0 -= 5; + *key_colours.key(Key::N).0 -= 5; + *key_colours.key(Key::U).0 -= 5; + *key_colours.key(Key::X).0 -= 5; + writer.write_colour_block(&key_colours)?; } - dbg!(std::time::Instant::now().duration_since(now).as_millis()); - //return Ok(()); } } diff --git a/aura/examples/pulser.rs b/aura/examples/pulser.rs new file mode 100644 index 00000000..eb022406 --- /dev/null +++ b/aura/examples/pulser.rs @@ -0,0 +1,36 @@ +use rog_aura::{AuraDbusWriter, GX502Layout, Key, KeyColourArray, KeyLayout}; +use std::ops::Sub; + +fn main() -> Result<(), Box> { + let mut writer = AuraDbusWriter::new()?; + + let mut key_colours = KeyColourArray::new(); + let layout = GX502Layout::default(); + + writer.init_effect()?; + let rows = layout.get_rows(); + + let mut fade = 50; + let mut flip = false; + loop { + for row in rows { + for (k, key) in row.iter().enumerate() { + *key_colours.key(*key).1 = 255 / fade / (k + 1) as u8; + } + } + + writer.write_colour_block(&key_colours)?; + + if flip { + if fade > 1 { + fade -= 1; + } else { + flip = !flip; + } + } else if fade < 50 { + fade += 1; + } else { + flip = !flip; + } + } +} diff --git a/aura/src/aura_dbus.rs b/aura/src/aura_dbus.rs index 13bcabc1..b80d4b65 100644 --- a/aura/src/aura_dbus.rs +++ b/aura/src/aura_dbus.rs @@ -71,7 +71,8 @@ impl AuraDbusWriter { .append1(&group[6].to_vec()) .append1(&group[7].to_vec()) .append1(&group[8].to_vec()) - .append1(&group[9].to_vec()); + .append1(&group[9].to_vec()) + .append1(&group[10].to_vec()); self.connection.send(msg).unwrap(); thread::sleep(Duration::from_millis(self.block_time)); if let Ok(lock) = self.stop.try_lock() { diff --git a/aura/src/fancy.rs b/aura/src/fancy.rs index 6c6502f6..2c48bd83 100644 --- a/aura/src/fancy.rs +++ b/aura/src/fancy.rs @@ -3,13 +3,17 @@ /// /// Each row of the internal array is a full HID packet that can be sent /// to the keyboard EC. One row controls one group of keys, these keys are not -/// neccessarily all on the same row of the keyboard, with some splitting between +/// necessarily all on the same row of the keyboard, with some splitting between /// two rows. -#[derive(Clone)] -pub struct KeyColourArray([[u8; 64]; 10]); +pub struct KeyColourArray([[u8; 64]; 11]); +impl Default for KeyColourArray { + fn default() -> Self { + Self::new() + } +} impl KeyColourArray { pub fn new() -> Self { - let mut set = [[0u8; 64]; 10]; + let mut set = [[0u8; 64]; 11]; for (count, row) in set.iter_mut().enumerate() { row[0] = 0x5d; // Report ID row[1] = 0xbc; // Mode = custom??, 0xb3 is builtin @@ -18,9 +22,10 @@ impl KeyColourArray { 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 { + if count == 10 { row[7] = 0x08; // 0b00001000 + } else { + row[7] = 0x10; // 0b00010000 addressing? flips for group a0 } row[8] = 0x00; } @@ -49,8 +54,8 @@ impl KeyColourArray { 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::VolDown => (0, 15), + Key::VolUp => (0, 18), Key::MicMute => (0, 21), Key::ROG => (0, 24), // @@ -168,11 +173,12 @@ impl KeyColourArray { } #[inline] - pub fn get(&self) -> &[[u8; 64]; 10] { + pub fn get(&self) -> &[[u8; 64]; 11] { &self.0 } } +#[derive(Debug, Copy, Clone)] pub enum Key { VolUp, VolDown, @@ -272,3 +278,128 @@ pub enum Key { Right, RFn, } + +pub trait KeyLayout { + fn get_rows(&self) -> &Vec>; +} + +pub struct GX502Layout(Vec>); + +impl KeyLayout for GX502Layout { + fn get_rows(&self) -> &Vec> { + &self.0 + } +} + +impl Default for GX502Layout { + fn default() -> Self { + GX502Layout(vec![ + vec![Key::VolDown, Key::VolUp, Key::MicMute, Key::ROG], + vec![ + Key::Esc, + Key::F1, + Key::F2, + Key::F3, + Key::F4, + Key::F5, + Key::F6, + Key::F7, + Key::F8, + Key::F9, + Key::F10, + Key::F11, + Key::F12, + Key::Del, + ], + vec![ + Key::Tilde, + Key::N1, + Key::N2, + Key::N3, + Key::N4, + Key::N5, + Key::N6, + Key::N7, + Key::N8, + Key::N9, + Key::N0, + Key::Hyphen, + Key::Equals, + Key::BkSpc1, + Key::BkSpc2, + Key::BkSpc3, + Key::Home, + ], + vec![ + Key::Tab, + Key::Q, + Key::W, + Key::E, + Key::R, + Key::T, + Key::Y, + Key::U, + Key::I, + Key::O, + Key::P, + Key::LBracket, + Key::RBracket, + Key::BackSlash, + Key::PgUp, + ], + vec![ + Key::Caps, + Key::A, + Key::S, + Key::D, + Key::F, + Key::G, + Key::H, + Key::J, + Key::K, + Key::L, + Key::SemiColon, + Key::Quote, + // + Key::Ret1, + Key::Ret2, + Key::Ret3, + Key::PgDn, + ], + vec![ + Key::LShift, + Key::Z, + Key::X, + Key::C, + Key::V, + Key::B, + Key::N, + Key::M, + Key::Comma, + Key::Period, + Key::FwdSlash, + Key::Rshift1, + Key::Rshift2, + Key::Rshift3, + Key::End, + ], + vec![ + Key::LCtrl, + Key::LFn, + // + Key::Meta, + Key::LAlt, + Key::Space1, + Key::Space2, + Key::Space3, + Key::Space4, + Key::RAlt, + Key::PrtSc, + Key::RCtrl, + Key::Up, + Key::RFn, + ], + vec![Key::Left, Key::Down, Key::Right], + ]) + } +} diff --git a/debian/changelog b/debian/changelog index 5094ceb4..7c508fb0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +rog-core (0.9.4) focal; urgency=medium + + * Fix reloading last keyboard brightness on boot + + -- Luke Jones Tue, 05 May 2020 14:24:46 +1200 + rog-core (0.9.3) focal; urgency=medium * Fixes to rog-core client functionality diff --git a/rog-core/src/daemon.rs b/rog-core/src/daemon.rs index 1aaac90a..883913dc 100644 --- a/rog-core/src/daemon.rs +++ b/rog-core/src/daemon.rs @@ -156,7 +156,7 @@ pub async fn start_daemon() -> Result<(), Box> { if let Ok(mut effect_lock) = effect.try_lock() { // Spawn a writer if let Some(effect) = effect_lock.take() { - if effect.len() == 10 { + if effect.len() == 11 { let mut config = config.lock().await; led_writer .do_command(AuraCommand::WriteEffect(effect), &mut config) @@ -229,8 +229,8 @@ fn dbus_create_ledeffect_method(effect: EffectType) -> Method { iter.read()?, iter.read()?, iter.read()?, + iter.read()?, ]; - *lock = Some(byte_array); let mret = m.msg.method_return().append1(&format!("Got effect part")); Ok(vec![mret]) @@ -250,6 +250,7 @@ fn dbus_create_ledeffect_method(effect: EffectType) -> Method { .inarg::, _>("bytearray") .inarg::, _>("bytearray") .inarg::, _>("bytearray") + .inarg::, _>("bytearray") } fn dbus_create_tree() -> (Tree, LedMsgType, EffectType, Arc>) { diff --git a/rog-core/src/led_control.rs b/rog-core/src/led_control.rs index 0b1b5700..9e34191d 100644 --- a/rog-core/src/led_control.rs +++ b/rog-core/src/led_control.rs @@ -40,6 +40,7 @@ where supported_modes: Vec, led_endpoint: u8, initialised: bool, + flip_effect_write: bool, _phantom: PhantomData<&'d DeviceHandle>, } @@ -63,6 +64,7 @@ where bright_min_max, supported_modes, initialised: false, + flip_effect_write: false, _phantom: PhantomData, } } @@ -138,11 +140,11 @@ where } /// Should only be used if the bytes you are writing are verified correct - async fn write_bytes(&mut self, message: &[u8]) -> Result<(), AuraError> { + async fn write_bytes(&self, message: &[u8]) -> Result<(), AuraError> { match unsafe { self.handle.as_ref() }.write_interrupt( self.led_endpoint, message, - Duration::from_millis(5), + Duration::from_millis(10), ) { Ok(_) => {} Err(err) => match err { @@ -153,7 +155,7 @@ where Ok(()) } - async fn write_array_of_bytes(&mut self, messages: &[&[u8]]) -> Result<(), AuraError> { + async fn write_array_of_bytes(&self, messages: &[&[u8]]) -> Result<(), AuraError> { for message in messages { self.write_bytes(*message).await?; self.write_bytes(&LED_SET).await?; @@ -166,25 +168,22 @@ where /// Write an effect block /// /// `aura_effect_init` must be called any effect routine, and called only once. - async fn write_effect(&self, effect: Vec>) -> Result<(), AuraError> { - for row in effect.iter() { - match unsafe { self.handle.as_ref() }.write_interrupt( - self.led_endpoint, - row, - Duration::from_millis(1), - ) { - Ok(_) => {} - Err(err) => match err { - rusb::Error::Timeout => {} - _ => error!("Failed to write LED interrupt: {:?}", err), - }, + async fn write_effect(&mut self, effect: Vec>) -> Result<(), AuraError> { + if self.flip_effect_write { + for row in effect.iter().rev() { + self.write_bytes(row).await?; + } + } else { + for row in effect.iter() { + self.write_bytes(row).await?; } } + self.flip_effect_write = !self.flip_effect_write; Ok(()) } /// Used to set a builtin mode and save the settings for it - async fn set_and_save(&mut self, bytes: &[u8], config: &mut Config) -> Result<(), AuraError> { + async fn set_and_save(&self, bytes: &[u8], config: &mut Config) -> Result<(), AuraError> { let mode = BuiltInModeByte::from(bytes[3]); // safety pass-through of possible effect write if bytes[1] == 0xbc { @@ -202,7 +201,7 @@ where } /// Used to set a builtin mode and save the settings for it - async fn reload_last_builtin(&mut self, config: &Config) -> Result<(), AuraError> { + async fn reload_last_builtin(&self, config: &Config) -> Result<(), AuraError> { let mode_curr = config.current_mode[3]; let mode = config .builtin_modes @@ -221,7 +220,7 @@ where /// Select next Aura effect /// /// If the current effect is the last one then the effect selected wraps around to the first. - async fn set_builtin(&mut self, config: &mut Config, index: usize) -> Result<(), AuraError> { + async fn set_builtin(&self, config: &mut Config, index: usize) -> Result<(), AuraError> { let mode_next = config .builtin_modes .get_field_from(self.supported_modes[index].into())