mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
Add DBUS method to toggle to next profile
This commit is contained in:
@@ -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).
|
||||
|
||||
## [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
|
||||
### Changed
|
||||
- Bugfixes
|
||||
|
||||
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -29,7 +29,7 @@ checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
|
||||
|
||||
[[package]]
|
||||
name = "asus-nb"
|
||||
version = "2.0.5"
|
||||
version = "2.1.0"
|
||||
dependencies = [
|
||||
"ctrl-gfx",
|
||||
"dbus",
|
||||
@@ -46,7 +46,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "asus-nb-ctrl"
|
||||
version = "2.0.5"
|
||||
version = "2.1.0"
|
||||
dependencies = [
|
||||
"asus-nb",
|
||||
"ctrl-gfx",
|
||||
|
||||
@@ -76,6 +76,12 @@ Accepts an integer from the following:
|
||||
- `1`: Boost 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
|
||||
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "asus-nb-ctrl"
|
||||
version = "2.0.5"
|
||||
version = "2.1.0"
|
||||
license = "MPL-2.0"
|
||||
readme = "README.md"
|
||||
authors = ["Luke <luke@ljones.dev>"]
|
||||
|
||||
@@ -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)?;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)?,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "asus-nb"
|
||||
version = "2.0.5"
|
||||
version = "2.1.0"
|
||||
license = "MPL-2.0"
|
||||
readme = "README.md"
|
||||
authors = ["Luke <luke@ljones.dev>"]
|
||||
|
||||
@@ -264,6 +264,17 @@ impl AuraDbusClient {
|
||||
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]
|
||||
pub fn write_fan_mode(&self, level: u8) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let proxy = self.connection.with_proxy(
|
||||
|
||||
@@ -6,6 +6,7 @@ use dbus::blocking;
|
||||
|
||||
pub trait OrgAsuslinuxDaemon {
|
||||
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 profile(&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, ))
|
||||
}
|
||||
|
||||
fn next_profile(&self) -> Result<(), dbus::Error> {
|
||||
self.method_call("org.asuslinux.Daemon", "NextProfile", ())
|
||||
}
|
||||
|
||||
fn active_profile_name(&self) -> Result<String, dbus::Error> {
|
||||
self.method_call("org.asuslinux.Daemon", "ActiveProfileName", ())
|
||||
.and_then(|r: (String, )| Ok(r.0, ))
|
||||
|
||||
@@ -76,6 +76,8 @@ fn parse_fan_curve(data: &str) -> Result<Curve, String> {
|
||||
pub struct ProfileCommand {
|
||||
#[options(help = "print help message")]
|
||||
help: bool,
|
||||
#[options(help = "toggle to next profile in list")]
|
||||
pub next: bool,
|
||||
#[options(help = "create the profile if it doesn't exist")]
|
||||
pub create: bool,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user