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

@@ -5,6 +5,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
# [2.1.0] - 2020-10-25
### Added
- Option to turn off AniMe display (@asere)
### Changed
- Change option -k to show current LED bright (@asere)
- Correctly disable GFX control via config
- Panic and exit if config can't be parsed
- Add DBUS method to toggle to next fan/thermal profile
# [2.0.5] - 2020-09-29 # [2.0.5] - 2020-09-29
### Changed ### Changed
- Bugfixes - Bugfixes

4
Cargo.lock generated
View File

@@ -29,7 +29,7 @@ checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]] [[package]]
name = "asus-nb" name = "asus-nb"
version = "2.0.5" version = "2.1.0"
dependencies = [ dependencies = [
"ctrl-gfx", "ctrl-gfx",
"dbus", "dbus",
@@ -46,7 +46,7 @@ dependencies = [
[[package]] [[package]]
name = "asus-nb-ctrl" name = "asus-nb-ctrl"
version = "2.0.5" version = "2.1.0"
dependencies = [ dependencies = [
"asus-nb", "asus-nb",
"ctrl-gfx", "ctrl-gfx",

View File

@@ -76,6 +76,12 @@ Accepts an integer from the following:
- `1`: Boost mode - `1`: Boost mode
- `2`: Silent mode - `2`: Silent mode
## dbus-send examples:
```
dbus-send --system --type=method_call --dest=org.asuslinux.Daemon /org/asuslinux/Profile org.asuslinux.Daemon.NextProfile
```
## dbus-send examples OUTDATED ## dbus-send examples OUTDATED
``` ```

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "asus-nb-ctrl" name = "asus-nb-ctrl"
version = "2.0.5" version = "2.1.0"
license = "MPL-2.0" license = "MPL-2.0"
readme = "README.md" readme = "README.md"
authors = ["Luke <luke@ljones.dev>"] authors = ["Luke <luke@ljones.dev>"]

View File

@@ -31,6 +31,7 @@ impl DbusFanAndCpu {
#[dbus_interface(name = "org.asuslinux.Daemon")] #[dbus_interface(name = "org.asuslinux.Daemon")]
impl DbusFanAndCpu { impl DbusFanAndCpu {
/// Set profile details
fn set_profile(&self, profile: String) { fn set_profile(&self, profile: String) {
if let Ok(event) = serde_json::from_str(&profile) { if let Ok(event) = serde_json::from_str(&profile) {
if let Ok(mut ctrl) = self.inner.try_lock() { 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 { fn active_profile_name(&mut self) -> String {
if let Ok(ctrl) = self.inner.try_lock() { if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.try_lock() { if let Ok(mut cfg) = ctrl.config.try_lock() {
@@ -55,6 +73,7 @@ impl DbusFanAndCpu {
"Failed".to_string() "Failed".to_string()
} }
/// Fetch the active profile details
fn profile(&mut self) -> String { fn profile(&mut self) -> String {
if let Ok(ctrl) = self.inner.try_lock() { if let Ok(ctrl) = self.inner.try_lock() {
if let Ok(mut cfg) = ctrl.config.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(); config.read();
let mut i = config let mut i = config
@@ -232,7 +252,7 @@ impl CtrlFanAndCPU {
config: &mut Config, config: &mut Config,
) -> Result<(), RogError> { ) -> Result<(), RogError> {
match event { match event {
ProfileEvent::Toggle => self.do_update(config)?, ProfileEvent::Toggle => self.do_next_profile(config)?,
ProfileEvent::ChangeMode(mode) => { ProfileEvent::ChangeMode(mode) => {
self.set_fan_mode(*mode, config)?; self.set_fan_mode(*mode, config)?;
} }

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "asus-nb" name = "asus-nb"
version = "2.0.5" version = "2.1.0"
license = "MPL-2.0" license = "MPL-2.0"
readme = "README.md" readme = "README.md"
authors = ["Luke <luke@ljones.dev>"] authors = ["Luke <luke@ljones.dev>"]

View File

@@ -264,6 +264,17 @@ impl AuraDbusClient {
Ok(()) Ok(())
} }
#[inline]
pub fn next_fan_profile(&self) -> Result<(), Box<dyn std::error::Error>> {
let proxy = self.connection.with_proxy(
"org.asuslinux.Daemon",
"/org/asuslinux/Profile",
Duration::from_secs(2),
);
proxy.next_profile()?;
Ok(())
}
#[inline] #[inline]
pub fn write_fan_mode(&self, level: u8) -> Result<(), Box<dyn std::error::Error>> { pub fn write_fan_mode(&self, level: u8) -> Result<(), Box<dyn std::error::Error>> {
let proxy = self.connection.with_proxy( let proxy = self.connection.with_proxy(

View File

@@ -6,6 +6,7 @@ use dbus::blocking;
pub trait OrgAsuslinuxDaemon { pub trait OrgAsuslinuxDaemon {
fn set_profile(&self, profile: &str) -> Result<(), dbus::Error>; fn set_profile(&self, profile: &str) -> Result<(), dbus::Error>;
fn next_profile(&self) -> Result<(), dbus::Error>;
fn active_profile_name(&self) -> Result<String, dbus::Error>; fn active_profile_name(&self) -> Result<String, dbus::Error>;
fn profile(&self) -> Result<String, dbus::Error>; fn profile(&self) -> Result<String, dbus::Error>;
fn profiles(&self) -> Result<String, dbus::Error>; fn profiles(&self) -> Result<String, dbus::Error>;
@@ -17,6 +18,10 @@ impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref<Target=T>> OrgAsuslin
self.method_call("org.asuslinux.Daemon", "SetProfile", (profile, )) self.method_call("org.asuslinux.Daemon", "SetProfile", (profile, ))
} }
fn next_profile(&self) -> Result<(), dbus::Error> {
self.method_call("org.asuslinux.Daemon", "NextProfile", ())
}
fn active_profile_name(&self) -> Result<String, dbus::Error> { fn active_profile_name(&self) -> Result<String, dbus::Error> {
self.method_call("org.asuslinux.Daemon", "ActiveProfileName", ()) self.method_call("org.asuslinux.Daemon", "ActiveProfileName", ())
.and_then(|r: (String, )| Ok(r.0, )) .and_then(|r: (String, )| Ok(r.0, ))

View File

@@ -76,6 +76,8 @@ fn parse_fan_curve(data: &str) -> Result<Curve, String> {
pub struct ProfileCommand { pub struct ProfileCommand {
#[options(help = "print help message")] #[options(help = "print help message")]
help: bool, help: bool,
#[options(help = "toggle to next profile in list")]
pub next: bool,
#[options(help = "create the profile if it doesn't exist")] #[options(help = "create the profile if it doesn't exist")]
pub create: bool, pub create: bool,