mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
Improve per-key LED. Add extra example
- Small fixes to use all keys on GX502
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
43
aura/examples/iterate-keys.rs
Normal file
43
aura/examples/iterate-keys.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use rog_aura::{AuraDbusWriter, GX502Layout, Key, KeyColourArray, KeyLayout};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,37 +3,28 @@ use rog_aura::{AuraDbusWriter, Key, KeyColourArray};
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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(());
|
||||
}
|
||||
}
|
||||
|
||||
36
aura/examples/pulser.rs
Normal file
36
aura/examples/pulser.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use rog_aura::{AuraDbusWriter, GX502Layout, Key, KeyColourArray, KeyLayout};
|
||||
use std::ops::Sub;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<Vec<Key>>;
|
||||
}
|
||||
|
||||
pub struct GX502Layout(Vec<Vec<Key>>);
|
||||
|
||||
impl KeyLayout for GX502Layout {
|
||||
fn get_rows(&self) -> &Vec<Vec<Key>> {
|
||||
&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],
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
6
debian/changelog
vendored
6
debian/changelog
vendored
@@ -1,3 +1,9 @@
|
||||
rog-core (0.9.4) focal; urgency=medium
|
||||
|
||||
* Fix reloading last keyboard brightness on boot
|
||||
|
||||
-- Luke Jones <luke@ljones.dev> Tue, 05 May 2020 14:24:46 +1200
|
||||
|
||||
rog-core (0.9.3) focal; urgency=medium
|
||||
|
||||
* Fixes to rog-core client functionality
|
||||
|
||||
@@ -156,7 +156,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
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<MTSync, ()> {
|
||||
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<MTSync, ()> {
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
.inarg::<Vec<u8>, _>("bytearray")
|
||||
}
|
||||
|
||||
fn dbus_create_tree() -> (Tree<MTSync, ()>, LedMsgType, EffectType, Arc<Signal<()>>) {
|
||||
|
||||
@@ -40,6 +40,7 @@ where
|
||||
supported_modes: Vec<BuiltInModeByte>,
|
||||
led_endpoint: u8,
|
||||
initialised: bool,
|
||||
flip_effect_write: bool,
|
||||
_phantom: PhantomData<&'d DeviceHandle<C>>,
|
||||
}
|
||||
|
||||
@@ -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<Vec<u8>>) -> 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<Vec<u8>>) -> 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())
|
||||
|
||||
Reference in New Issue
Block a user