Major cleanup of older gui state code

This commit is contained in:
Luke D. Jones
2024-04-05 20:19:07 +13:00
parent ca0d8bda4b
commit 4701c019a8
24 changed files with 238 additions and 948 deletions

View File

@@ -5,10 +5,12 @@ use std::process::exit;
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::{AnimeDiagonal, AnimeType}; use rog_anime::{AnimeDiagonal, AnimeType};
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use zbus::blocking::Connection;
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() != 3 { if args.len() != 3 {
@@ -26,11 +28,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let anime_type = get_anime_type()?; let anime_type = get_anime_type()?;
client proxy.write(matrix.into_data_buffer(anime_type)?).unwrap();
.proxies()
.anime()
.write(matrix.into_data_buffer(anime_type)?)
.unwrap();
Ok(()) Ok(())
} }

View File

@@ -3,7 +3,8 @@ use std::time::Duration;
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::{AnimeDiagonal, AnimeType}; use rog_anime::{AnimeDiagonal, AnimeType};
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use zbus::blocking::Connection;
// In usable data: // In usable data:
// Top row start at 1, ends at 32 // Top row start at 1, ends at 32
@@ -11,7 +12,8 @@ use rog_dbus::RogDbusClientBlocking;
// 74w x 36h diagonal used by the windows app // 74w x 36h diagonal used by the windows app
fn main() { fn main() {
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
for step in (2..50).rev() { for step in (2..50).rev() {
let mut matrix = AnimeDiagonal::new(AnimeType::GA401, None); let mut matrix = AnimeDiagonal::new(AnimeType::GA401, None);
@@ -28,9 +30,7 @@ fn main() {
} }
let anime_type = get_anime_type().unwrap(); let anime_type = get_anime_type().unwrap();
client proxy
.proxies()
.anime()
.write(matrix.into_data_buffer(anime_type).unwrap()) .write(matrix.into_data_buffer(anime_type).unwrap())
.unwrap(); .unwrap();
sleep(Duration::from_millis(300)); sleep(Duration::from_millis(300));

View File

@@ -4,10 +4,12 @@ use std::thread::sleep;
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::{ActionData, ActionLoader, Sequences}; use rog_anime::{ActionData, ActionLoader, Sequences};
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use zbus::blocking::Connection;
fn main() { fn main() {
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() != 3 { if args.len() != 3 {
@@ -33,11 +35,7 @@ fn main() {
for action in seq.iter() { for action in seq.iter() {
if let ActionData::Animation(frames) = action { if let ActionData::Animation(frames) = action {
for frame in frames.frames() { for frame in frames.frames() {
client proxy.write(frame.frame().clone()).unwrap();
.proxies()
.anime()
.write(frame.frame().clone())
.unwrap();
sleep(frame.delay()); sleep(frame.delay());
} }
} }

View File

@@ -2,7 +2,8 @@ use std::convert::TryFrom;
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::{AnimeDataBuffer, AnimeGrid}; use rog_anime::{AnimeDataBuffer, AnimeGrid};
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use zbus::blocking::Connection;
// In usable data: // In usable data:
// Top row start at 1, ends at 32 // Top row start at 1, ends at 32
@@ -10,7 +11,9 @@ use rog_dbus::RogDbusClientBlocking;
// 74w x 36h diagonal used by the windows app // 74w x 36h diagonal used by the windows app
fn main() { fn main() {
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
let anime_type = get_anime_type().unwrap(); let anime_type = get_anime_type().unwrap();
let mut matrix = AnimeGrid::new(anime_type); let mut matrix = AnimeGrid::new(anime_type);
let tmp = matrix.get_mut(); let tmp = matrix.get_mut();
@@ -43,5 +46,5 @@ fn main() {
let matrix = <AnimeDataBuffer>::try_from(matrix).unwrap(); let matrix = <AnimeDataBuffer>::try_from(matrix).unwrap();
client.proxies().anime().write(matrix).unwrap(); proxy.write(matrix).unwrap();
} }

View File

@@ -1,12 +1,14 @@
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::AnimeDataBuffer; use rog_anime::AnimeDataBuffer;
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use zbus::blocking::Connection;
// In usable data: // In usable data:
// Top row start at 1, ends at 32 // Top row start at 1, ends at 32
fn main() { fn main() {
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
let anime_type = get_anime_type().unwrap(); let anime_type = get_anime_type().unwrap();
let mut matrix = AnimeDataBuffer::new(anime_type); let mut matrix = AnimeDataBuffer::new(anime_type);
matrix.data_mut()[1] = 100; // start = 1 matrix.data_mut()[1] = 100; // start = 1
@@ -127,5 +129,5 @@ fn main() {
matrix.data_mut()[1244] = 100; // end matrix.data_mut()[1244] = 100; // end
println!("{:?}", &matrix); println!("{:?}", &matrix);
client.proxies().anime().write(matrix).unwrap(); proxy.write(matrix).unwrap();
} }

View File

@@ -6,10 +6,12 @@ use std::process::exit;
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2}; use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2};
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use zbus::blocking::Connection;
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() != 7 { if args.len() != 7 {
@@ -31,11 +33,7 @@ fn main() -> Result<(), Box<dyn Error>> {
anime_type, anime_type,
)?; )?;
client proxy.write(<AnimeDataBuffer>::try_from(&matrix)?).unwrap();
.proxies()
.anime()
.write(<AnimeDataBuffer>::try_from(&matrix)?)
.unwrap();
Ok(()) Ok(())
} }

View File

@@ -9,10 +9,12 @@ use std::time::Duration;
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2}; use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2};
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use zbus::blocking::Connection;
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AnimeProxyBlocking::new(&conn).unwrap();
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
if args.len() != 7 { if args.len() != 7 {
@@ -41,11 +43,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
matrix.update(); matrix.update();
client proxy.write(<AnimeDataBuffer>::try_from(&matrix)?).unwrap();
.proxies()
.anime()
.write(<AnimeDataBuffer>::try_from(&matrix)?)
.unwrap();
sleep(Duration::from_micros(500)); sleep(Duration::from_micros(500));
} }
} }

View File

@@ -5,12 +5,14 @@ use rog_aura::advanced::LedCode;
use rog_aura::effects::{AdvancedEffects, Effect}; use rog_aura::effects::{AdvancedEffects, Effect};
use rog_aura::layouts::KeyLayout; use rog_aura::layouts::KeyLayout;
use rog_aura::Colour; use rog_aura::Colour;
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_aura::AuraProxyBlocking;
use zbus::blocking::Connection;
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
let layout = KeyLayout::default_layout(); let layout = KeyLayout::default_layout();
let (client, _) = RogDbusClientBlocking::new().unwrap(); let conn = Connection::system().unwrap();
let proxy = AuraProxyBlocking::new(&conn).unwrap();
let mut seq = AdvancedEffects::new(true); let mut seq = AdvancedEffects::new(true);
@@ -62,7 +64,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
seq.next_state(&layout); seq.next_state(&layout);
let packets = seq.create_packets(); let packets = seq.create_packets();
client.proxies().aura().direct_addressing_raw(packets)?; proxy.direct_addressing_raw(packets)?;
std::thread::sleep(std::time::Duration::from_millis(33)); std::thread::sleep(std::time::Duration::from_millis(33));
} }
} }

View File

@@ -15,10 +15,13 @@ use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage,
use rog_aura::power::KbAuraPowerState; use rog_aura::power::KbAuraPowerState;
use rog_aura::usb::{AuraDevRog1, AuraDevTuf, AuraDevice, AuraPowerDev}; use rog_aura::usb::{AuraDevRog1, AuraDevTuf, AuraDevice, AuraPowerDev};
use rog_aura::{self, AuraEffect}; use rog_aura::{self, AuraEffect};
use rog_dbus::zbus_anime::AnimeProxyBlocking;
use rog_dbus::zbus_aura::AuraProxyBlocking; use rog_dbus::zbus_aura::AuraProxyBlocking;
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_fan_curves::FanCurvesProxyBlocking;
use rog_dbus::zbus_platform::PlatformProxyBlocking;
use rog_platform::platform::{GpuMode, Properties, ThrottlePolicy}; use rog_platform::platform::{GpuMode, Properties, ThrottlePolicy};
use rog_profiles::error::ProfileError; use rog_profiles::error::ProfileError;
use zbus::blocking::Connection;
use crate::aura_cli::{AuraPowerStates, LedBrightness}; use crate::aura_cli::{AuraPowerStates, LedBrightness};
use crate::cli_opts::*; use crate::cli_opts::*;
@@ -44,13 +47,21 @@ fn main() {
} }
}; };
if let Ok((dbus, _)) = RogDbusClientBlocking::new().map_err(|e| { let conn = Connection::system().unwrap();
if let Ok(platform_proxy) = PlatformProxyBlocking::new(&conn).map_err(|e| {
check_service("asusd"); check_service("asusd");
println!("\nError: {e}\n"); println!("\nError: {e}\n");
print_info(); print_info();
}) { }) {
let supported_properties = dbus.proxies().platform().supported_properties().unwrap(); let self_version = env!("CARGO_PKG_VERSION");
let supported_interfaces = dbus.proxies().platform().supported_interfaces().unwrap(); let asusd_version = platform_proxy.version().unwrap();
if asusd_version != self_version {
println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}");
return;
}
let supported_properties = platform_proxy.supported_properties().unwrap();
let supported_interfaces = platform_proxy.supported_interfaces().unwrap();
if parsed.version { if parsed.version {
println!("asusctl v{}", env!("CARGO_PKG_VERSION")); println!("asusctl v{}", env!("CARGO_PKG_VERSION"));
@@ -58,7 +69,7 @@ fn main() {
print_info(); print_info();
} }
if let Err(err) = do_parsed(&parsed, &supported_interfaces, &supported_properties, &dbus) { if let Err(err) = do_parsed(&parsed, &supported_interfaces, &supported_properties, conn) {
print_error_help(&*err, &supported_interfaces, &supported_properties); print_error_help(&*err, &supported_interfaces, &supported_properties);
} }
} }
@@ -143,19 +154,23 @@ fn do_parsed(
parsed: &CliStart, parsed: &CliStart,
supported_interfaces: &[String], supported_interfaces: &[String],
supported_properties: &[Properties], supported_properties: &[Properties],
dbus: &RogDbusClientBlocking<'_>, conn: Connection,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
match &parsed.command { match &parsed.command {
Some(CliCommand::LedMode(mode)) => handle_led_mode(&find_aura_iface()?, mode)?, Some(CliCommand::LedMode(mode)) => handle_led_mode(&find_aura_iface()?, mode)?,
Some(CliCommand::LedPow1(pow)) => handle_led_power1(&find_aura_iface()?, pow)?, Some(CliCommand::LedPow1(pow)) => handle_led_power1(&find_aura_iface()?, pow)?,
Some(CliCommand::LedPow2(pow)) => handle_led_power2(&find_aura_iface()?, pow)?, Some(CliCommand::LedPow2(pow)) => handle_led_power2(&find_aura_iface()?, pow)?,
Some(CliCommand::Profile(cmd)) => handle_throttle_profile(dbus, supported_properties, cmd)?, Some(CliCommand::Profile(cmd)) => {
handle_throttle_profile(&conn, supported_properties, cmd)?
}
Some(CliCommand::FanCurve(cmd)) => { Some(CliCommand::FanCurve(cmd)) => {
handle_fan_curve(dbus, supported_interfaces, cmd)?; handle_fan_curve(&conn, supported_interfaces, cmd)?;
} }
Some(CliCommand::Graphics(_)) => do_gfx(), Some(CliCommand::Graphics(_)) => do_gfx(),
Some(CliCommand::Anime(cmd)) => handle_anime(dbus, cmd)?, Some(CliCommand::Anime(cmd)) => handle_anime(&conn, cmd)?,
Some(CliCommand::Bios(cmd)) => handle_platform_properties(dbus, supported_properties, cmd)?, Some(CliCommand::Bios(cmd)) => {
handle_platform_properties(&conn, supported_properties, cmd)?
}
None => { None => {
if (!parsed.show_supported if (!parsed.show_supported
&& parsed.kbd_bright.is_none() && parsed.kbd_bright.is_none()
@@ -261,9 +276,8 @@ fn do_parsed(
} }
if let Some(chg_limit) = parsed.chg_limit { if let Some(chg_limit) = parsed.chg_limit {
dbus.proxies() let proxy = PlatformProxyBlocking::new(&conn)?;
.platform() proxy.set_charge_control_end_threshold(chg_limit)?;
.set_charge_control_end_threshold(chg_limit)?;
} }
Ok(()) Ok(())
@@ -277,10 +291,7 @@ fn do_gfx() {
println!("This command will be removed in future"); println!("This command will be removed in future");
} }
fn handle_anime( fn handle_anime(conn: &Connection, cmd: &AnimeCommand) -> Result<(), Box<dyn std::error::Error>> {
dbus: &RogDbusClientBlocking<'_>,
cmd: &AnimeCommand,
) -> Result<(), Box<dyn std::error::Error>> {
if (cmd.command.is_none() if (cmd.command.is_none()
&& cmd.enable_display.is_none() && cmd.enable_display.is_none()
&& cmd.enable_powersave_anim.is_none() && cmd.enable_powersave_anim.is_none()
@@ -297,23 +308,24 @@ fn handle_anime(
println!("\n{}", lst); println!("\n{}", lst);
} }
} }
let proxy = AnimeProxyBlocking::new(conn)?;
if let Some(enable) = cmd.enable_display { if let Some(enable) = cmd.enable_display {
dbus.proxies().anime().set_enable_display(enable)?; proxy.set_enable_display(enable)?;
} }
if let Some(enable) = cmd.enable_powersave_anim { if let Some(enable) = cmd.enable_powersave_anim {
dbus.proxies().anime().set_builtins_enabled(enable)?; proxy.set_builtins_enabled(enable)?;
} }
if let Some(bright) = cmd.brightness { if let Some(bright) = cmd.brightness {
dbus.proxies().anime().set_brightness(bright)?; proxy.set_brightness(bright)?;
} }
if let Some(enable) = cmd.off_when_lid_closed { if let Some(enable) = cmd.off_when_lid_closed {
dbus.proxies().anime().set_off_when_lid_closed(enable)?; proxy.set_off_when_lid_closed(enable)?;
} }
if let Some(enable) = cmd.off_when_suspended { if let Some(enable) = cmd.off_when_suspended {
dbus.proxies().anime().set_off_when_suspended(enable)?; proxy.set_off_when_suspended(enable)?;
} }
if let Some(enable) = cmd.off_when_unplugged { if let Some(enable) = cmd.off_when_unplugged {
dbus.proxies().anime().set_off_when_unplugged(enable)?; proxy.set_off_when_unplugged(enable)?;
} }
if cmd.off_with_his_head.is_some() { if cmd.off_with_his_head.is_some() {
println!("Did Alice _really_ make it back from Wonderland?"); println!("Did Alice _really_ make it back from Wonderland?");
@@ -329,7 +341,7 @@ fn handle_anime(
if cmd.clear { if cmd.clear {
let data = vec![255u8; anime_type.data_length()]; let data = vec![255u8; anime_type.data_length()];
let tmp = AnimeDataBuffer::from_vec(anime_type, data)?; let tmp = AnimeDataBuffer::from_vec(anime_type, data)?;
dbus.proxies().anime().write(tmp)?; proxy.write(tmp)?;
} }
if let Some(action) = cmd.command.as_ref() { if let Some(action) = cmd.command.as_ref() {
@@ -353,9 +365,7 @@ fn handle_anime(
anime_type, anime_type,
)?; )?;
dbus.proxies() proxy.write(<AnimeDataBuffer>::try_from(&matrix)?)?;
.anime()
.write(<AnimeDataBuffer>::try_from(&matrix)?)?;
} }
AnimeActions::PixelImage(image) => { AnimeActions::PixelImage(image) => {
if image.help_requested() || image.path.is_empty() { if image.help_requested() || image.path.is_empty() {
@@ -374,9 +384,7 @@ fn handle_anime(
anime_type, anime_type,
)?; )?;
dbus.proxies() proxy.write(matrix.into_data_buffer(anime_type)?)?;
.anime()
.write(matrix.into_data_buffer(anime_type)?)?;
} }
AnimeActions::Gif(gif) => { AnimeActions::Gif(gif) => {
if gif.help_requested() || gif.path.is_empty() { if gif.help_requested() || gif.path.is_empty() {
@@ -401,7 +409,7 @@ fn handle_anime(
let mut loops = gif.loops as i32; let mut loops = gif.loops as i32;
loop { loop {
for frame in matrix.frames() { for frame in matrix.frames() {
dbus.proxies().anime().write(frame.frame().clone())?; proxy.write(frame.frame().clone())?;
sleep(frame.delay()); sleep(frame.delay());
} }
if loops >= 0 { if loops >= 0 {
@@ -432,7 +440,7 @@ fn handle_anime(
let mut loops = gif.loops as i32; let mut loops = gif.loops as i32;
loop { loop {
for frame in matrix.frames() { for frame in matrix.frames() {
dbus.proxies().anime().write(frame.frame().clone())?; proxy.write(frame.frame().clone())?;
sleep(frame.delay()); sleep(frame.delay());
} }
if loops >= 0 { if loops >= 0 {
@@ -453,14 +461,12 @@ fn handle_anime(
return Ok(()); return Ok(());
} }
dbus.proxies() proxy.set_builtin_animations(rog_anime::Animations {
.anime() boot: builtins.boot,
.set_builtin_animations(rog_anime::Animations { awake: builtins.awake,
boot: builtins.boot, sleep: builtins.sleep,
awake: builtins.awake, shutdown: builtins.shutdown,
sleep: builtins.sleep, })?;
shutdown: builtins.shutdown,
})?;
} }
} }
} }
@@ -716,7 +722,7 @@ fn handle_led_power2(
} }
fn handle_throttle_profile( fn handle_throttle_profile(
dbus: &RogDbusClientBlocking<'_>, conn: &Connection,
supported: &[Properties], supported: &[Properties],
cmd: &ProfileCommand, cmd: &ProfileCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -736,16 +742,14 @@ fn handle_throttle_profile(
} }
return Ok(()); return Ok(());
} }
let current = dbus.proxies().platform().throttle_thermal_policy()?;
let proxy = PlatformProxyBlocking::new(conn)?;
let current = proxy.throttle_thermal_policy()?;
if cmd.next { if cmd.next {
dbus.proxies() proxy.set_throttle_thermal_policy(current.next())?;
.platform()
.set_throttle_thermal_policy(current.next())?;
} else if let Some(profile) = cmd.profile_set { } else if let Some(profile) = cmd.profile_set {
dbus.proxies() proxy.set_throttle_thermal_policy(profile)?;
.platform()
.set_throttle_thermal_policy(profile)?;
} }
if cmd.list { if cmd.list {
@@ -763,7 +767,7 @@ fn handle_throttle_profile(
} }
fn handle_fan_curve( fn handle_fan_curve(
dbus: &RogDbusClientBlocking<'_>, conn: &Connection,
supported: &[String], supported: &[String],
cmd: &FanCurveCommand, cmd: &FanCurveCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -794,37 +798,35 @@ fn handle_fan_curve(
return Ok(()); return Ok(());
} }
let plat_proxy = PlatformProxyBlocking::new(conn)?;
let fan_proxy = FanCurvesProxyBlocking::new(conn)?;
if cmd.get_enabled { if cmd.get_enabled {
let profile = dbus.proxies().platform().throttle_thermal_policy()?; let profile = plat_proxy.throttle_thermal_policy()?;
let curves = dbus.proxies().fan_curves().fan_curve_data(profile)?; let curves = fan_proxy.fan_curve_data(profile)?;
for curve in curves.iter() { for curve in curves.iter() {
println!("{}", String::from(curve)); println!("{}", String::from(curve));
} }
} }
if cmd.default { if cmd.default {
let active = dbus.proxies().platform().throttle_thermal_policy()?; let active = plat_proxy.throttle_thermal_policy()?;
dbus.proxies().fan_curves().set_curves_to_defaults(active)?; fan_proxy.set_curves_to_defaults(active)?;
} }
if let Some(profile) = cmd.mod_profile { if let Some(profile) = cmd.mod_profile {
if cmd.enable_fan_curves.is_none() && cmd.data.is_none() { if cmd.enable_fan_curves.is_none() && cmd.data.is_none() {
let data = dbus.proxies().fan_curves().fan_curve_data(profile)?; let data = fan_proxy.fan_curve_data(profile)?;
let data = toml::to_string(&data)?; let data = toml::to_string(&data)?;
println!("\nFan curves for {:?}\n\n{}", profile, data); println!("\nFan curves for {:?}\n\n{}", profile, data);
} }
if let Some(enabled) = cmd.enable_fan_curves { if let Some(enabled) = cmd.enable_fan_curves {
dbus.proxies() fan_proxy.set_fan_curves_enabled(profile, enabled)?;
.fan_curves()
.set_fan_curves_enabled(profile, enabled)?;
} }
if let Some(enabled) = cmd.enable_fan_curve { if let Some(enabled) = cmd.enable_fan_curve {
if let Some(fan) = cmd.fan { if let Some(fan) = cmd.fan {
dbus.proxies() fan_proxy.set_profile_fan_curve_enabled(profile, fan, enabled)?;
.fan_curves()
.set_profile_fan_curve_enabled(profile, fan, enabled)?;
} else { } else {
println!( println!(
"--enable-fan-curves, --enable-fan-curve, --fan, and --data options require \ "--enable-fan-curves, --enable-fan-curve, --fan, and --data options require \
@@ -836,7 +838,7 @@ fn handle_fan_curve(
if let Some(mut curve) = cmd.data.clone() { if let Some(mut curve) = cmd.data.clone() {
let fan = cmd.fan.unwrap_or_default(); let fan = cmd.fan.unwrap_or_default();
curve.set_fan(fan); curve.set_fan(fan);
dbus.proxies().fan_curves().set_fan_curve(profile, curve)?; fan_proxy.set_fan_curve(profile, curve)?;
} }
} }
@@ -844,7 +846,7 @@ fn handle_fan_curve(
} }
fn handle_platform_properties( fn handle_platform_properties(
dbus: &RogDbusClientBlocking<'_>, conn: &Connection,
supported: &[Properties], supported: &[Properties],
cmd: &BiosCommand, cmd: &BiosCommand,
) -> Result<(), Box<dyn std::error::Error>> { ) -> Result<(), Box<dyn std::error::Error>> {
@@ -870,34 +872,34 @@ fn handle_platform_properties(
} }
} }
let proxy = PlatformProxyBlocking::new(conn)?;
if let Some(opt) = cmd.post_sound_set { if let Some(opt) = cmd.post_sound_set {
dbus.proxies().platform().set_boot_sound(opt)?; proxy.set_boot_sound(opt)?;
} }
if cmd.post_sound_get { if cmd.post_sound_get {
let res = dbus.proxies().platform().boot_sound()?; let res = proxy.boot_sound()?;
println!("Bios POST sound on: {}", res); println!("Bios POST sound on: {}", res);
} }
if let Some(opt) = cmd.gpu_mux_mode_set { if let Some(opt) = cmd.gpu_mux_mode_set {
println!("Rebuilding initrd to include drivers"); println!("Rebuilding initrd to include drivers");
dbus.proxies() proxy.set_gpu_mux_mode(GpuMode::from_mux(opt))?;
.platform()
.set_gpu_mux_mode(GpuMode::from_mux(opt))?;
println!( println!(
"The mode change is not active until you reboot, on boot the bios will make the \ "The mode change is not active until you reboot, on boot the bios will make the \
required change" required change"
); );
} }
if cmd.gpu_mux_mode_get { if cmd.gpu_mux_mode_get {
let res = dbus.proxies().platform().gpu_mux_mode()?; let res = proxy.gpu_mux_mode()?;
println!("Bios GPU MUX: {:?}", res); println!("Bios GPU MUX: {:?}", res);
} }
if let Some(opt) = cmd.panel_overdrive_set { if let Some(opt) = cmd.panel_overdrive_set {
dbus.proxies().platform().set_panel_od(opt)?; proxy.set_panel_od(opt)?;
} }
if cmd.panel_overdrive_get { if cmd.panel_overdrive_get {
let res = dbus.proxies().platform().panel_od()?; let res = proxy.panel_od()?;
println!("Panel overdrive on: {}", res); println!("Panel overdrive on: {}", res);
} }
} }

View File

@@ -7,7 +7,7 @@ use std::time::{Duration, Instant};
use config_traits::StdConfig; use config_traits::StdConfig;
use rog_anime::error::AnimeError; use rog_anime::error::AnimeError;
use rog_anime::{ActionData, ActionLoader, AnimTime, Fade, Sequences, Vec2}; use rog_anime::{ActionData, ActionLoader, AnimTime, Fade, Sequences, Vec2};
use rog_dbus::RogDbusClientBlocking; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use zbus::interface; use zbus::interface;
use zbus::zvariant::{ObjectPath, Type}; use zbus::zvariant::{ObjectPath, Type};
@@ -61,14 +61,14 @@ pub enum TimeType {
/// thread and a zbus server behind `Arc<Mutex<T>>` /// thread and a zbus server behind `Arc<Mutex<T>>`
pub struct CtrlAnimeInner<'a> { pub struct CtrlAnimeInner<'a> {
sequences: Sequences, sequences: Sequences,
client: RogDbusClientBlocking<'a>, client: AnimeProxyBlocking<'a>,
do_early_return: Arc<AtomicBool>, do_early_return: Arc<AtomicBool>,
} }
impl<'a> CtrlAnimeInner<'static> { impl<'a> CtrlAnimeInner<'static> {
pub fn new( pub fn new(
sequences: Sequences, sequences: Sequences,
client: RogDbusClientBlocking<'static>, client: AnimeProxyBlocking<'static>,
do_early_return: Arc<AtomicBool>, do_early_return: Arc<AtomicBool>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Ok(Self { Ok(Self {
@@ -93,19 +93,13 @@ impl<'a> CtrlAnimeInner<'static> {
return Ok(true); // Do safe exit return Ok(true); // Do safe exit
} }
self.client self.client
.proxies()
.anime()
.write(output) .write(output)
.map_err(|e| AnimeError::Dbus(format!("{}", e))) .map_err(|e| AnimeError::Dbus(format!("{}", e)))
.map(|_| false) .map(|_| false)
}); });
} }
ActionData::Image(image) => { ActionData::Image(image) => {
self.client self.client.write(image.as_ref().clone()).ok();
.proxies()
.anime()
.write(image.as_ref().clone())
.ok();
} }
ActionData::Pause(duration) => { ActionData::Pause(duration) => {
let start = Instant::now(); let start = Instant::now();
@@ -132,7 +126,7 @@ impl<'a> CtrlAnimeInner<'static> {
pub struct CtrlAnime<'a> { pub struct CtrlAnime<'a> {
config: Arc<Mutex<ConfigAnime>>, config: Arc<Mutex<ConfigAnime>>,
client: RogDbusClientBlocking<'a>, client: AnimeProxyBlocking<'a>,
inner: Arc<Mutex<CtrlAnimeInner<'a>>>, inner: Arc<Mutex<CtrlAnimeInner<'a>>>,
/// Must be the same Atomic as in CtrlAnimeInner /// Must be the same Atomic as in CtrlAnimeInner
inner_early_return: Arc<AtomicBool>, inner_early_return: Arc<AtomicBool>,
@@ -142,7 +136,7 @@ impl CtrlAnime<'static> {
pub fn new( pub fn new(
config: Arc<Mutex<ConfigAnime>>, config: Arc<Mutex<ConfigAnime>>,
inner: Arc<Mutex<CtrlAnimeInner<'static>>>, inner: Arc<Mutex<CtrlAnimeInner<'static>>>,
client: RogDbusClientBlocking<'static>, client: AnimeProxyBlocking<'static>,
inner_early_return: Arc<AtomicBool>, inner_early_return: Arc<AtomicBool>,
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Ok(CtrlAnime { Ok(CtrlAnime {
@@ -356,13 +350,13 @@ impl CtrlAnime<'static> {
pub fn set_state(&mut self, on: bool) -> zbus::fdo::Result<()> { pub fn set_state(&mut self, on: bool) -> zbus::fdo::Result<()> {
// Operations here need to be in specific order // Operations here need to be in specific order
if on { if on {
self.client.proxies().anime().set_enable_display(on).ok(); self.client.set_enable_display(on).ok();
// Let the inner loop run // Let the inner loop run
self.inner_early_return.store(false, Ordering::SeqCst); self.inner_early_return.store(false, Ordering::SeqCst);
} else { } else {
// Must make the inner run loop return early // Must make the inner run loop return early
self.inner_early_return.store(true, Ordering::SeqCst); self.inner_early_return.store(true, Ordering::SeqCst);
self.client.proxies().anime().set_enable_display(on).ok(); self.client.set_enable_display(on).ok();
} }
Ok(()) Ok(())
} }

View File

@@ -9,7 +9,10 @@ use config_traits::{StdConfig, StdConfigLoad};
use rog_anime::usb::get_anime_type; use rog_anime::usb::get_anime_type;
use rog_aura::aura_detection::LaptopLedData; use rog_aura::aura_detection::LaptopLedData;
use rog_aura::layouts::KeyLayout; use rog_aura::layouts::KeyLayout;
use rog_dbus::{RogDbusClientBlocking, DBUS_NAME}; use rog_dbus::zbus_anime::AnimeProxyBlocking;
use rog_dbus::zbus_aura::AuraProxyBlocking;
use rog_dbus::zbus_platform::PlatformProxyBlocking;
use rog_dbus::DBUS_NAME;
use smol::Executor; use smol::Executor;
use zbus::Connection; use zbus::Connection;
@@ -32,10 +35,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!(" rog-dbus v{}", rog_dbus::VERSION); println!(" rog-dbus v{}", rog_dbus::VERSION);
println!("rog-platform v{}", rog_platform::VERSION); println!("rog-platform v{}", rog_platform::VERSION);
let (client, _) = RogDbusClientBlocking::new()?; let conn = zbus::blocking::Connection::system().unwrap();
let supported = client let platform_proxy = PlatformProxyBlocking::new(&conn).unwrap();
.proxies()
.platform() let supported = platform_proxy
.supported_interfaces() .supported_interfaces()
.unwrap_or_default() .unwrap_or_default()
.contains(&"Anime".to_string()); .contains(&"Anime".to_string());
@@ -51,6 +54,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let anime = anime_config.create(anime_type)?; let anime = anime_config.create(anime_type)?;
let anime_config = Arc::new(Mutex::new(anime_config)); let anime_config = Arc::new(Mutex::new(anime_config));
let anime_proxy_blocking = AnimeProxyBlocking::new(&conn).unwrap();
executor executor
.spawn(async move { .spawn(async move {
// Create server // Create server
@@ -59,12 +63,21 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Inner behind mutex required for thread safety // Inner behind mutex required for thread safety
let inner = Arc::new(Mutex::new( let inner = Arc::new(Mutex::new(
CtrlAnimeInner::new(anime, client, early_return.clone()).unwrap(), CtrlAnimeInner::new(
anime,
anime_proxy_blocking.clone(),
early_return.clone(),
)
.unwrap(),
)); ));
// Need new client object for dbus control part // Need new client object for dbus control part
let (client, _) = RogDbusClientBlocking::new().unwrap(); let anime_control = CtrlAnime::new(
let anime_control = anime_config,
CtrlAnime::new(anime_config, inner.clone(), client, early_return).unwrap(); inner.clone(),
anime_proxy_blocking,
early_return,
)
.unwrap();
anime_control.add_to_server(&mut connection).await; anime_control.add_to_server(&mut connection).await;
loop { loop {
if let Ok(inner) = inner.clone().try_lock() { if let Ok(inner) = inner.clone().try_lock() {
@@ -89,22 +102,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}) })
.unwrap_or_else(|_| KeyLayout::default_layout()); .unwrap_or_else(|_| KeyLayout::default_layout());
let aura_proxy_blocking = AuraProxyBlocking::new(&conn).unwrap();
executor executor
.spawn(async move { .spawn(async move {
// Create server
let (client, _) = RogDbusClientBlocking::new().unwrap();
// let connection = Connection::session().await.unwrap();
// connection.request_name(DBUS_NAME).await.unwrap();
loop { loop {
aura_config.aura.next_state(&layout); aura_config.aura.next_state(&layout);
let packets = aura_config.aura.create_packets(); let packets = aura_config.aura.create_packets();
client aura_proxy_blocking.direct_addressing_raw(packets).unwrap();
.proxies()
.aura()
.direct_addressing_raw(packets)
.unwrap();
std::thread::sleep(std::time::Duration::from_millis(33)); std::thread::sleep(std::time::Duration::from_millis(33));
} }
}) })

View File

@@ -274,19 +274,13 @@ impl crate::Reloadable for CtrlFanCurveZbus {
/// Fetch the active profile and use that to set all related components up /// Fetch the active profile and use that to set all related components up
async fn reload(&mut self) -> Result<(), RogError> { async fn reload(&mut self) -> Result<(), RogError> {
let active = self.platform.get_throttle_thermal_policy()?.into(); let active = self.platform.get_throttle_thermal_policy()?.into();
let mut config = self.config.lock().await;
if let Ok(mut device) = find_fan_curve_node() { if let Ok(mut device) = find_fan_curve_node() {
// There is a possibility that the curve was default zeroed, so this call config
// initialises the data from system read and we need to save it .profiles
// after .write_profile_curve_to_platform(active, &mut device)?;
loop {
if let Ok(mut config) = self.config.try_lock() {
config
.profiles
.write_profile_curve_to_platform(active, &mut device)?;
break;
}
}
} }
Ok(()) Ok(())
} }
} }

View File

@@ -175,7 +175,7 @@ impl CtrlPlatform {
fn set_gfx_mode(&self, mode: GpuMode) -> Result<(), RogError> { fn set_gfx_mode(&self, mode: GpuMode) -> Result<(), RogError> {
self.platform.set_gpu_mux_mode(mode.to_mux_attr())?; self.platform.set_gpu_mux_mode(mode.to_mux_attr())?;
// self.update_initramfs(enable)?; // self.update_initramfs(enable)?;
if mode == GpuMode::Discrete { if mode == GpuMode::Ultimate {
info!("Set system-level graphics mode: Dedicated Nvidia"); info!("Set system-level graphics mode: Dedicated Nvidia");
} else { } else {
info!("Set system-level graphics mode: Optimus"); info!("Set system-level graphics mode: Optimus");
@@ -264,6 +264,7 @@ impl CtrlPlatform {
#[interface(name = "org.asuslinux.Platform")] #[interface(name = "org.asuslinux.Platform")]
impl CtrlPlatform { impl CtrlPlatform {
#[zbus(property)]
async fn version(&self) -> String { async fn version(&self) -> String {
crate::VERSION.to_string() crate::VERSION.to_string()
} }

View File

@@ -1,3 +1,7 @@
// TODO: Generic builtin modes
// TODO: Traits for finding device + writing generic modes
// TODO: Traits for writing aura_sync
mod builtin_modes; mod builtin_modes;
use advanced::LedCode; use advanced::LedCode;
pub use builtin_modes::*; pub use builtin_modes::*;

View File

@@ -23,22 +23,12 @@ pub mod types;
pub mod ui; pub mod ui;
pub mod update_and_notify; pub mod update_and_notify;
#[cfg(feature = "mocking")]
pub use mocking::RogDbusClientBlocking;
use nix::sys::stat; use nix::sys::stat;
use nix::unistd; use nix::unistd;
#[cfg(not(feature = "mocking"))]
pub use rog_dbus::RogDbusClientBlocking;
use tempfile::TempDir; use tempfile::TempDir;
// use log::{error, info, warn}; // use log::{error, info, warn};
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg(not(feature = "mocking"))]
const DATA_DIR: &str = "/usr/share/rog-gui/";
#[cfg(feature = "mocking")]
const DATA_DIR: &str = env!("CARGO_MANIFEST_DIR");
const BOARD_NAME: &str = "/sys/class/dmi/id/board_name";
pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png"; pub const APP_ICON_PATH: &str = "/usr/share/icons/hicolor/512x512/apps/rog-control-center.png";
pub fn print_versions() { pub fn print_versions() {

View File

@@ -15,19 +15,28 @@ use rog_control_center::cli_options::CliStart;
use rog_control_center::config::Config; use rog_control_center::config::Config;
use rog_control_center::error::Result; use rog_control_center::error::Result;
use rog_control_center::slint::ComponentHandle; use rog_control_center::slint::ComponentHandle;
use rog_control_center::system_state::{AuraCreation, SystemState}; use rog_control_center::system_state::SystemState;
use rog_control_center::tray::init_tray; use rog_control_center::tray::init_tray;
use rog_control_center::ui::setup_window; use rog_control_center::ui::setup_window;
use rog_control_center::update_and_notify::{start_notifications, EnabledNotifications}; use rog_control_center::update_and_notify::{start_notifications, EnabledNotifications};
use rog_control_center::{ use rog_control_center::{
get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, RogDbusClientBlocking, QUIT_APP, get_ipc_file, on_tmp_dir_exists, print_versions, MainWindow, QUIT_APP, SHOWING_GUI, SHOW_GUI,
SHOWING_GUI, SHOW_GUI,
}; };
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
// use winit::monitor::VideoMode; // use winit::monitor::VideoMode;
// use winit::window::{Fullscreen, WindowLevel}; // use winit::window::{Fullscreen, WindowLevel};
fn main() -> Result<()> { #[tokio::main]
async fn main() -> Result<()> {
let self_version = env!("CARGO_PKG_VERSION");
let conn = zbus::blocking::Connection::system()?;
let proxy = rog_dbus::zbus_platform::PlatformProxyBlocking::new(&conn)?;
let asusd_version = proxy.version().unwrap();
if asusd_version != self_version {
println!("Version mismatch: asusctl = {self_version}, asusd = {asusd_version}");
return Ok(());
}
let dmi = DMIID::new().unwrap_or_default(); let dmi = DMIID::new().unwrap_or_default();
let board_name = dmi.board_name; let board_name = dmi.board_name;
let prod_family = dmi.product_family; let prod_family = dmi.product_family;
@@ -70,13 +79,7 @@ fn main() -> Result<()> {
// Enter the runtime so that `tokio::spawn` is available immediately. // Enter the runtime so that `tokio::spawn` is available immediately.
let _enter = rt.enter(); let _enter = rt.enter();
let (dbus, _) = RogDbusClientBlocking::new() let supported_properties = match proxy.supported_properties() {
.map_err(|_| {
// TODO: show an error window
})
.unwrap();
let supported_properties = match dbus.proxies().platform().supported_properties() {
Ok(s) => s, Ok(s) => s,
Err(_e) => { Err(_e) => {
// TODO: show an error window // TODO: show an error window
@@ -113,10 +116,9 @@ fn main() -> Result<()> {
config.write(); config.write();
let enabled_notifications = EnabledNotifications::tokio_mutex(&config); let enabled_notifications = EnabledNotifications::tokio_mutex(&config);
let aura_creation = AuraCreation::new(cli_parsed.board_name, cli_parsed.layout_viewing)?;
// TODO: config mutex to share config in various places // TODO: config mutex to share config in various places
let states = setup_page_state_and_notifs(aura_creation, &enabled_notifications, &config)?; let states = setup_page_state_and_notifs(&enabled_notifications, &config).await?;
let enable_tray_icon = config.enable_tray_icon; let enable_tray_icon = config.enable_tray_icon;
let startup_in_background = config.startup_in_background; let startup_in_background = config.startup_in_background;
@@ -214,17 +216,18 @@ fn main() -> Result<()> {
Ok(()) Ok(())
} }
fn setup_page_state_and_notifs( async fn setup_page_state_and_notifs(
aura_creation: AuraCreation,
enabled_notifications: &Arc<Mutex<EnabledNotifications>>, enabled_notifications: &Arc<Mutex<EnabledNotifications>>,
config: &Config, config: &Config,
) -> Result<Arc<Mutex<SystemState>>> { ) -> Result<Arc<Mutex<SystemState>>> {
let page_states = Arc::new(Mutex::new(SystemState::new( let page_states = Arc::new(Mutex::new(
aura_creation, SystemState::new(
enabled_notifications.clone(), enabled_notifications.clone(),
config.enable_tray_icon, config.enable_tray_icon,
config.run_in_background, config.run_in_background,
)?)); )
.await?,
));
start_notifications(config, &page_states, enabled_notifications)?; start_notifications(config, &page_states, enabled_notifications)?;
@@ -261,8 +264,10 @@ fn setup_page_state_and_notifs(
// IconData { // IconData {
// height, // height,
// width, // width,
// rgba, // rgba
// } //
//
// / }
// } // }
fn do_cli_help(parsed: &CliStart) -> bool { fn do_cli_help(parsed: &CliStart) -> bool {

View File

@@ -1,190 +1,15 @@
use std::collections::{BTreeMap, HashSet};
use std::path::PathBuf;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::SystemTime;
use log::{error, warn}; use log::error;
use rog_anime::{Animations, DeviceState};
use rog_aura::aura_detection::{LaptopLedData, LedSupportFile};
use rog_aura::layouts::KeyLayout;
use rog_aura::usb::AuraPowerDev;
use rog_aura::{AuraEffect, AuraModeNum, LedBrightness};
use rog_platform::platform::{GpuMode, ThrottlePolicy};
use rog_profiles::fan_curve_set::CurveData;
use rog_profiles::FanCurvePU;
use supergfxctl::pci_device::{GfxMode, GfxPower}; use supergfxctl::pci_device::{GfxMode, GfxPower};
#[cfg(not(feature = "mocking"))] #[cfg(not(feature = "mocking"))]
use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxyBlocking; use supergfxctl::zbus_proxy::DaemonProxy as GfxProxy;
use zbus::Connection;
use crate::error::Result; use crate::error::Result;
#[cfg(feature = "mocking")] #[cfg(feature = "mocking")]
use crate::mocking::DaemonProxyBlocking as GfxProxyBlocking; use crate::mocking::DaemonProxyBlocking as GfxProxyBlocking;
use crate::update_and_notify::EnabledNotifications; use crate::update_and_notify::EnabledNotifications;
use crate::{RogDbusClientBlocking, BOARD_NAME, DATA_DIR};
#[derive(Clone, Debug, Default)]
pub struct PlatformState {
/// To be shared to a thread that checks notifications.
/// It's a bit general in that it won't provide *what* was
/// updated, so the full state needs refresh
pub post_sound: Option<bool>,
pub gpu_mux_mode: Option<GpuMode>,
pub panel_overdrive: Option<bool>,
pub mini_led_mode: Option<bool>,
pub dgpu_disable: Option<bool>,
pub egpu_enable: Option<bool>,
pub throttle: Option<ThrottlePolicy>,
pub charge_limit: Option<u8>,
}
impl PlatformState {
pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
Ok(Self {
post_sound: dbus.proxies().platform().boot_sound().ok(),
gpu_mux_mode: dbus
.proxies()
.platform()
.gpu_mux_mode()
.map(GpuMode::from)
.ok(),
panel_overdrive: dbus.proxies().platform().panel_od().ok(),
mini_led_mode: dbus.proxies().platform().mini_led_mode().ok(),
// TODO: needs supergfx
dgpu_disable: dbus.proxies().platform().dgpu_disable().ok(),
egpu_enable: dbus.proxies().platform().egpu_enable().ok(),
throttle: dbus.proxies().platform().throttle_thermal_policy().ok(),
charge_limit: dbus
.proxies()
.platform()
.charge_control_end_threshold()
.ok(),
})
}
}
#[derive(Clone, Debug, Default)]
pub struct FanCurvesState {
pub show_curve: ThrottlePolicy,
pub show_graph: FanCurvePU,
pub curves: BTreeMap<ThrottlePolicy, Vec<CurveData>>,
pub available_fans: HashSet<FanCurvePU>,
// pub drag_delta: Vec2,
}
impl FanCurvesState {
pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
let profiles = vec![
ThrottlePolicy::Balanced,
ThrottlePolicy::Quiet,
ThrottlePolicy::Performance,
];
let mut available_fans = HashSet::new();
let mut curves: BTreeMap<ThrottlePolicy, Vec<CurveData>> = BTreeMap::new();
for p in &profiles {
if let Ok(curve) = dbus.proxies().fan_curves().fan_curve_data(*p) {
if available_fans.is_empty() {
for fan in &curve {
available_fans.insert(fan.fan);
}
}
curves.insert(*p, curve);
} else {
curves.insert(*p, Default::default());
}
}
let show_curve = dbus.proxies().platform().throttle_thermal_policy()?;
Ok(Self {
show_curve,
show_graph: FanCurvePU::CPU,
curves,
available_fans,
// drag_delta: Vec2::default(),
})
}
}
#[derive(Clone, Debug, Default)]
pub struct AuraState {
pub current_mode: AuraModeNum,
pub modes: BTreeMap<AuraModeNum, AuraEffect>,
pub enabled: AuraPowerDev,
/// Brightness from 0-3
pub bright: LedBrightness,
pub wave_red: [u8; 22],
pub wave_green: [u8; 22],
pub wave_blue: [u8; 22],
}
impl AuraState {
pub fn new(layout: &KeyLayout, dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
Ok(Self {
current_mode: if !layout.basic_modes().is_empty() {
dbus.proxies().aura().led_mode().unwrap_or_default()
} else {
AuraModeNum::Static
},
modes: if !layout.basic_modes().is_empty() {
dbus.proxies().aura().all_mode_data().unwrap_or_default()
} else {
BTreeMap::new()
},
enabled: dbus.proxies().aura().led_power().unwrap_or_default(),
bright: Default::default(),
wave_red: [0u8; 22],
wave_green: [0u8; 22],
wave_blue: [0u8; 22],
})
}
/// Bump value in to the wave and surf all along.
pub fn nudge_wave(&mut self, r: u8, g: u8, b: u8) {
for i in (0..self.wave_red.len()).rev() {
if i > 0 {
self.wave_red[i] = self.wave_red[i - 1];
self.wave_green[i] = self.wave_green[i - 1];
self.wave_blue[i] = self.wave_blue[i - 1];
}
}
self.wave_red[0] = r;
self.wave_green[0] = g;
self.wave_blue[0] = b;
}
}
#[derive(Clone, Debug, Default)]
pub struct AnimeState {
pub display_enabled: bool,
pub display_brightness: u8,
pub builtin_anims_enabled: bool,
pub builtin_anims: Animations,
}
impl AnimeState {
pub fn new(dbus: &RogDbusClientBlocking<'_>) -> Result<Self> {
let device_state = dbus.proxies().anime().device_state()?;
Ok(Self {
display_enabled: device_state.display_enabled,
display_brightness: device_state.display_brightness as u8,
builtin_anims_enabled: device_state.builtin_anims_enabled,
builtin_anims: device_state.builtin_anims,
})
}
}
impl From<DeviceState> for AnimeState {
fn from(dev: DeviceState) -> Self {
Self {
display_enabled: dev.display_enabled,
display_brightness: dev.display_brightness as u8,
builtin_anims_enabled: dev.builtin_anims_enabled,
builtin_anims: dev.builtin_anims,
}
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct GfxState { pub struct GfxState {
@@ -194,11 +19,11 @@ pub struct GfxState {
} }
impl GfxState { impl GfxState {
pub fn new(dbus: &GfxProxyBlocking<'_>) -> Result<Self> { pub async fn new(dbus: &GfxProxy<'_>) -> Result<Self> {
Ok(Self { Ok(Self {
has_supergfx: dbus.mode().is_ok(), has_supergfx: dbus.mode().await.is_ok(),
mode: dbus.mode().unwrap_or(GfxMode::None), mode: dbus.mode().await.unwrap_or(GfxMode::None),
power_status: dbus.power().unwrap_or(GfxPower::Unknown), power_status: dbus.power().await.unwrap_or(GfxPower::Unknown),
}) })
} }
} }
@@ -213,115 +38,16 @@ impl Default for GfxState {
} }
} }
/// The keyboard layout, used for such things as per-key and zones
#[derive(Clone, Debug)]
pub struct AuraCreation {
/// Specifically for testing the development of keyboard layouts (combined
/// with `--layout-name` CLI option)
pub layout_testing: Option<PathBuf>,
pub layout_last_modified: SystemTime,
pub keyboard_layout: KeyLayout,
pub keyboard_layouts: Vec<PathBuf>,
/// current index in to `self.keyboard_layouts`
pub keyboard_layout_index: usize,
}
impl AuraCreation {
pub fn new(test_name: Option<String>, view_layout: bool) -> Result<Self> {
let mut led_support = LaptopLedData::get_data();
let mut path = PathBuf::from(DATA_DIR);
let mut layout_testing = None;
let mut keyboard_layouts = Vec::new();
// Find and load a matching layout for laptop
let mut board_name = std::fs::read_to_string(BOARD_NAME).map_err(|e| {
println!("DOH! {BOARD_NAME}, {e}");
e
})?;
if test_name.is_some() || view_layout {
if cfg!(feature = "mocking") {
path.pop();
path.push("rog-aura");
path.push("data");
}
keyboard_layouts = KeyLayout::layout_files(path.clone()).unwrap();
if let Some(name) = test_name {
if let Some(modes) = LedSupportFile::load_from_supoprt_db() {
if let Some(data) = modes.matcher(&name) {
led_support = data;
}
}
board_name = name;
for layout in &keyboard_layouts {
if layout
.file_name()
.unwrap()
.to_string_lossy()
.contains(&led_support.layout_name.to_lowercase())
{
layout_testing = Some(layout.clone());
}
}
} else {
board_name = "GQ401QM".to_owned();
};
if view_layout {
layout_testing = Some(keyboard_layouts[0].clone());
board_name = keyboard_layouts[0]
.file_name()
.unwrap()
.to_string_lossy()
.split_once('_')
.unwrap()
.0
.to_owned();
led_support.layout_name = board_name.clone();
}
}
let keyboard_layout = KeyLayout::find_layout(led_support, path)
.map_err(|e| {
println!("DERP! , {e}");
})
.unwrap_or_else(|_| {
warn!("Did not find a keyboard layout matching {board_name}");
KeyLayout::default_layout()
});
Ok(Self {
layout_testing,
layout_last_modified: SystemTime::now(),
keyboard_layout,
keyboard_layouts,
keyboard_layout_index: 0,
})
}
}
/// State stored from system daemons. This is shared with: tray, zbus /// State stored from system daemons. This is shared with: tray, zbus
/// notifications thread and the GUI app thread. /// notifications thread and the GUI app thread.
pub struct SystemState { pub struct SystemState {
pub aura_creation: AuraCreation,
//--
pub enabled_notifications: Arc<Mutex<EnabledNotifications>>, pub enabled_notifications: Arc<Mutex<EnabledNotifications>>,
/// Because much of the app state here is the same as
/// `RogBiosSupportedFunctions` we can re-use that structure.
pub bios: PlatformState,
pub aura: AuraState,
pub anime: AnimeState,
pub fan_curves: FanCurvesState,
pub gfx_state: GfxState, pub gfx_state: GfxState,
pub error: Option<String>, pub error: Option<String>,
/// Specific field for the tray only so that we can know when it does need /// Specific field for the tray only so that we can know when it does need
/// update. The tray should set this to false when done. /// update. The tray should set this to false when done.
pub tray_should_update: bool, pub tray_should_update: bool,
pub app_should_update: bool, pub app_should_update: bool,
pub asus_dbus: RogDbusClientBlocking<'static>,
pub gfx_dbus: GfxProxyBlocking<'static>,
pub tray_enabled: bool, pub tray_enabled: bool,
pub run_in_bg: bool, pub run_in_bg: bool,
} }
@@ -329,47 +55,22 @@ pub struct SystemState {
impl SystemState { impl SystemState {
/// Creates self, including the relevant dbus connections and proixies for /// Creates self, including the relevant dbus connections and proixies for
/// internal use /// internal use
pub fn new( pub async fn new(
aura_creation: AuraCreation,
enabled_notifications: Arc<Mutex<EnabledNotifications>>, enabled_notifications: Arc<Mutex<EnabledNotifications>>,
tray_enabled: bool, tray_enabled: bool,
run_in_bg: bool, run_in_bg: bool,
) -> Result<Self> { ) -> Result<Self> {
let (asus_dbus, conn) = RogDbusClientBlocking::new()?; let conn = Connection::system().await?;
let aura = AuraState::new(&aura_creation.keyboard_layout, &asus_dbus)
.map_err(|e| {
let e = format!("Could not get AuraState state: {e}");
error!("{e}");
})
.unwrap_or_default();
let gfx_dbus = GfxProxyBlocking::builder(&conn) let gfx_dbus = GfxProxy::builder(&conn)
.destination(":org.supergfxctl.Daemon")? .destination(":org.supergfxctl.Daemon")?
.build() .build()
.await
.expect("Couldn't connect to supergfxd"); .expect("Couldn't connect to supergfxd");
Ok(Self { Ok(Self {
aura_creation,
enabled_notifications, enabled_notifications,
bios: PlatformState::new(&asus_dbus)
.map_err(|e| {
let e = format!("Could not get BiosState state: {e}");
error!("{e}");
})
.unwrap_or_default(),
aura,
anime: AnimeState::new(&asus_dbus)
.map_err(|e| {
let e = format!("Could not get AnimeState state: {e}");
error!("{e}");
})
.unwrap_or_default(),
fan_curves: FanCurvesState::new(&asus_dbus)
.map_err(|e| {
let e = format!("Could not get FanCurvesState state: {e}");
error!("{e}");
})
.unwrap_or_default(),
gfx_state: GfxState::new(&gfx_dbus) gfx_state: GfxState::new(&gfx_dbus)
.await
.map_err(|e| { .map_err(|e| {
let e = format!("Could not get supergfxd state: {e}"); let e = format!("Could not get supergfxd state: {e}");
error!("{e}"); error!("{e}");
@@ -378,8 +79,6 @@ impl SystemState {
error: None, error: None,
tray_should_update: true, tray_should_update: true,
app_should_update: true, app_should_update: true,
asus_dbus,
gfx_dbus,
tray_enabled, tray_enabled,
run_in_bg, run_in_bg,
}) })
@@ -390,51 +89,3 @@ impl SystemState {
self.app_should_update = true; self.app_should_update = true;
} }
} }
impl Default for SystemState {
fn default() -> Self {
let (asus_dbus, conn) = RogDbusClientBlocking::new().expect("Couldn't connect to asusd");
let gfx_dbus = GfxProxyBlocking::builder(&conn)
.build()
.expect("Couldn't connect to supergfxd");
Self {
aura_creation: AuraCreation {
layout_testing: None,
layout_last_modified: SystemTime::now(),
keyboard_layout: KeyLayout::default_layout(),
keyboard_layouts: Default::default(),
keyboard_layout_index: 0,
},
enabled_notifications: Default::default(),
bios: PlatformState {
post_sound: Default::default(),
gpu_mux_mode: None,
charge_limit: Some(100),
..Default::default()
},
aura: AuraState {
current_mode: AuraModeNum::Static,
modes: Default::default(),
enabled: AuraPowerDev::default(),
..Default::default()
},
anime: AnimeState::default(),
fan_curves: FanCurvesState {
..Default::default()
},
gfx_state: GfxState {
has_supergfx: false,
mode: GfxMode::None,
power_status: GfxPower::Unknown,
},
error: Default::default(),
tray_should_update: true,
app_should_update: true,
asus_dbus,
gfx_dbus,
tray_enabled: true,
run_in_bg: true,
}
}
}

View File

@@ -11,7 +11,7 @@ use std::time::Duration;
use betrayer::{Icon, Menu, MenuItem, TrayEvent, TrayIcon, TrayIconBuilder}; use betrayer::{Icon, Menu, MenuItem, TrayEvent, TrayIcon, TrayIconBuilder};
use log::{debug, error, info, warn}; use log::{debug, error, info, warn};
use rog_platform::platform::{GpuMode, Properties}; use rog_platform::platform::Properties;
use supergfxctl::pci_device::{GfxMode, GfxPower}; use supergfxctl::pci_device::{GfxMode, GfxPower};
use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxy; use supergfxctl::zbus_proxy::DaemonProxyBlocking as GfxProxy;
use versions::Versioning; use versions::Versioning;
@@ -113,16 +113,7 @@ fn set_tray_icon_and_tip(lock: &SystemState, tray: &TrayIcon<TrayAction>, superg
} }
}; };
let current_gpu_mode = if supergfx_active { let current_gpu_mode = lock.gfx_state.mode;
lock.gfx_state.mode
} else if let Some(mode) = lock.bios.gpu_mux_mode {
match mode {
GpuMode::Discrete => GfxMode::AsusMuxDgpu,
_ => GfxMode::Hybrid,
}
} else {
GfxMode::Hybrid
};
tray.set_tooltip(format!( tray.set_tooltip(format!(
"ROG: gpu mode = {current_gpu_mode:?}, gpu power = {gpu_status:?}" "ROG: gpu mode = {current_gpu_mode:?}, gpu power = {gpu_status:?}"

View File

@@ -11,10 +11,8 @@ use std::time::Duration;
use log::{error, info, trace, warn}; use log::{error, info, trace, warn};
use notify_rust::{Hint, Notification, NotificationHandle, Urgency}; use notify_rust::{Hint, Notification, NotificationHandle, Urgency};
use rog_dbus::zbus_anime::AnimeProxy;
use rog_dbus::zbus_aura::AuraProxy;
use rog_dbus::zbus_platform::PlatformProxy; use rog_dbus::zbus_platform::PlatformProxy;
use rog_platform::platform::{GpuMode, ThrottlePolicy}; use rog_platform::platform::GpuMode;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use supergfxctl::actions::UserActionRequired as GfxUserAction; use supergfxctl::actions::UserActionRequired as GfxUserAction;
use supergfxctl::pci_device::{GfxMode, GfxPower}; use supergfxctl::pci_device::{GfxMode, GfxPower};
@@ -31,45 +29,12 @@ const NOTIF_HEADER: &str = "ROG Control";
static mut POWER_AC_CMD: Option<Command> = None; static mut POWER_AC_CMD: Option<Command> = None;
static mut POWER_BAT_CMD: Option<Command> = None; static mut POWER_BAT_CMD: Option<Command> = None;
#[derive(Debug, Clone, Deserialize, Serialize)] #[derive(Debug, Default, Clone, Deserialize, Serialize)]
#[serde(default)] #[serde(default)]
pub struct EnabledNotifications { pub struct EnabledNotifications {
pub receive_boot_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_gpu_mux_mode_changed: bool,
pub receive_charge_control_end_threshold_changed: bool,
pub receive_notify_mains_online: bool,
pub receive_throttle_thermal_policy_changed: bool,
pub receive_led_mode_data_changed: bool,
/// Anime
pub receive_power_states: bool, pub receive_power_states: bool,
pub receive_notify_gfx: bool, pub receive_notify_gfx: bool,
pub receive_notify_gfx_status: bool, pub receive_notify_gfx_status: bool,
pub all_enabled: bool,
}
impl Default for EnabledNotifications {
fn default() -> Self {
Self {
receive_boot_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_gpu_mux_mode_changed: true,
receive_charge_control_end_threshold_changed: true,
receive_notify_mains_online: false,
receive_throttle_thermal_policy_changed: true,
receive_led_mode_data_changed: true,
receive_power_states: false,
receive_notify_gfx: false,
receive_notify_gfx_status: false,
all_enabled: false,
}
}
} }
impl EnabledNotifications { impl EnabledNotifications {
@@ -78,6 +43,18 @@ impl EnabledNotifications {
} }
} }
fn gpu_to_gfx(value: GpuMode) -> GfxMode {
match value {
GpuMode::Optimus => GfxMode::Hybrid,
GpuMode::Integrated => GfxMode::Integrated,
GpuMode::Egpu => GfxMode::AsusEgpu,
GpuMode::Vfio => GfxMode::Vfio,
GpuMode::Ultimate => GfxMode::AsusMuxDgpu,
GpuMode::Error => GfxMode::None,
GpuMode::NotSupported => GfxMode::None,
}
}
// TODO: drop the macro and use generics plus closure // TODO: drop the macro and use generics plus closure
macro_rules! recv_notif { macro_rules! recv_notif {
($proxy:ident, ($proxy:ident,
@@ -107,7 +84,7 @@ macro_rules! recv_notif {
while let Some(e) = p.next().await { while let Some(e) = p.next().await {
if let Ok(out) = e.args() { if let Ok(out) = e.args() {
if let Ok(config) = notifs_enabled1.lock() { if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.$signal { if config.$signal {
trace!("zbus signal {}", stringify!($signal)); trace!("zbus signal {}", stringify!($signal));
$notifier($msg, &out.$($out_arg)+()).ok(); $notifier($msg, &out.$($out_arg)+()).ok();
} }
@@ -124,49 +101,6 @@ 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.into();
lock.set_notified();
}
}
sleep(Duration::from_millis(500)).await;
}
});
};
}
pub fn start_notifications( pub fn start_notifications(
config: &Config, config: &Config,
page_states: &Arc<Mutex<SystemState>>, page_states: &Arc<Mutex<SystemState>>,
@@ -196,155 +130,6 @@ pub fn start_notifications(
} }
} }
// BIOS notif
recv_changed!(
PlatformProxy,
receive_boot_sound_changed,
last_notification,
enabled_notifications,
page_states,
(bios.post_sound),
"BIOS Post sound",
do_notification
);
recv_changed!(
PlatformProxy,
receive_panel_od_changed,
last_notification,
enabled_notifications,
page_states,
(bios.panel_overdrive),
"Panel Overdrive enabled:",
do_notification
);
recv_changed!(
PlatformProxy,
receive_mini_led_mode_changed,
last_notification,
enabled_notifications,
page_states,
(bios.mini_led_mode),
"MiniLED mode enabled:",
do_notification
);
recv_changed!(
PlatformProxy,
receive_dgpu_disable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.dgpu_disable),
"BIOS dGPU disabled",
do_notification
);
recv_changed!(
PlatformProxy,
receive_egpu_enable_changed,
last_notification,
enabled_notifications,
page_states,
(bios.egpu_enable),
"BIOS eGPU enabled",
do_notification
);
// Charge notif
recv_changed!(
PlatformProxy,
receive_charge_control_end_threshold_changed,
last_notification,
enabled_notifications,
page_states,
(bios.charge_limit),
"Battery charge limit changed to",
do_notification
);
// Profile notif
recv_changed!(
PlatformProxy,
receive_throttle_thermal_policy_changed,
last_notification,
enabled_notifications,
page_states,
(bios.throttle),
"Profile changed to",
do_thermal_notif
);
// notify!(do_thermal_notif(&out.profile), lock);
// LED notif
recv_changed!(
AuraProxy,
receive_led_mode_data_changed,
last_notification,
enabled_notifications,
page_states,
(aura.current_mode),
"Keyboard LED mode changed to",
do_notification
);
// let page_states1 = page_states.clone();
// tokio::spawn(async move {
// let conn = zbus::Connection::system()
// .await
// .map_err(|e| {
// error!("zbus signal: receive_device_state: {e}");
// e
// })
// .unwrap();
// let proxy = AuraProxy::new(&conn)
// .await
// .map_err(|e| {
// error!("zbus signal: receive_device_state: {e}");
// e
// })
// .unwrap();
// let p = proxy.receive_led_power_changed().await;
// info!("Started zbus signal thread: receive_notify_power_states");
// while let Some(e) = p.next().await {
// if let Ok(out) = e.get().await {
// if let Ok(mut lock) = page_states1.lock() {
// lock.aura.enabled = out;
// lock.set_notified();
// }
// }
// }
// });
let page_states1 = page_states.clone();
tokio::spawn(async move {
let conn = zbus::Connection::system()
.await
.map_err(|e| {
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
let proxy = AnimeProxy::new(&conn)
.await
.map_err(|e| {
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
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() {
if let Ok(mut lock) = page_states1.lock() {
lock.anime = out.data.into();
}
}
}
};
});
let page_states1 = page_states.clone(); let page_states1 = page_states.clone();
tokio::spawn(async move { tokio::spawn(async move {
let conn = zbus::Connection::system() let conn = zbus::Connection::system()
@@ -375,7 +160,7 @@ pub fn start_notifications(
continue; continue;
} }
if let Ok(mut lock) = page_states1.lock() { if let Ok(mut lock) = page_states1.lock() {
lock.bios.gpu_mux_mode = Some(mode); lock.gfx_state.mode = gpu_to_gfx(mode);
lock.set_notified(); lock.set_notified();
} }
do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &mode).ok(); do_mux_notification("Reboot required. BIOS GPU MUX mode set to", &mode).ok();
@@ -397,7 +182,7 @@ pub fn start_notifications(
if let Ok(status) = dev.get_runtime_status() { if let Ok(status) = dev.get_runtime_status() {
if status != GfxPower::Unknown && status != last_status { if status != GfxPower::Unknown && status != last_status {
if let Ok(config) = notifs_enabled1.lock() { if let Ok(config) = notifs_enabled1.lock() {
if config.all_enabled && config.receive_notify_gfx_status { if config.receive_notify_gfx_status {
// Required check because status cycles through // Required check because status cycles through
// active/unknown/suspended // active/unknown/suspended
do_gpu_status_notif("dGPU status changed:", &status).ok(); do_gpu_status_notif("dGPU status changed:", &status).ok();
@@ -498,7 +283,7 @@ fn convert_gfx_mode(gfx: GfxMode) -> GpuMode {
match gfx { match gfx {
GfxMode::Hybrid => GpuMode::Optimus, GfxMode::Hybrid => GpuMode::Optimus,
GfxMode::Integrated => GpuMode::Integrated, GfxMode::Integrated => GpuMode::Integrated,
GfxMode::NvidiaNoModeset => GpuMode::Discrete, GfxMode::NvidiaNoModeset => GpuMode::Optimus,
GfxMode::Vfio => GpuMode::Vfio, GfxMode::Vfio => GpuMode::Vfio,
GfxMode::AsusEgpu => GpuMode::Egpu, GfxMode::AsusEgpu => GpuMode::Egpu,
GfxMode::AsusMuxDgpu => GpuMode::Ultimate, GfxMode::AsusMuxDgpu => GpuMode::Ultimate,
@@ -553,17 +338,6 @@ fn _ac_power_notification(message: &str, on: &bool) -> Result<NotificationHandle
Ok(base_notification(message, &data).show()?) Ok(base_notification(message, &data).show()?)
} }
fn do_thermal_notif(message: &str, profile: &ThrottlePolicy) -> Result<NotificationHandle> {
let icon = match profile {
ThrottlePolicy::Balanced => "asus_notif_yellow",
ThrottlePolicy::Performance => "asus_notif_red",
ThrottlePolicy::Quiet => "asus_notif_green",
};
let profile: &str = (*profile).into();
let mut notif = base_notification(message, &profile.to_uppercase());
Ok(notif.icon(icon).show()?)
}
fn do_gpu_status_notif(message: &str, data: &GfxPower) -> Result<NotificationHandle> { fn do_gpu_status_notif(message: &str, data: &GfxPower) -> Result<NotificationHandle> {
// eww // eww
let mut notif = base_notification(message, &<&str>::from(data).to_owned()); let mut notif = base_notification(message, &<&str>::from(data).to_owned());

View File

@@ -2,7 +2,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-04-03 20:58+0000\n" "POT-Creation-Date: 2024-04-05 03:00+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"

View File

@@ -4,124 +4,4 @@ pub mod zbus_aura;
pub mod zbus_fan_curves; pub mod zbus_fan_curves;
pub mod zbus_platform; pub mod zbus_platform;
// use rog_anime::AnimePowerStates;
// use rog_aura::{AuraEffect, LedPowerStates};
// use rog_profiles::Profile;
// use std::sync::mpsc::{channel, Receiver};
use zbus::{blocking, Connection, Result};
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub struct DbusProxiesBlocking<'a> {
anime: zbus_anime::AnimeProxyBlocking<'a>,
led: zbus_aura::AuraProxyBlocking<'a>,
profile: zbus_fan_curves::FanCurvesProxyBlocking<'a>,
rog_bios: zbus_platform::PlatformProxyBlocking<'a>,
}
impl<'a> DbusProxiesBlocking<'a> {
#[inline]
pub fn new() -> Result<(Self, blocking::Connection)> {
let conn = blocking::Connection::system()?;
Ok((
DbusProxiesBlocking {
anime: zbus_anime::AnimeProxyBlocking::new(&conn)?,
led: zbus_aura::AuraProxyBlocking::new(&conn)?,
profile: zbus_fan_curves::FanCurvesProxyBlocking::new(&conn)?,
rog_bios: zbus_platform::PlatformProxyBlocking::new(&conn)?,
},
conn,
))
}
pub fn anime(&self) -> &zbus_anime::AnimeProxyBlocking<'a> {
&self.anime
}
pub fn aura(&self) -> &zbus_aura::AuraProxyBlocking<'a> {
&self.led
}
pub fn fan_curves(&self) -> &zbus_fan_curves::FanCurvesProxyBlocking<'a> {
&self.profile
}
pub fn platform(&self) -> &zbus_platform::PlatformProxyBlocking<'a> {
&self.rog_bios
}
}
/// This is the main way to communicate with the DBUS interface
pub struct RogDbusClientBlocking<'a> {
proxies: DbusProxiesBlocking<'a>,
}
impl<'a> RogDbusClientBlocking<'a> {
#[inline]
pub fn new() -> Result<(Self, blocking::Connection)> {
let (proxies, conn) = DbusProxiesBlocking::new()?;
Ok((RogDbusClientBlocking { proxies }, conn))
}
pub fn proxies(&self) -> &DbusProxiesBlocking<'_> {
&self.proxies
}
}
pub struct DbusProxies<'a> {
anime: zbus_anime::AnimeProxy<'a>,
led: zbus_aura::AuraProxy<'a>,
profile: zbus_fan_curves::FanCurvesProxy<'a>,
rog_bios: zbus_platform::PlatformProxy<'a>,
}
impl<'a> DbusProxies<'a> {
#[inline]
pub async fn new() -> Result<(DbusProxies<'a>, Connection)> {
let conn = Connection::system().await?;
Ok((
DbusProxies {
anime: zbus_anime::AnimeProxy::new(&conn).await?,
led: zbus_aura::AuraProxy::new(&conn).await?,
profile: zbus_fan_curves::FanCurvesProxy::new(&conn).await?,
rog_bios: zbus_platform::PlatformProxy::new(&conn).await?,
},
conn,
))
}
pub fn anime(&self) -> &zbus_anime::AnimeProxy<'a> {
&self.anime
}
pub fn led(&self) -> &zbus_aura::AuraProxy<'a> {
&self.led
}
pub fn profile(&self) -> &zbus_fan_curves::FanCurvesProxy<'a> {
&self.profile
}
pub fn rog_bios(&self) -> &zbus_platform::PlatformProxy<'a> {
&self.rog_bios
}
}
/// This is the main way to communicate with the DBUS interface
pub struct RogDbusClient<'a> {
proxies: DbusProxies<'a>,
}
impl<'a> RogDbusClient<'a> {
#[inline]
pub async fn new() -> Result<(RogDbusClient<'a>, Connection)> {
let (proxies, conn) = DbusProxies::new().await?;
Ok((RogDbusClient { proxies }, conn))
}
pub fn proxies(&self) -> &DbusProxies<'_> {
&self.proxies
}
}

View File

@@ -30,6 +30,9 @@ use zbus::proxy;
default_path = "/org/asuslinux" default_path = "/org/asuslinux"
)] )]
trait Platform { trait Platform {
#[zbus(property)]
fn version(&self) -> zbus::Result<String>;
/// NextThrottleThermalPolicy method /// NextThrottleThermalPolicy method
fn next_throttle_thermal_policy(&self) -> zbus::Result<()>; fn next_throttle_thermal_policy(&self) -> zbus::Result<()>;

View File

@@ -154,27 +154,25 @@ impl Default for RogPlatform {
Serialize, Deserialize, Default, Type, Value, OwnedValue, Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, Default, Type, Value, OwnedValue, Debug, PartialEq, Eq, Clone, Copy,
)] )]
pub enum GpuMode { pub enum GpuMode {
Discrete = 0, Optimus = 0,
Optimus = 1, Integrated = 1,
Integrated = 2, Egpu = 2,
Egpu = 3, Vfio = 3,
Vfio = 4, Ultimate = 4,
Ultimate = 5,
#[default] #[default]
Error = 6, Error = 254,
NotSupported = 7, NotSupported = 255,
} }
impl From<u8> for GpuMode { impl From<u8> for GpuMode {
fn from(v: u8) -> Self { fn from(v: u8) -> Self {
match v { match v {
0 => GpuMode::Discrete, 0 => GpuMode::Optimus,
1 => GpuMode::Optimus, 1 => GpuMode::Integrated,
2 => GpuMode::Integrated, 2 => GpuMode::Egpu,
3 => GpuMode::Egpu, 3 => GpuMode::Vfio,
4 => GpuMode::Vfio, 4 => GpuMode::Ultimate,
5 => GpuMode::Ultimate, 5 => GpuMode::Error,
6 => GpuMode::Error,
_ => GpuMode::NotSupported, _ => GpuMode::NotSupported,
} }
} }
@@ -189,7 +187,7 @@ impl From<GpuMode> for u8 {
impl GpuMode { impl GpuMode {
/// For writing to `gpu_mux_mode` attribute /// For writing to `gpu_mux_mode` attribute
pub fn to_mux_attr(&self) -> u8 { pub fn to_mux_attr(&self) -> u8 {
if *self == Self::Discrete { if *self == Self::Ultimate {
return 0; return 0;
} }
1 1
@@ -211,7 +209,7 @@ impl GpuMode {
pub fn from_mux(num: u8) -> Self { pub fn from_mux(num: u8) -> Self {
if num == 0 { if num == 0 {
return Self::Discrete; return Self::Ultimate;
} }
Self::Optimus Self::Optimus
} }
@@ -236,7 +234,6 @@ impl GpuMode {
impl Display for GpuMode { impl Display for GpuMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
GpuMode::Discrete => write!(f, "Discrete"),
GpuMode::Optimus => write!(f, "Optimus"), GpuMode::Optimus => write!(f, "Optimus"),
GpuMode::Integrated => write!(f, "Integrated"), GpuMode::Integrated => write!(f, "Integrated"),
GpuMode::Egpu => write!(f, "eGPU"), GpuMode::Egpu => write!(f, "eGPU"),

View File

@@ -14,6 +14,8 @@ use zbus::zvariant::{OwnedValue, Value};
pub const VERSION: &str = env!("CARGO_PKG_VERSION"); pub const VERSION: &str = env!("CARGO_PKG_VERSION");
/// Use udev system to find the fan curve path/node which is labelled with
/// "asus_custom_fan_curve" in the kernel
pub fn find_fan_curve_node() -> Result<Device, ProfileError> { pub fn find_fan_curve_node() -> Result<Device, ProfileError> {
let mut enumerator = udev::Enumerator::new()?; let mut enumerator = udev::Enumerator::new()?;
enumerator.match_subsystem("hwmon")?; enumerator.match_subsystem("hwmon")?;
@@ -170,9 +172,7 @@ impl FanCurveProfiles {
} }
/// Write the curves for the selected profile to the device. If the curve is /// Write the curves for the selected profile to the device. If the curve is
/// in the enabled list it will become active. If the curve is zeroed it /// in the enabled list it will become active.
/// will be initialised to a default read from the system.
// TODO: Make this return an error if curve is zeroed
pub fn write_profile_curve_to_platform( pub fn write_profile_curve_to_platform(
&mut self, &mut self,
profile: ThrottlePolicy, profile: ThrottlePolicy,