mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fix LED brightness apply on resume
This commit is contained in:
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Extra info in log for G-Sync to help prevent user confusion around gfx switching
|
- Extra info in log for G-Sync to help prevent user confusion around gfx switching
|
||||||
- Add GA503Q led modes
|
- Add GA503Q led modes
|
||||||
- Added ability to fade in/out gifs and images for anime. This does break anime configs. See manual for details.
|
- Added ability to fade in/out gifs and images for anime. This does break anime configs. See manual for details.
|
||||||
|
- Added task to CtrlLed to set the keyboard LED brightness on wake from suspend
|
||||||
|
+ requires a kernel patch which will be upstreamed and in fedora rog kernel
|
||||||
|
|
||||||
# [3.6.1] - 2021-05-25
|
# [3.6.1] - 2021-05-25
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ use crate::{
|
|||||||
config_aura::AuraConfig,
|
config_aura::AuraConfig,
|
||||||
error::RogError,
|
error::RogError,
|
||||||
laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES},
|
laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES},
|
||||||
|
CtrlTask,
|
||||||
};
|
};
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
|
use logind_zbus::ManagerProxy;
|
||||||
use rog_aura::{
|
use rog_aura::{
|
||||||
usb::{
|
usb::{
|
||||||
LED_APPLY, LED_AWAKE_OFF_SLEEP_OFF, LED_AWAKE_OFF_SLEEP_ON, LED_AWAKE_ON_SLEEP_OFF,
|
LED_APPLY, LED_AWAKE_OFF_SLEEP_OFF, LED_AWAKE_OFF_SLEEP_ON, LED_AWAKE_ON_SLEEP_OFF,
|
||||||
@@ -15,11 +17,12 @@ use rog_aura::{
|
|||||||
AuraEffect, LedBrightness, LED_MSG_LEN,
|
AuraEffect, LedBrightness, LED_MSG_LEN,
|
||||||
};
|
};
|
||||||
use rog_types::supported::LedSupportedFunctions;
|
use rog_types::supported::LedSupportedFunctions;
|
||||||
use std::fs::OpenOptions;
|
use std::{fs::OpenOptions, thread::{self, spawn}, time::Duration};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
use zbus::Connection;
|
||||||
|
|
||||||
use crate::GetSupported;
|
use crate::GetSupported;
|
||||||
|
|
||||||
@@ -50,32 +53,79 @@ pub struct CtrlKbdLed {
|
|||||||
pub config: AuraConfig,
|
pub config: AuraConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CtrlKbdLedTask(pub Arc<Mutex<CtrlKbdLed>>);
|
pub struct CtrlKbdLedTask<'a> {
|
||||||
|
inner: Arc<Mutex<CtrlKbdLed>>,
|
||||||
|
_c: Connection,
|
||||||
|
manager: ManagerProxy<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
impl crate::CtrlTask for CtrlKbdLedTask {
|
impl<'a> CtrlKbdLedTask<'a> {
|
||||||
fn do_task(&self) -> Result<(), RogError> {
|
pub fn new(inner: Arc<Mutex<CtrlKbdLed>>) -> Self {
|
||||||
if let Ok(mut lock) = self.0.try_lock() {
|
let connection = Connection::new_system().unwrap();
|
||||||
let mut file = OpenOptions::new()
|
|
||||||
.read(true)
|
let manager = ManagerProxy::new(&connection).unwrap();
|
||||||
.open(&lock.bright_node)
|
|
||||||
.map_err(|err| match err.kind() {
|
let c1 = inner.clone();
|
||||||
std::io::ErrorKind::NotFound => {
|
// Run this action when the system wakes up from sleep
|
||||||
RogError::MissingLedBrightNode((&lock.bright_node).into(), err)
|
manager
|
||||||
}
|
.connect_prepare_for_sleep(move |sleep| {
|
||||||
_ => RogError::Path((&lock.bright_node).into(), err),
|
if !sleep {
|
||||||
})?;
|
let c1 = c1.clone();
|
||||||
let mut buf = [0u8; 1];
|
spawn(move || {
|
||||||
file.read_exact(&mut buf)
|
// wait a fraction for things to wake up properly
|
||||||
.map_err(|err| RogError::Read("buffer".into(), err))?;
|
//std::thread::sleep(Duration::from_millis(100));
|
||||||
if let Some(num) = char::from(buf[0]).to_digit(10) {
|
loop {
|
||||||
if lock.config.brightness != num.into() {
|
if let Ok(ref mut lock) = c1.try_lock() {
|
||||||
lock.config.read();
|
lock.set_brightness(lock.config.brightness).ok();
|
||||||
lock.config.brightness = num.into();
|
break;
|
||||||
lock.config.write();
|
}}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.map_err(|err| {
|
||||||
|
warn!("CtrlAnimeTask: new() {}", err);
|
||||||
|
err
|
||||||
|
})
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
inner,
|
||||||
|
_c: connection,
|
||||||
|
manager,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_config(lock: &mut CtrlKbdLed) -> Result<(), RogError> {
|
||||||
|
let mut file = OpenOptions::new()
|
||||||
|
.read(true)
|
||||||
|
.open(&lock.bright_node)
|
||||||
|
.map_err(|err| match err.kind() {
|
||||||
|
std::io::ErrorKind::NotFound => {
|
||||||
|
RogError::MissingLedBrightNode((&lock.bright_node).into(), err)
|
||||||
}
|
}
|
||||||
return Ok(());
|
_ => RogError::Path((&lock.bright_node).into(), err),
|
||||||
|
})?;
|
||||||
|
let mut buf = [0u8; 1];
|
||||||
|
file.read_exact(&mut buf)
|
||||||
|
.map_err(|err| RogError::Read("buffer".into(), err))?;
|
||||||
|
if let Some(num) = char::from(buf[0]).to_digit(10) {
|
||||||
|
if lock.config.brightness != num.into() {
|
||||||
|
lock.config.read();
|
||||||
|
lock.config.brightness = num.into();
|
||||||
|
lock.config.write();
|
||||||
}
|
}
|
||||||
return Err(RogError::ParseLed);
|
return Ok(());
|
||||||
|
}
|
||||||
|
Err(RogError::ParseLed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> CtrlTask for CtrlKbdLedTask<'a> {
|
||||||
|
fn do_task(&self) -> Result<(), RogError> {
|
||||||
|
self.manager.next_signal()?;
|
||||||
|
if let Ok(ref mut lock) = self.inner.try_lock() {
|
||||||
|
return Self::update_config(lock);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
.unwrap_or_else(|err| warn!("Keyboard LED control: {}", err));
|
.unwrap_or_else(|err| warn!("Keyboard LED control: {}", err));
|
||||||
|
|
||||||
CtrlKbdLedZbus::new(inner.clone()).add_to_server(&mut object_server);
|
CtrlKbdLedZbus::new(inner.clone()).add_to_server(&mut object_server);
|
||||||
let task = CtrlKbdLedTask(inner);
|
let task = CtrlKbdLedTask::new(inner);
|
||||||
tasks.push(Box::new(task));
|
tasks.push(Box::new(task));
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user