rog-platform: add CPU and GPU tunings

rog-platform: add tunables to supported dat

Anime: fixes to how some power options work
This commit is contained in:
Luke D. Jones
2023-11-16 21:31:15 +13:00
parent b9c2d929b3
commit fa043adc99
10 changed files with 201 additions and 72 deletions

View File

@@ -120,6 +120,7 @@ pub struct AnimeConfig {
pub off_when_unplugged: bool,
pub off_when_suspended: bool,
pub off_when_lid_closed: bool,
pub brightness_on_battery: Brightness,
pub builtin_anims: Animations,
}
@@ -138,6 +139,7 @@ impl Default for AnimeConfig {
off_when_unplugged: true,
off_when_suspended: true,
off_when_lid_closed: true,
brightness_on_battery: Brightness::Low,
builtin_anims: Animations::default(),
}
}
@@ -169,6 +171,7 @@ impl From<&AnimeConfig> for DeviceState {
off_when_unplugged: config.off_when_unplugged,
off_when_suspended: config.off_when_suspended,
off_when_lid_closed: config.off_when_lid_closed,
brightness_on_battery: config.brightness_on_battery,
}
}
}

View File

@@ -4,19 +4,32 @@ use std::sync::Arc;
use async_trait::async_trait;
use config_traits::StdConfig;
use log::warn;
use logind_zbus::manager::ManagerProxy;
use rog_anime::usb::{
pkt_set_brightness, pkt_set_builtin_animations, pkt_set_enable_display,
pkt_set_enable_powersave_anim, AnimAwake, AnimBooting, AnimShutdown, AnimSleeping, Brightness,
};
use rog_anime::{AnimeDataBuffer, DeviceState};
use zbus::export::futures_util::lock::Mutex;
use zbus::{dbus_interface, Connection, SignalContext};
use zbus::{dbus_interface, CacheProperties, Connection, SignalContext};
use super::CtrlAnime;
use crate::error::RogError;
pub(super) const ZBUS_PATH: &str = "/org/asuslinux/Anime";
async fn get_logind_manager<'a>() -> ManagerProxy<'a> {
let connection = Connection::system()
.await
.expect("Controller could not create dbus connection");
ManagerProxy::builder(&connection)
.cache_properties(CacheProperties::No)
.build()
.await
.expect("Controller could not create ManagerProxy")
}
#[derive(Clone)]
pub struct CtrlAnimeZbus(pub Arc<Mutex<CtrlAnime>>);
@@ -176,6 +189,16 @@ impl CtrlAnimeZbus {
enabled: bool,
) {
let mut lock = self.0.lock().await;
let manager = get_logind_manager().await;
let pow = manager.on_external_power().await.unwrap_or_default();
lock.node
.write_bytes(&pkt_set_enable_display(!pow && !enabled))
.map_err(|err| {
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
})
.ok();
lock.config.off_when_unplugged = enabled;
lock.config.write();
Self::notify_device_state(&ctxt, DeviceState::from(&lock.config))
@@ -204,6 +227,16 @@ impl CtrlAnimeZbus {
enabled: bool,
) {
let mut lock = self.0.lock().await;
let manager = get_logind_manager().await;
let lid = manager.lid_closed().await.unwrap_or_default();
lock.node
.write_bytes(&pkt_set_enable_display(lid && !enabled))
.map_err(|err| {
warn!("create_sys_event_tasks::off_when_lid_closed {}", err);
})
.ok();
lock.config.off_when_lid_closed = enabled;
lock.config.write();
Self::notify_device_state(&ctxt, DeviceState::from(&lock.config))
@@ -225,15 +258,7 @@ impl CtrlAnimeZbus {
// #[dbus_interface(property)]
async fn device_state(&self) -> DeviceState {
let lock = self.0.lock().await;
DeviceState {
display_enabled: lock.config.display_enabled,
display_brightness: lock.config.display_brightness,
builtin_anims_enabled: lock.config.builtin_anims_enabled,
builtin_anims: lock.config.builtin_anims,
off_when_unplugged: lock.config.off_when_unplugged,
off_when_suspended: lock.config.off_when_suspended,
off_when_lid_closed: lock.config.off_when_lid_closed,
}
DeviceState::from(&lock.config)
}
/// Notify listeners of the status of AniMe LED power and factory
@@ -320,6 +345,13 @@ impl crate::CtrlTask for CtrlAnimeZbus {
warn!("create_sys_event_tasks::off_when_unplugged {}", err);
})
.ok();
} else {
lock.node
.write_bytes(&pkt_set_brightness(lock.config.brightness_on_battery))
.map_err(|err| {
warn!("create_sys_event_tasks::off_when_unplugged {}", err);
})
.ok();
}
}
},

View File

@@ -8,7 +8,7 @@ use async_trait::async_trait;
use config_traits::StdConfig;
use log::{info, warn};
use rog_platform::platform::{AsusPlatform, GpuMode};
use rog_platform::supported::RogBiosSupportedFunctions;
use rog_platform::supported::PlatformSupportedFunctions;
use zbus::export::futures_util::lock::Mutex;
use zbus::{dbus_interface, Connection, SignalContext};
@@ -27,31 +27,11 @@ pub struct CtrlPlatform {
}
impl GetSupported for CtrlPlatform {
type A = RogBiosSupportedFunctions;
type A = PlatformSupportedFunctions;
fn get_supported() -> Self::A {
let mut panel_overdrive = false;
let mut mini_led_mode = false;
let mut dgpu_disable = false;
let mut egpu_enable = false;
let mut gpu_mux = false;
if let Ok(platform) = AsusPlatform::new() {
panel_overdrive = platform.has_panel_od();
mini_led_mode = platform.has_mini_led_mode();
dgpu_disable = platform.has_dgpu_disable();
egpu_enable = platform.has_egpu_enable();
gpu_mux = platform.has_gpu_mux_mode();
}
RogBiosSupportedFunctions {
post_sound: Path::new(ASUS_POST_LOGO_SOUND).exists(),
gpu_mux,
panel_overdrive,
mini_led_mode,
dgpu_disable,
egpu_enable,
}
let platform = AsusPlatform::new().unwrap_or_default();
platform.into()
}
}