mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Refined AC monitoring
This commit is contained in:
@@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- `NotifyEgpuEnable`
|
- `NotifyEgpuEnable`
|
||||||
- `MainsOnline` (This is AC, check if plugged in or not)
|
- `MainsOnline` (This is AC, check if plugged in or not)
|
||||||
- `NotifyMainsOnline`
|
- `NotifyMainsOnline`
|
||||||
|
- `nvidia-powerd.service` will now enable or disable depending on the AC power state
|
||||||
|
and on resume/boot (hybrid boot). It has been proven that this nvidia daemon can be
|
||||||
|
problematic when on battery, not allowing the dgpu to suspend within decent time and
|
||||||
|
sometimes blocking it completely.
|
||||||
### Changed
|
### Changed
|
||||||
- Use loops to ensure that mutex is gained for LED changes.
|
- Use loops to ensure that mutex is gained for LED changes.
|
||||||
- asusctl now uses tokio for async runtime. This helps simplify some code.
|
- asusctl now uses tokio for async runtime. This helps simplify some code.
|
||||||
@@ -30,7 +34,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- `ChargeControlEndThreshold`
|
- `ChargeControlEndThreshold`
|
||||||
- `SetChargeControlEndThreshold`
|
- `SetChargeControlEndThreshold`
|
||||||
- `NotifyChargeControlEndThreshold`
|
- `NotifyChargeControlEndThreshold`
|
||||||
- `PanelOd` (form PanelOverdrive)
|
- DBUS: all panel overdrive methods renamed to:
|
||||||
|
- `PanelOd` (from PanelOverdrive)
|
||||||
- `SetPanelOd`
|
- `SetPanelOd`
|
||||||
- `NotifyPanelOd`
|
- `NotifyPanelOd`
|
||||||
- Path `/org/asuslinux/Charge` changed to `/org/asuslinux/Power`
|
- Path `/org/asuslinux/Charge` changed to `/org/asuslinux/Power`
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::systemd::{do_systemd_unit_action, SystemdUnitAction};
|
||||||
use crate::{config::Config, error::RogError, GetSupported};
|
use crate::{config::Config, error::RogError, GetSupported};
|
||||||
use crate::{task_watch_item, CtrlTask};
|
use crate::{task_watch_item, CtrlTask};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@@ -5,13 +6,15 @@ use log::{info, warn};
|
|||||||
use rog_platform::power::AsusPower;
|
use rog_platform::power::AsusPower;
|
||||||
use rog_platform::supported::ChargeSupportedFunctions;
|
use rog_platform::supported::ChargeSupportedFunctions;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::sleep;
|
||||||
use zbus::dbus_interface;
|
use zbus::dbus_interface;
|
||||||
use zbus::export::futures_util::lock::Mutex;
|
use zbus::export::futures_util::lock::Mutex;
|
||||||
use zbus::export::futures_util::StreamExt;
|
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
use zbus::SignalContext;
|
use zbus::SignalContext;
|
||||||
|
|
||||||
const ZBUS_PATH: &str = "/org/asuslinux/Power";
|
const ZBUS_PATH: &str = "/org/asuslinux/Power";
|
||||||
|
const NVIDIA_POWERD: &str = "nvidia-powerd.service";
|
||||||
|
|
||||||
impl GetSupported for CtrlPower {
|
impl GetSupported for CtrlPower {
|
||||||
type A = ChargeSupportedFunctions;
|
type A = ChargeSupportedFunctions;
|
||||||
@@ -163,6 +166,16 @@ impl CtrlTask for CtrlPower {
|
|||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
if let Ok(value) = power1.power.get_online() {
|
||||||
|
let action = if value == 1 {
|
||||||
|
SystemdUnitAction::Restart
|
||||||
|
} else {
|
||||||
|
SystemdUnitAction::Stop
|
||||||
|
};
|
||||||
|
if do_systemd_unit_action(action, NVIDIA_POWERD).is_ok() {
|
||||||
|
info!("CtrlPower task: did {action:?} on {NVIDIA_POWERD}");
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
move || {},
|
move || {},
|
||||||
move || {
|
move || {
|
||||||
@@ -176,6 +189,16 @@ impl CtrlTask for CtrlPower {
|
|||||||
})
|
})
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
|
if let Ok(value) = power2.power.get_online() {
|
||||||
|
let action = if value == 1 {
|
||||||
|
SystemdUnitAction::Restart
|
||||||
|
} else {
|
||||||
|
SystemdUnitAction::Stop
|
||||||
|
};
|
||||||
|
if do_systemd_unit_action(action, NVIDIA_POWERD).is_ok() {
|
||||||
|
info!("CtrlPower task: did {action:?} on {NVIDIA_POWERD}");
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -184,25 +207,32 @@ impl CtrlTask for CtrlPower {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let ctrl = self.clone();
|
let ctrl = self.clone();
|
||||||
match ctrl.power.monitor_online() {
|
dbg!("CtrlPower");
|
||||||
Ok(mut watch) => {
|
tokio::spawn(async move {
|
||||||
tokio::spawn(async move {
|
let mut online = 10;
|
||||||
let mut buffer = [0; 32];
|
loop {
|
||||||
watch
|
if let Ok(value) = ctrl.power.get_online() {
|
||||||
.event_stream(&mut buffer)
|
if online != value {
|
||||||
.unwrap()
|
online = value;
|
||||||
.for_each(|_| async {
|
let action = if value == 1 {
|
||||||
if let Ok(value) = ctrl.power.get_online() {
|
SystemdUnitAction::Restart
|
||||||
Self::notify_mains_online(&signal_ctxt, value == 1)
|
} else {
|
||||||
.await
|
SystemdUnitAction::Stop
|
||||||
.unwrap();
|
};
|
||||||
}
|
if do_systemd_unit_action(action, NVIDIA_POWERD).is_ok() {
|
||||||
})
|
info!("CtrlPower task: did {action:?} on {NVIDIA_POWERD}");
|
||||||
.await;
|
}
|
||||||
});
|
|
||||||
|
Self::notify_mains_online(&signal_ctxt, value == 1)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// The inotify doesn't pick up events when the kernel changes internal value
|
||||||
|
// so we need to watch it with a thread and sleep unfortunately
|
||||||
|
sleep(Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
Err(e) => info!("inotify watch failed: {}", e),
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ pub enum RogError {
|
|||||||
NoAuraNode,
|
NoAuraNode,
|
||||||
Anime(AnimeError),
|
Anime(AnimeError),
|
||||||
Platform(PlatformError),
|
Platform(PlatformError),
|
||||||
|
SystemdUnitAction(String),
|
||||||
|
SystemdUnitWaitTimeout(String),
|
||||||
|
Command(String, std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for RogError {
|
impl fmt::Display for RogError {
|
||||||
@@ -60,6 +63,17 @@ impl fmt::Display for RogError {
|
|||||||
RogError::NoAuraNode => write!(f, "No Aura keyboard node found"),
|
RogError::NoAuraNode => write!(f, "No Aura keyboard node found"),
|
||||||
RogError::Anime(deets) => write!(f, "AniMe Matrix error: {}", deets),
|
RogError::Anime(deets) => write!(f, "AniMe Matrix error: {}", deets),
|
||||||
RogError::Platform(deets) => write!(f, "Asus Platform error: {}", deets),
|
RogError::Platform(deets) => write!(f, "Asus Platform error: {}", deets),
|
||||||
|
RogError::SystemdUnitAction(action) => {
|
||||||
|
write!(f, "systemd unit action {} failed", action)
|
||||||
|
}
|
||||||
|
RogError::SystemdUnitWaitTimeout(state) => {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"Timed out waiting for systemd unit change {} state",
|
||||||
|
state
|
||||||
|
)
|
||||||
|
}
|
||||||
|
RogError::Command(func, error) => write!(f, "Command exec error: {}: {}", func, error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ pub mod ctrl_profiles;
|
|||||||
/// Laptop matching to determine capabilities
|
/// Laptop matching to determine capabilities
|
||||||
pub mod laptops;
|
pub mod laptops;
|
||||||
|
|
||||||
|
pub mod systemd;
|
||||||
|
|
||||||
/// Fetch all supported functions for the laptop
|
/// Fetch all supported functions for the laptop
|
||||||
pub mod ctrl_supported;
|
pub mod ctrl_supported;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user