Add DBUS method to toggle to next profile

This commit is contained in:
Luke D Jones
2020-10-25 15:02:35 +13:00
parent 68ea73c847
commit 0558f919c4
11 changed files with 79 additions and 33 deletions

View File

@@ -31,6 +31,7 @@ impl DbusFanAndCpu {
#[dbus_interface(name = "org.asuslinux.Daemon")]
impl DbusFanAndCpu {
/// Set profile details
fn set_profile(&self, profile: String) {
if let Ok(event) = serde_json::from_str(&profile) {
if let Ok(mut ctrl) = self.inner.try_lock() {
@@ -45,6 +46,23 @@ impl DbusFanAndCpu {
}
}
/// Fetch the active profile name
fn next_profile(&mut self) {
if let Ok(mut ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.clone().try_lock() {
ctrl.do_next_profile(&mut cfg)
.unwrap_or_else(|err| warn!("{}", err));
if let Some(profile) = cfg.power_profiles.get(&cfg.active_profile) {
if let Ok(json) = serde_json::to_string(profile) {
self.notify_profile(&json)
.unwrap_or_else(|err| warn!("{}", err));
}
}
}
}
}
/// Fetch the active profile name
fn active_profile_name(&mut self) -> String {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.try_lock() {
@@ -55,6 +73,7 @@ impl DbusFanAndCpu {
"Failed".to_string()
}
/// Fetch the active profile details
fn profile(&mut self) -> String {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.try_lock() {
@@ -178,7 +197,8 @@ impl CtrlFanAndCPU {
}
}
pub(super) fn do_update(&mut self, config: &mut Config) -> Result<(), RogError> {
/// Toggle to next profile in list
pub(super) fn do_next_profile(&mut self, config: &mut Config) -> Result<(), RogError> {
config.read();
let mut i = config
@@ -232,7 +252,7 @@ impl CtrlFanAndCPU {
config: &mut Config,
) -> Result<(), RogError> {
match event {
ProfileEvent::Toggle => self.do_update(config)?,
ProfileEvent::Toggle => self.do_next_profile(config)?,
ProfileEvent::ChangeMode(mode) => {
self.set_fan_mode(*mode, config)?;
}

View File

@@ -72,6 +72,7 @@ impl DbusKbdBacklight {
}
}
/// Return the current mode data
fn led_mode(&self) -> String {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(cfg) = ctrl.config.clone().try_lock() {
@@ -86,6 +87,7 @@ impl DbusKbdBacklight {
"SetKeyBacklight could not deserialise".to_string()
}
/// Return a list of available modes
fn led_modes(&self) -> String {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(cfg) = ctrl.config.clone().try_lock() {
@@ -98,7 +100,8 @@ impl DbusKbdBacklight {
"SetKeyBacklight could not deserialise".to_string()
}
fn led_bright(&self) -> i8 {
/// Return the current LED brightness
fn led_brightness(&self) -> i8 {
if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(cfg) = ctrl.config.clone().try_lock() {
return cfg.kbd_led_brightness as i8;

View File

@@ -1,25 +1,14 @@
use asus_nb::{
cli_options::{
LedBrightness,
SetAuraBuiltin,
AniMeActions,
},
core_dbus::AuraDbusClient,
anime_dbus::AniMeDbusWriter,
cli_options::{AniMeActions, LedBrightness, SetAuraBuiltin},
core_dbus::AuraDbusClient,
profile::{ProfileCommand, ProfileEvent},
};
use ctrl_gfx::vendors::GfxVendors;
use daemon::ctrl_fan_cpu::FanLevel;
use gumdrop::{
Opt,
Options,
};
use gumdrop::{Opt, Options};
use log::LevelFilter;
use std::{
env::args,
io::Write,
process::Command,
};
use std::{env::args, io::Write, process::Command};
use yansi_term::Colour::Green;
use yansi_term::Colour::Red;
@@ -77,11 +66,9 @@ struct GraphicsCommand {
struct AniMeCommand {
#[options(help = "print help message")]
help: bool,
#[options(help = "turn on the panel (and accept write requests)",
no_short)]
#[options(help = "turn on the panel (and accept write requests)", no_short)]
on: bool,
#[options(help = "turn off the panel (and reject write requests)",
no_short)]
#[options(help = "turn off the panel (and reject write requests)", no_short)]
off: bool,
#[options(command)]
command: Option<AniMeActions>,
@@ -95,10 +82,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.filter(None, LevelFilter::Info)
.init();
let mut args : Vec<String> = args().collect();
let mut args: Vec<String> = args().collect();
args.remove(0);
let parsed : CLIStart;
let parsed: CLIStart;
let missing_argument_k = gumdrop::Error::missing_argument(Opt::Short('k'));
match CLIStart::parse_args_default(&args) {
Ok(p) => {
@@ -136,7 +123,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
Some(CliCommand::Profile(command)) => {
writer.write_profile_command(&ProfileEvent::Cli(command))?
if command.next {
writer.next_fan_profile()?;
} else {
writer.write_profile_command(&ProfileEvent::Cli(command))?
}
}
Some(CliCommand::Graphics(command)) => do_gfx(command, &writer)?,
Some(CliCommand::AniMe(anime)) => {
@@ -153,16 +144,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
}
}
None => ()
None => (),
}
if let Some(brightness) = parsed.kbd_bright {
match brightness.level() {
None => {
let level = writer.get_led_brightness()?;
println!("Current keyboard led brightness: {}",
level.to_string());
},
println!("Current keyboard led brightness: {}", level.to_string());
}
Some(level) => writer.write_brightness(level)?,
}
}