mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Reload LED mode on boot
This commit is contained in:
@@ -22,7 +22,7 @@ use zvariant::ObjectPath;
|
|||||||
|
|
||||||
use crate::GetSupported;
|
use crate::GetSupported;
|
||||||
|
|
||||||
impl GetSupported for CtrlKbdBacklight {
|
impl GetSupported for CtrlKbdLed {
|
||||||
type A = LedSupportedFunctions;
|
type A = LedSupportedFunctions;
|
||||||
|
|
||||||
fn get_supported() -> Self::A {
|
fn get_supported() -> Self::A {
|
||||||
@@ -37,7 +37,7 @@ impl GetSupported for CtrlKbdBacklight {
|
|||||||
};
|
};
|
||||||
|
|
||||||
LedSupportedFunctions {
|
LedSupportedFunctions {
|
||||||
brightness_set: CtrlKbdBacklight::get_kbd_bright_path().is_some(),
|
brightness_set: CtrlKbdLed::get_kbd_bright_path().is_some(),
|
||||||
stock_led_modes,
|
stock_led_modes,
|
||||||
multizone_led_mode,
|
multizone_led_mode,
|
||||||
per_key_led_mode,
|
per_key_led_mode,
|
||||||
@@ -45,7 +45,7 @@ impl GetSupported for CtrlKbdBacklight {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CtrlKbdBacklight {
|
pub struct CtrlKbdLed {
|
||||||
led_node: Option<String>,
|
led_node: Option<String>,
|
||||||
pub bright_node: String,
|
pub bright_node: String,
|
||||||
supported_modes: LaptopLedData,
|
supported_modes: LaptopLedData,
|
||||||
@@ -53,9 +53,9 @@ pub struct CtrlKbdBacklight {
|
|||||||
config: AuraConfig,
|
config: AuraConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CtrlKbdBacklightTask(pub Arc<Mutex<CtrlKbdBacklight>>);
|
pub struct CtrlKbdLedTask(pub Arc<Mutex<CtrlKbdLed>>);
|
||||||
|
|
||||||
impl crate::CtrlTask for CtrlKbdBacklightTask {
|
impl crate::CtrlTask for CtrlKbdLedTask {
|
||||||
fn do_task(&self) -> Result<(), RogError> {
|
fn do_task(&self) -> Result<(), RogError> {
|
||||||
if let Ok(mut lock) = self.0.try_lock() {
|
if let Ok(mut lock) = self.0.try_lock() {
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
@@ -84,22 +84,36 @@ impl crate::CtrlTask for CtrlKbdBacklightTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DbusKbdBacklight {
|
pub struct CtrlKbdLedReloader(pub Arc<Mutex<CtrlKbdLed>>);
|
||||||
inner: Arc<Mutex<CtrlKbdBacklight>>,
|
|
||||||
|
impl crate::Reloadable for CtrlKbdLedReloader {
|
||||||
|
fn reload(&mut self) -> Result<(), RogError> {
|
||||||
|
if let Ok(mut lock) = self.0.try_lock() {
|
||||||
|
let current = lock.config.current_mode;
|
||||||
|
if let Some(mode) = lock.config.builtins.get(¤t).cloned() {
|
||||||
|
lock.do_command(mode).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DbusKbdBacklight {
|
pub struct CtrlKbdLedZbus {
|
||||||
pub fn new(inner: Arc<Mutex<CtrlKbdBacklight>>) -> Self {
|
inner: Arc<Mutex<CtrlKbdLed>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CtrlKbdLedZbus {
|
||||||
|
pub fn new(inner: Arc<Mutex<CtrlKbdLed>>) -> Self {
|
||||||
Self { inner }
|
Self { inner }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::ZbusAdd for DbusKbdBacklight {
|
impl crate::ZbusAdd for CtrlKbdLedZbus {
|
||||||
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
fn add_to_server(self, server: &mut zbus::ObjectServer) {
|
||||||
server
|
server
|
||||||
.at(&ObjectPath::from_str_unchecked("/org/asuslinux/Led"), self)
|
.at(&ObjectPath::from_str_unchecked("/org/asuslinux/Led"), self)
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
error!("DbusKbdBacklight: add_to_server {}", err);
|
error!("DbusKbdLed: add_to_server {}", err);
|
||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
@@ -109,7 +123,7 @@ impl crate::ZbusAdd for DbusKbdBacklight {
|
|||||||
///
|
///
|
||||||
/// LED commands are split between Brightness, Modes, Per-Key
|
/// LED commands are split between Brightness, Modes, Per-Key
|
||||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||||
impl DbusKbdBacklight {
|
impl CtrlKbdLedZbus {
|
||||||
fn set_brightness(&mut self, brightness: LedBrightness) {
|
fn set_brightness(&mut self, brightness: LedBrightness) {
|
||||||
if let Ok(ctrl) = self.inner.try_lock() {
|
if let Ok(ctrl) = self.inner.try_lock() {
|
||||||
ctrl.set_brightness(brightness)
|
ctrl.set_brightness(brightness)
|
||||||
@@ -200,7 +214,7 @@ impl DbusKbdBacklight {
|
|||||||
fn notify_led(&self, data: &str) -> zbus::Result<()>;
|
fn notify_led(&self, data: &str) -> zbus::Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CtrlKbdBacklight {
|
impl CtrlKbdLed {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result<Self, RogError> {
|
pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result<Self, RogError> {
|
||||||
// TODO: return error if *all* nodes are None
|
// TODO: return error if *all* nodes are None
|
||||||
@@ -230,7 +244,7 @@ impl CtrlKbdBacklight {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let ctrl = CtrlKbdBacklight {
|
let ctrl = CtrlKbdLed {
|
||||||
led_node,
|
led_node,
|
||||||
bright_node: bright_node.unwrap(), // If was none then we already returned above
|
bright_node: bright_node.unwrap(), // If was none then we already returned above
|
||||||
supported_modes,
|
supported_modes,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use zvariant::ObjectPath;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ctrl_anime::CtrlAnime, ctrl_charge::CtrlCharge, ctrl_fan_cpu::CtrlFanAndCpu,
|
ctrl_anime::CtrlAnime, ctrl_charge::CtrlCharge, ctrl_fan_cpu::CtrlFanAndCpu,
|
||||||
ctrl_leds::CtrlKbdBacklight, ctrl_rog_bios::CtrlRogBios, GetSupported,
|
ctrl_leds::CtrlKbdLed, ctrl_rog_bios::CtrlRogBios, GetSupported,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rog_types::supported::{
|
use rog_types::supported::{
|
||||||
@@ -49,7 +49,7 @@ impl GetSupported for SupportedFunctions {
|
|||||||
|
|
||||||
fn get_supported() -> Self::A {
|
fn get_supported() -> Self::A {
|
||||||
SupportedFunctions {
|
SupportedFunctions {
|
||||||
keyboard_led: CtrlKbdBacklight::get_supported(),
|
keyboard_led: CtrlKbdLed::get_supported(),
|
||||||
anime_ctrl: CtrlAnime::get_supported(),
|
anime_ctrl: CtrlAnime::get_supported(),
|
||||||
charge_ctrl: CtrlCharge::get_supported(),
|
charge_ctrl: CtrlCharge::get_supported(),
|
||||||
fan_cpu_ctrl: CtrlFanAndCpu::get_supported(),
|
fan_cpu_ctrl: CtrlFanAndCpu::get_supported(),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use daemon::ctrl_leds::{CtrlKbdBacklight, CtrlKbdBacklightTask, DbusKbdBacklight};
|
use daemon::ctrl_leds::{CtrlKbdLed, CtrlKbdLedTask, CtrlKbdLedZbus, CtrlKbdLedReloader};
|
||||||
use daemon::{
|
use daemon::{
|
||||||
config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported,
|
config::Config, ctrl_supported::SupportedFunctions, laptops::print_board_info, GetSupported,
|
||||||
};
|
};
|
||||||
@@ -120,11 +120,17 @@ fn start_daemon() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let laptop = LaptopLedData::get_data();
|
let laptop = LaptopLedData::get_data();
|
||||||
let aura_config = AuraConfig::load(&laptop);
|
let aura_config = AuraConfig::load(&laptop);
|
||||||
match CtrlKbdBacklight::new(laptop, aura_config) {
|
match CtrlKbdLed::new(laptop, aura_config) {
|
||||||
Ok(ctrl) => {
|
Ok(ctrl) => {
|
||||||
let tmp = Arc::new(Mutex::new(ctrl));
|
let inner = Arc::new(Mutex::new(ctrl));
|
||||||
DbusKbdBacklight::new(tmp.clone()).add_to_server(&mut object_server);
|
|
||||||
let task = CtrlKbdBacklightTask(tmp);
|
let mut reload = CtrlKbdLedReloader(inner.clone());
|
||||||
|
reload
|
||||||
|
.reload()
|
||||||
|
.unwrap_or_else(|err| warn!("Keyboard LED control: {}", err));
|
||||||
|
|
||||||
|
CtrlKbdLedZbus::new(inner.clone()).add_to_server(&mut object_server);
|
||||||
|
let task = CtrlKbdLedTask(inner);
|
||||||
tasks.push(Box::new(task));
|
tasks.push(Box::new(task));
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user