mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Move led_writer to a main loop due to strange mpsc behaviour
This commit is contained in:
@@ -89,6 +89,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
writer.write_colour_block(&colours)?;
|
writer.write_colour_block(&colours)?;
|
||||||
|
|
||||||
// can change 100 times per second, so need to slow it down
|
// can change 100 times per second, so need to slow it down
|
||||||
std::thread::sleep(std::time::Duration::from_millis(60));
|
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
writer.write_colour_block(&key_colours)?;
|
writer.write_colour_block(&key_colours)?;
|
||||||
std::thread::sleep(std::time::Duration::from_millis(250));
|
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ use yansi_term::Colour::RGB;
|
|||||||
/// See the examples for ways to write an image to `AniMeMatrix` format.
|
/// See the examples for ways to write an image to `AniMeMatrix` format.
|
||||||
pub struct AniMeMatrix(AniMeBufferType);
|
pub struct AniMeMatrix(AniMeBufferType);
|
||||||
|
|
||||||
|
impl Default for AniMeMatrix {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AniMeMatrix {
|
impl AniMeMatrix {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
AniMeMatrix([[0u8; WIDTH]; HEIGHT])
|
AniMeMatrix([[0u8; WIDTH]; HEIGHT])
|
||||||
@@ -127,7 +133,7 @@ impl From<AniMeMatrix> for AniMePacketType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let index = row.len() - prog_row_len;
|
let index = row.len() - prog_row_len;
|
||||||
for n in index..row.len() {
|
for n in row.iter().skip(index) {
|
||||||
// Require a special case to catch the correct end-of-packet which is
|
// Require a special case to catch the correct end-of-packet which is
|
||||||
// 6 bytes from the end
|
// 6 bytes from the end
|
||||||
if write_index == BLOCK_END && !block1_done {
|
if write_index == BLOCK_END && !block1_done {
|
||||||
@@ -136,8 +142,7 @@ impl From<AniMeMatrix> for AniMePacketType {
|
|||||||
write_index = BLOCK_START;
|
write_index = BLOCK_START;
|
||||||
}
|
}
|
||||||
|
|
||||||
//println!("{:?}", write_block.to_vec());
|
write_block[write_index] = *n;
|
||||||
write_block[write_index] = row[n];
|
|
||||||
write_index += 1;
|
write_index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -211,10 +211,10 @@ impl From<SetAuraBuiltin> for [[u8; LED_MSG_LEN]; 4] {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn from(mode: SetAuraBuiltin) -> Self {
|
fn from(mode: SetAuraBuiltin) -> Self {
|
||||||
let mut msg = [[0u8; LED_MSG_LEN]; 4];
|
let mut msg = [[0u8; LED_MSG_LEN]; 4];
|
||||||
for i in 0..4 {
|
for (i, row) in msg.iter_mut().enumerate() {
|
||||||
msg[i][0] = 0x5d;
|
row[0] = 0x5d;
|
||||||
msg[i][1] = 0xb3;
|
row[1] = 0xb3;
|
||||||
msg[i][2] = i as u8 + 1;
|
row[2] = i as u8 + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
|
|||||||
@@ -148,14 +148,14 @@ impl AniMeWriter {
|
|||||||
init[idx + 1] = *byte
|
init[idx + 1] = *byte
|
||||||
}
|
}
|
||||||
self.write_bytes(&init).await?;
|
self.write_bytes(&init).await?;
|
||||||
|
|
||||||
// clear the init array and write other init message
|
// clear the init array and write other init message
|
||||||
for idx in 0..INIT_STR.len() {
|
for ch in init.iter_mut() {
|
||||||
match idx {
|
*ch = 0;
|
||||||
0 => init[idx] = DEV_PAGE, // write it to be sure?
|
|
||||||
1 => init[idx] = INIT,
|
|
||||||
_ => init[idx] = 0,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
init[0] = DEV_PAGE; // write it to be sure?
|
||||||
|
init[1] = INIT;
|
||||||
|
|
||||||
self.write_bytes(&init).await?;
|
self.write_bytes(&init).await?;
|
||||||
self.initialised = true;
|
self.initialised = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ impl Config {
|
|||||||
// Should be okay to unwrap this as is since it is a Default
|
// Should be okay to unwrap this as is since it is a Default
|
||||||
let toml = toml::to_string(&c).unwrap();
|
let toml = toml::to_string(&c).unwrap();
|
||||||
file.write_all(toml.as_bytes())
|
file.write_all(toml.as_bytes())
|
||||||
.expect("Writing default config failed");
|
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
|
||||||
self = c;
|
self = c;
|
||||||
} else {
|
} else {
|
||||||
self =
|
self =
|
||||||
@@ -54,8 +54,8 @@ impl Config {
|
|||||||
if l == 0 {
|
if l == 0 {
|
||||||
panic!("Missing {}", CONFIG_PATH);
|
panic!("Missing {}", CONFIG_PATH);
|
||||||
} else {
|
} else {
|
||||||
let x: Config =
|
let x: Config = toml::from_str(&buf)
|
||||||
toml::from_str(&buf).expect(&format!("Could not deserialise {}", CONFIG_PATH));
|
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
|
||||||
*self = x;
|
*self = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,9 @@ use log::{error, info, warn};
|
|||||||
use rog_client::{DBUS_IFACE, DBUS_NAME, DBUS_PATH};
|
use rog_client::{DBUS_IFACE, DBUS_NAME, DBUS_PATH};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::{Duration, Instant};
|
use tokio::sync::Mutex;
|
||||||
use tokio::sync::{mpsc, Mutex};
|
|
||||||
|
|
||||||
pub(super) type FanModeType = Arc<Mutex<Option<u8>>>;
|
pub(super) type FanModeType = Arc<Mutex<Option<u8>>>;
|
||||||
pub(super) type LedMsgType = Arc<Mutex<Option<Vec<u8>>>>;
|
|
||||||
pub(super) type NestedVecType = Arc<Mutex<Option<Vec<Vec<u8>>>>>;
|
|
||||||
|
|
||||||
// Timing is such that:
|
// Timing is such that:
|
||||||
// - interrupt write is minimum 1ms (sometimes lower)
|
// - interrupt write is minimum 1ms (sometimes lower)
|
||||||
@@ -108,7 +105,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let config1 = config.clone();
|
let config1 = config.clone();
|
||||||
// start the keyboard reader and laptop-action loop
|
// start the keyboard reader and laptop-action loop
|
||||||
let key_read_handle = tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
// Fan mode
|
// Fan mode
|
||||||
if let Ok(mut lock) = fan_mode.try_lock() {
|
if let Ok(mut lock) = fan_mode.try_lock() {
|
||||||
@@ -129,39 +126,8 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// start the LED writer loop
|
|
||||||
let led_write_handle = tokio::spawn(async move {
|
|
||||||
loop {
|
|
||||||
//connection.process_all();
|
|
||||||
|
|
||||||
// Check if a key press issued a command
|
|
||||||
while let Some(command) = aura_command_recv.recv().await {
|
|
||||||
let mut config = config.lock().await;
|
|
||||||
match command {
|
|
||||||
AuraCommand::WriteEffect(_) | AuraCommand::WriteMultizone(_) => led_writer
|
|
||||||
.do_command(command, &mut config)
|
|
||||||
.await
|
|
||||||
.unwrap_or_else(|err| warn!("{:?}", err)),
|
|
||||||
_ => {
|
|
||||||
led_writer
|
|
||||||
.do_command(command, &mut config)
|
|
||||||
.await
|
|
||||||
.unwrap_or_else(|err| warn!("{:?}", err));
|
|
||||||
connection
|
|
||||||
.send(
|
|
||||||
effect_cancel_signal
|
|
||||||
.msg(&DBUS_PATH.into(), &DBUS_IFACE.into())
|
|
||||||
.append1(true),
|
|
||||||
)
|
|
||||||
.unwrap_or_else(|_| 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// If animatrix is supported, try doing a write
|
// If animatrix is supported, try doing a write
|
||||||
let animatrix_write_handle = tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Some(writer) = animatrix_writer.as_mut() {
|
if let Some(writer) = animatrix_writer.as_mut() {
|
||||||
while let Some(image) = animatrix_recv.recv().await {
|
while let Some(image) = animatrix_recv.recv().await {
|
||||||
writer
|
writer
|
||||||
@@ -172,8 +138,32 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
animatrix_write_handle.await?;
|
// start the main loop
|
||||||
led_write_handle.await?;
|
loop {
|
||||||
key_read_handle.await?;
|
connection.process_all();
|
||||||
Ok(())
|
|
||||||
|
// Check if a key press issued a command
|
||||||
|
while let Some(command) = aura_command_recv.recv().await {
|
||||||
|
let mut config = config.lock().await;
|
||||||
|
match command {
|
||||||
|
AuraCommand::WriteEffect(_) | AuraCommand::WriteMultizone(_) => led_writer
|
||||||
|
.do_command(command, &mut config)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|err| warn!("{:?}", err)),
|
||||||
|
_ => {
|
||||||
|
led_writer
|
||||||
|
.do_command(command, &mut config)
|
||||||
|
.await
|
||||||
|
.unwrap_or_else(|err| warn!("{:?}", err));
|
||||||
|
connection
|
||||||
|
.send(
|
||||||
|
effect_cancel_signal
|
||||||
|
.msg(&DBUS_PATH.into(), &DBUS_IFACE.into())
|
||||||
|
.append1(true),
|
||||||
|
)
|
||||||
|
.unwrap_or_else(|_| 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,13 +174,13 @@ impl LaptopBase {
|
|||||||
aura_command
|
aura_command
|
||||||
.send(AuraCommand::BrightInc)
|
.send(AuraCommand::BrightInc)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| {});
|
.unwrap_or_else(|err| warn!("LedBrightUp: {}", err));
|
||||||
}
|
}
|
||||||
GX502Keys::LedBrightDown => {
|
GX502Keys::LedBrightDown => {
|
||||||
aura_command
|
aura_command
|
||||||
.send(AuraCommand::BrightDec)
|
.send(AuraCommand::BrightDec)
|
||||||
.await
|
.await
|
||||||
.unwrap_or_else(|_| {});
|
.unwrap_or_else(|err| warn!("LedBrightDown: {}", err));
|
||||||
}
|
}
|
||||||
GX502Keys::AuraNext => {
|
GX502Keys::AuraNext => {
|
||||||
aura_command
|
aura_command
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
use crate::daemon::{FanModeType, LedMsgType, NestedVecType};
|
use crate::daemon::FanModeType;
|
||||||
use crate::led_control::AuraCommand;
|
use crate::led_control::AuraCommand;
|
||||||
use crate::rogcore::FanLevel;
|
use crate::rogcore::FanLevel;
|
||||||
use dbus::tree::{Factory, MTSync, Method, MethodErr, Signal, Tree};
|
use dbus::tree::{Factory, MTSync, Method, MethodErr, Signal, Tree};
|
||||||
use log::{error, info, warn};
|
use log::warn;
|
||||||
use rog_client::{DBUS_IFACE, DBUS_PATH};
|
use rog_client::{DBUS_IFACE, DBUS_PATH};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{
|
use tokio::sync::{
|
||||||
@@ -162,6 +162,7 @@ pub(super) fn dbus_create_fan_mode_method(fan_mode: FanModeType) -> Method<MTSyn
|
|||||||
.inarg::<u8, _>("byte")
|
.inarg::<u8, _>("byte")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
pub(super) fn dbus_create_tree() -> (
|
pub(super) fn dbus_create_tree() -> (
|
||||||
Tree<MTSync, ()>,
|
Tree<MTSync, ()>,
|
||||||
Sender<AuraCommand>,
|
Sender<AuraCommand>,
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ pub struct VirtKeys {
|
|||||||
device: UHIDDevice<std::fs::File>,
|
device: UHIDDevice<std::fs::File>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for VirtKeys {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl VirtKeys {
|
impl VirtKeys {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
VirtKeys {
|
VirtKeys {
|
||||||
|
|||||||
Reference in New Issue
Block a user