Cleanup after changes from Platform dbus rework

This commit is contained in:
Luke D. Jones
2023-11-18 22:36:55 +13:00
parent 1f696508e7
commit f6e4cc0626
9 changed files with 143 additions and 101 deletions

1
Cargo.lock generated
View File

@@ -225,6 +225,7 @@ dependencies = [
"config-traits",
"dmi_id",
"env_logger",
"futures-lite",
"log",
"logind-zbus",
"rog_anime",

View File

@@ -772,10 +772,10 @@ fn handle_bios_option(
}
if let Some(opt) = cmd.post_sound_set {
dbus.proxies().rog_bios().set_post_boot_sound(opt)?;
dbus.proxies().rog_bios().set_post_animation_sound(opt)?;
}
if cmd.post_sound_get {
let res = dbus.proxies().rog_bios().post_boot_sound()? == 1;
let res = dbus.proxies().rog_bios().post_animation_sound()?;
println!("Bios POST sound on: {}", res);
}

View File

@@ -240,7 +240,7 @@ impl CtrlPlatform {
platform_get_value!(self, egpu_enable, "egpu_enable")
}
/// ***************************************************************************
/// ************************************************************************
#[dbus_interface(property)]
async fn ppt_pl1_spl(&self) -> Result<u8, FdoErr> {
platform_get_value_if_some!(self, ppt_pl1_spl, "ppt_pl1_spl", 5)

View File

@@ -39,13 +39,13 @@ pub struct BiosState {
impl BiosState {
pub fn new(supported: &SupportedFunctions, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
Ok(Self {
post_sound: if supported.rog_bios_ctrl.post_sound {
dbus.proxies().rog_bios().post_boot_sound()? != 0
post_sound: if supported.rog_bios_ctrl.post_animation_sound {
dbus.proxies().rog_bios().post_animation_sound()?
} else {
false
},
dedicated_gfx: if supported.rog_bios_ctrl.gpu_mux {
dbus.proxies().rog_bios().gpu_mux_mode()?
GpuMode::from(dbus.proxies().rog_bios().gpu_mux_mode()?)
} else {
GpuMode::NotSupported
},

View File

@@ -325,7 +325,7 @@ impl ROGTray {
let mut reboot_required = false;
if let Ok(mode) = gfx_dbus.gpu_mux_mode() {
let mode = match mode {
let mode = match GpuMode::from(mode) {
GpuMode::Discrete => GfxMode::AsusMuxDgpu,
_ => GfxMode::Hybrid,
};

View File

@@ -37,11 +37,11 @@ static mut POWER_BAT_CMD: Option<Command> = None;
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
pub struct EnabledNotifications {
pub receive_notify_post_boot_sound: bool,
pub receive_notify_panel_od: bool,
pub receive_notify_mini_led_mode: bool,
pub receive_notify_dgpu_disable: bool,
pub receive_notify_egpu_enable: bool,
pub receive_post_animation_sound_changed: bool,
pub receive_panel_od_changed: bool,
pub receive_mini_led_mode_changed: bool,
pub receive_dgpu_disable_changed: bool,
pub receive_egpu_enable_changed: bool,
pub receive_notify_gpu_mux_mode: bool,
pub receive_notify_charge_control_end_threshold: bool,
pub receive_notify_mains_online: bool,
@@ -57,11 +57,11 @@ pub struct EnabledNotifications {
impl Default for EnabledNotifications {
fn default() -> Self {
Self {
receive_notify_post_boot_sound: false,
receive_notify_panel_od: true,
receive_notify_mini_led_mode: true,
receive_notify_dgpu_disable: true,
receive_notify_egpu_enable: true,
receive_post_animation_sound_changed: false,
receive_panel_od_changed: true,
receive_mini_led_mode_changed: true,
receive_dgpu_disable_changed: true,
receive_egpu_enable_changed: true,
receive_notify_gpu_mux_mode: true,
receive_notify_charge_control_end_threshold: true,
receive_notify_mains_online: false,
@@ -127,6 +127,49 @@ macro_rules! recv_notif {
};
}
macro_rules! recv_changed {
($proxy:ident,
$signal:ident,
$last_notif:ident,
$notif_enabled:ident,
$page_states:ident,
($($args: tt)*),
// ($($out_arg:tt)+),
$msg:literal,
$notifier:ident) => {
let notifs_enabled1 = $notif_enabled.clone();
let page_states1 = $page_states.clone();
tokio::spawn(async move {
let conn = zbus::Connection::system().await.map_err(|e| {
log::error!("zbus signal: {}: {e}", stringify!($signal));
e
}).unwrap();
let proxy = $proxy::new(&conn).await.map_err(|e| {
log::error!("zbus signal: {}: {e}", stringify!($signal));
e
}).unwrap();
info!("Started zbus signal thread: {}", stringify!($signal));
while let Some(e) = proxy.$signal().await.next().await {
if let Ok(out) = e.get().await {
if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.$signal {
trace!("zbus signal {}", stringify!($signal));
$notifier($msg, &out).ok();
}
}
if let Ok(mut lock) = page_states1.lock() {
lock.$($args)+ = out;
lock.set_notified();
}
}
sleep(Duration::from_millis(500)).await;
}
});
};
}
pub fn start_notifications(
config: &Config,
page_states: &Arc<Mutex<SystemState>>,
@@ -157,62 +200,57 @@ pub fn start_notifications(
}
// BIOS notif
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_post_boot_sound,
receive_post_animation_sound_changed,
last_notification,
enabled_notifications,
page_states,
(bios.post_sound),
(on),
"BIOS Post sound",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_panel_od,
receive_panel_od_changed,
last_notification,
enabled_notifications,
page_states,
(bios.panel_overdrive),
(overdrive),
"Panel Overdrive enabled:",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_mini_led_mode,
receive_mini_led_mode_changed,
last_notification,
enabled_notifications,
page_states,
(bios.mini_led_mode),
(on),
"MiniLED mode enabled:",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_dgpu_disable,
receive_dgpu_disable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.dgpu_disable),
(disable),
"BIOS dGPU disabled",
do_notification
);
recv_notif!(
recv_changed!(
RogBiosProxy,
receive_notify_egpu_enable,
receive_egpu_enable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.egpu_enable),
(enable),
"BIOS eGPU enabled",
do_notification
);
@@ -314,7 +352,7 @@ pub fn start_notifications(
e
})
.unwrap();
if let Ok(mut p) = proxy.receive_device_state().await {
if let Ok(mut p) = proxy.receive_notify_device_state().await {
info!("Started zbus signal thread: receive_device_state");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
@@ -345,25 +383,23 @@ pub fn start_notifications(
let mut actual_mux_mode = GpuMode::Error;
if let Ok(mode) = proxy.gpu_mux_mode().await {
actual_mux_mode = mode;
actual_mux_mode = GpuMode::from(mode);
}
if let Ok(mut p) = proxy.receive_notify_gpu_mux_mode().await {
info!("Started zbus signal thread: receive_notify_gpu_mux_mode");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
if out.mode == actual_mux_mode {
continue;
}
if let Ok(mut lock) = page_states1.lock() {
lock.bios.dedicated_gfx = out.mode;
lock.set_notified();
}
do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &out.mode)
.ok();
info!("Started zbus signal thread: receive_notify_gpu_mux_mode");
while let Some(e) = proxy.receive_gpu_mux_mode_changed().await.next().await {
if let Ok(out) = e.get().await {
let mode = GpuMode::from(out);
if mode == actual_mux_mode {
continue;
}
if let Ok(mut lock) = page_states1.lock() {
lock.bios.dedicated_gfx = mode;
lock.set_notified();
}
do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &mode).ok();
}
};
}
});
if let Ok(lock) = page_states.try_lock() {

View File

@@ -51,13 +51,13 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_dgpu_disable,
&mut enabled_notifications.receive_dgpu_disable_changed,
"Enable dGPU disablement notification",
)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_egpu_enable,
&mut enabled_notifications.receive_egpu_enable_changed,
"Enable eGPU enablement notification",
)
.clicked()
@@ -81,19 +81,19 @@ pub fn app_settings(config: &mut Config, states: &mut SystemState, ui: &mut Ui)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_panel_od,
&mut enabled_notifications.receive_panel_od_changed,
"Enable panel overdrive notification",
)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_mini_led_mode,
&mut enabled_notifications.receive_mini_led_mode_changed,
"Enable MiniLED mode notification",
)
.clicked()
|| ui
.checkbox(
&mut enabled_notifications.receive_notify_post_boot_sound,
&mut enabled_notifications.receive_post_animation_sound_changed,
"Enable BIOS post sound notification",
)
.clicked();

View File

@@ -55,7 +55,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
.ok();
}
if supported.rog_bios_ctrl.post_sound
if supported.rog_bios_ctrl.post_animation_sound
&& ui
.add(egui::Checkbox::new(
&mut states.bios.post_sound,
@@ -67,7 +67,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
.asus_dbus
.proxies()
.rog_bios()
.set_post_boot_sound(states.bios.post_sound)
.set_post_animation_sound(states.bios.post_sound)
.map_err(|err| {
states.error = Some(err.to_string());
})
@@ -118,7 +118,7 @@ pub fn rog_bios_group(supported: &SupportedFunctions, states: &mut SystemState,
let mut reboot_required = false;
if let Ok(mode) = states.asus_dbus.proxies().rog_bios().gpu_mux_mode() {
reboot_required = mode != states.bios.dedicated_gfx;
reboot_required = GpuMode::from(mode) != states.bios.dedicated_gfx;
}
ui.group(|ui| {

View File

@@ -28,64 +28,69 @@ use zbus::dbus_proxy;
default_path = "/org/asuslinux/Platform"
)]
trait RogBios {
/// DgpuDisable method
/// SupportedProperties method
fn supported_properties(&self) -> zbus::Result<Vec<String>>;
/// DgpuDisable property
#[dbus_proxy(property)]
fn dgpu_disable(&self) -> zbus::Result<bool>;
/// EgpuEnable method
/// EgpuEnable property
#[dbus_proxy(property)]
fn egpu_enable(&self) -> zbus::Result<bool>;
/// GpuMuxMode method
fn gpu_mux_mode(&self) -> zbus::Result<GpuMode>;
/// GpuMuxMode property
#[dbus_proxy(property)]
fn gpu_mux_mode(&self) -> zbus::Result<u8>;
fn set_gpu_mux_mode(&self, value: GpuMode) -> zbus::Result<()>;
/// PanelOd method
fn panel_od(&self) -> zbus::Result<bool>;
/// MiniLedMode method
/// MiniLedMode property
#[dbus_proxy(property)]
fn mini_led_mode(&self) -> zbus::Result<bool>;
fn set_mini_led_mode(&self, value: bool) -> zbus::Result<()>;
/// PostBootSound method
fn post_boot_sound(&self) -> zbus::Result<i16>;
/// NvDynamicBoost property
#[dbus_proxy(property)]
fn nv_dynamic_boost(&self) -> zbus::Result<u8>;
fn set_nv_dynamic_boost(&self, value: u8) -> zbus::Result<()>;
/// SetDgpuDisable method
fn set_dgpu_disable(&self, disable: bool) -> zbus::Result<()>;
/// NvTempTarget property
#[dbus_proxy(property)]
fn nv_temp_target(&self) -> zbus::Result<u8>;
fn set_nv_temp_target(&self, value: u8) -> zbus::Result<()>;
/// SetEgpuEnable method
fn set_egpu_enable(&self, enable: bool) -> zbus::Result<()>;
/// PanelOd property
#[dbus_proxy(property)]
fn panel_od(&self) -> zbus::Result<bool>;
fn set_panel_od(&self, value: bool) -> zbus::Result<()>;
/// SetGpuMuxMode method
fn set_gpu_mux_mode(&self, mode: GpuMode) -> zbus::Result<()>;
/// PostAnimationSound property
#[dbus_proxy(property)]
fn post_animation_sound(&self) -> zbus::Result<bool>;
fn set_post_animation_sound(&self, value: bool) -> zbus::Result<()>;
/// SetPanelOd method
fn set_panel_od(&self, overdrive: bool) -> zbus::Result<()>;
/// PptApuSppt property
#[dbus_proxy(property)]
fn ppt_apu_sppt(&self) -> zbus::Result<u8>;
fn set_ppt_apu_sppt(&self, value: u8) -> zbus::Result<()>;
/// SetminiLedMode
fn set_mini_led_mode(&self, on: bool) -> zbus::Result<()>;
/// PptFppt property
#[dbus_proxy(property)]
fn ppt_fppt(&self) -> zbus::Result<u8>;
fn set_ppt_fppt(&self, value: u8) -> zbus::Result<()>;
/// SetPostBootSound method
fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>;
/// PptPl1Spl property
#[dbus_proxy(property)]
fn ppt_pl1_spl(&self) -> zbus::Result<u8>;
fn set_ppt_pl1_spl(&self, value: u8) -> zbus::Result<()>;
/// NotifyDgpuDisable signal
#[dbus_proxy(signal)]
fn notify_dgpu_disable(&self, disable: bool) -> zbus::Result<()>;
/// PptPl2Sppt property
#[dbus_proxy(property)]
fn ppt_pl2_sppt(&self) -> zbus::Result<u8>;
fn set_ppt_pl2_sppt(&self, value: u8) -> zbus::Result<()>;
/// NotifyEgpuEnable signal
#[dbus_proxy(signal)]
fn notify_egpu_enable(&self, enable: bool) -> zbus::Result<()>;
/// NotifyGpuMuxMode signal
#[dbus_proxy(signal)]
fn notify_gpu_mux_mode(&self, mode: GpuMode) -> zbus::Result<()>;
/// NotifyPanelOd signal
#[dbus_proxy(signal)]
fn notify_panel_od(&self, overdrive: bool) -> zbus::Result<()>;
/// NotifyMiniLedMode signal
#[dbus_proxy(signal)]
fn notify_mini_led_mode(&self, on: bool) -> zbus::Result<()>;
/// NotifyPostBootSound signal
#[inline]
#[dbus_proxy(signal)]
fn notify_post_boot_sound(&self, on: bool) -> zbus::Result<()>;
/// PptPlatformSppt property
#[dbus_proxy(property)]
fn ppt_platform_sppt(&self) -> zbus::Result<u8>;
fn set_ppt_platform_sppt(&self, value: u8) -> zbus::Result<()>;
}