mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Add dbus methods and CLI args for battery charge limit
This commit is contained in:
60
README.md
60
README.md
@@ -115,7 +115,7 @@ Occasionally I might break things for you by tweaking or changing the config fil
|
||||
need to remove `/etc/rog-core.conf` and restart the daemon to create a new one. You *can* back up the old one and copy
|
||||
settings back over (then restart daemon again).
|
||||
|
||||
## Use
|
||||
# Usage
|
||||
|
||||
**NOTE! Fan mode toggling requires a newer kernel**. I'm unsure when the patches required for it got merged - I've
|
||||
tested with the 5.6.6 kernel and above only. To see if the fan-mode changed cat either:
|
||||
@@ -147,6 +147,60 @@ Some commands may have subcommands:
|
||||
rog-core <command> <subcommand> --help
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
$ rog-core --help
|
||||
Usage: rog-core [OPTIONS]
|
||||
|
||||
Optional arguments:
|
||||
-h, --help print help message
|
||||
-v, --version show program version number
|
||||
-d, --daemon start daemon
|
||||
-b, --bright VAL <off, low, med, high>
|
||||
-f, --fan-mode FAN <silent, normal, boost>
|
||||
|
||||
Available commands:
|
||||
led-mode Set the keyboard lighting from built-in modes
|
||||
|
||||
$ rog-core led-mode --help
|
||||
Usage: rog-core led-mode [OPTIONS]
|
||||
|
||||
Optional arguments:
|
||||
-h, --help print help message
|
||||
|
||||
Available commands:
|
||||
stable set a single static colour
|
||||
breathe pulse between one or two colours
|
||||
strobe strobe through all colours
|
||||
rainbow rainbow cycling in one of four directions
|
||||
star rain pattern mimicking raindrops
|
||||
rain rain pattern of three preset colours
|
||||
highlight pressed keys are highlighted to fade
|
||||
laser pressed keys generate horizontal laser
|
||||
ripple pressed keys ripple outwards like a splash
|
||||
pulse set a rapid pulse
|
||||
comet set a vertical line zooming from left
|
||||
flash set a wide vertical line zooming from left
|
||||
multi-static 4-zone multi-colour
|
||||
|
||||
$ rog-core led-mode stable --help
|
||||
Usage: rog-core led-mode stable [OPTIONS]
|
||||
|
||||
Optional arguments:
|
||||
-h, --help print help message
|
||||
-c HEX set the RGB value e.g, ff00ff
|
||||
|
||||
$ rog-core led-mode star --help
|
||||
Usage: rog-core led-mode star [OPTIONS]
|
||||
|
||||
Optional arguments:
|
||||
-h, --help print help message
|
||||
-c HEX set the first RGB value e.g, ff00ff
|
||||
-C HEX set the second RGB value e.g, ff00ff
|
||||
-s SPEED set the speed: low, med, high
|
||||
```
|
||||
|
||||
## Daemon mode
|
||||
|
||||
If the daemon service is enabled then on boot the following will be reloaded from save:
|
||||
@@ -175,6 +229,10 @@ Commands: `FanMode`, `LedWriteBytes`, `LedWriteMultizone`, `LedWriteEffect`
|
||||
|
||||
TODO: fill in this info
|
||||
|
||||
### AniMe input
|
||||
|
||||
You will want to look at what MeuMeu has done with [https://github.com/Meumeu/ZephyrusBling/](https://github.com/Meumeu/ZephyrusBling/)
|
||||
|
||||
### Wireshark captures
|
||||
|
||||
TODO: see `./wireshark_data/` for some captures.
|
||||
|
||||
@@ -121,6 +121,19 @@ impl AuraDbusWriter {
|
||||
Err(Box::new(dbus::Error::new_custom("name", "message")))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_charge_limit(&self, level: u8) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let msg = Message::new_method_call(DBUS_NAME, DBUS_PATH, DBUS_IFACE, "ChargeLimit")?
|
||||
.append1(level);
|
||||
let r = self
|
||||
.connection
|
||||
.send_with_reply_and_block(msg, Duration::from_millis(5000))?;
|
||||
if let Some(reply) = r.get1::<&str>() {
|
||||
return Ok(reply.to_owned());
|
||||
}
|
||||
Err(Box::new(dbus::Error::new_custom("name", "message")))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_builtin_mode(
|
||||
&self,
|
||||
|
||||
@@ -16,7 +16,7 @@ use std::error::Error;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
pub(super) type FanModeType = Arc<Mutex<Option<u8>>>;
|
||||
pub(super) type DbusU8Type = Arc<Mutex<Option<u8>>>;
|
||||
|
||||
// Timing is such that:
|
||||
// - interrupt write is minimum 1ms (sometimes lower)
|
||||
@@ -93,6 +93,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
mut aura_command_recv,
|
||||
mut animatrix_recv,
|
||||
fan_mode,
|
||||
charge_limit,
|
||||
effect_cancel_signal,
|
||||
) = dbus_create_tree();
|
||||
// We add the tree to the connection so that incoming method calls will be handled.
|
||||
@@ -119,6 +120,16 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
|
||||
.unwrap_or_else(|err| warn!("{:?}", err));
|
||||
}
|
||||
}
|
||||
// Charge limit
|
||||
if let Ok(mut lock) = charge_limit.try_lock() {
|
||||
if let Some(n) = lock.take() {
|
||||
let mut config = config1.lock().await;
|
||||
rogcore
|
||||
.set_charge_limit(n, &mut config)
|
||||
.unwrap_or_else(|err| warn!("{:?}", err));
|
||||
}
|
||||
}
|
||||
// Keyboard reads
|
||||
let data = keyboard_reader.poll_keyboard().await;
|
||||
if let Some(bytes) = data {
|
||||
laptop
|
||||
|
||||
@@ -22,6 +22,8 @@ struct CLIStart {
|
||||
bright: Option<LedBrightness>,
|
||||
#[options(meta = "FAN", help = "<silent, normal, boost>")]
|
||||
fan_mode: Option<FanLevel>,
|
||||
#[options(meta = "CHRG", help = "<20-100>")]
|
||||
charge_limit: Option<u8>,
|
||||
#[options(command)]
|
||||
command: Option<Command>,
|
||||
}
|
||||
@@ -87,5 +89,11 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Err(err) => println!("Error: {}", err),
|
||||
}
|
||||
}
|
||||
if let Some(charge_limit) = parsed.charge_limit {
|
||||
match writer.write_charge_limit(charge_limit) {
|
||||
Ok(msg) => println!("Daemon response: {}", msg),
|
||||
Err(err) => println!("Error: {}", err),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::daemon::FanModeType;
|
||||
use crate::daemon::DbusU8Type;
|
||||
use crate::led_control::AuraCommand;
|
||||
use crate::rogcore::FanLevel;
|
||||
use dbus::tree::{Factory, MTSync, Method, MethodErr, Signal, Tree};
|
||||
@@ -138,13 +138,13 @@ pub(super) fn dbus_create_animatrix_method(
|
||||
.annotate("org.freedesktop.DBus.Method.NoReply", "true")
|
||||
}
|
||||
|
||||
pub(super) fn dbus_create_fan_mode_method(fan_mode: FanModeType) -> Method<MTSync, ()> {
|
||||
pub(super) fn dbus_create_fan_mode_method(data: DbusU8Type) -> Method<MTSync, ()> {
|
||||
let factory = Factory::new_sync::<()>();
|
||||
factory
|
||||
// method for ledmessage
|
||||
.method("FanMode", (), {
|
||||
move |m| {
|
||||
if let Ok(mut lock) = fan_mode.try_lock() {
|
||||
if let Ok(mut lock) = data.try_lock() {
|
||||
let mut iter = m.msg.iter_init();
|
||||
let byte: u8 = iter.read()?;
|
||||
*lock = Some(byte);
|
||||
@@ -162,21 +162,49 @@ pub(super) fn dbus_create_fan_mode_method(fan_mode: FanModeType) -> Method<MTSyn
|
||||
.inarg::<u8, _>("byte")
|
||||
}
|
||||
|
||||
pub(super) fn dbus_create_charge_limit_method(data: DbusU8Type) -> Method<MTSync, ()> {
|
||||
let factory = Factory::new_sync::<()>();
|
||||
factory
|
||||
// method for ledmessage
|
||||
.method("ChargeLimit", (), {
|
||||
move |m| {
|
||||
if let Ok(mut lock) = data.try_lock() {
|
||||
let mut iter = m.msg.iter_init();
|
||||
let byte: u8 = iter.read()?;
|
||||
*lock = Some(byte);
|
||||
let mret = m
|
||||
.msg
|
||||
.method_return()
|
||||
.append1(format!("Battery charge limit set to {}", byte));
|
||||
Ok(vec![mret])
|
||||
} else {
|
||||
Err(MethodErr::failed("Could not lock daemon for access"))
|
||||
}
|
||||
}
|
||||
})
|
||||
.outarg::<&str, _>("reply")
|
||||
.inarg::<u8, _>("byte")
|
||||
}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub(super) fn dbus_create_tree() -> (
|
||||
Tree<MTSync, ()>,
|
||||
Sender<AuraCommand>,
|
||||
Receiver<AuraCommand>,
|
||||
Receiver<Vec<Vec<u8>>>,
|
||||
FanModeType,
|
||||
DbusU8Type,
|
||||
DbusU8Type,
|
||||
Arc<Signal<()>>,
|
||||
) {
|
||||
let (aura_command_send, aura_command_recv) = channel::<AuraCommand>(1);
|
||||
let (animatrix_send, animatrix_recv) = channel::<Vec<Vec<u8>>>(1);
|
||||
let fan_mode: FanModeType = Arc::new(Mutex::new(None));
|
||||
let fan_mode: DbusU8Type = Arc::new(Mutex::new(None));
|
||||
let charge_limit: DbusU8Type = Arc::new(Mutex::new(None));
|
||||
|
||||
let factory = Factory::new_sync::<()>();
|
||||
|
||||
let effect_cancel_sig = Arc::new(factory.signal("LedCancelEffect", ()));
|
||||
|
||||
let tree = factory
|
||||
.tree(())
|
||||
.add(
|
||||
@@ -194,6 +222,7 @@ pub(super) fn dbus_create_tree() -> (
|
||||
)))
|
||||
.add_m(dbus_create_animatrix_method(Mutex::new(animatrix_send)))
|
||||
.add_m(dbus_create_fan_mode_method(fan_mode.clone()))
|
||||
.add_m(dbus_create_charge_limit_method(charge_limit.clone()))
|
||||
.add_s(effect_cancel_sig.clone()),
|
||||
),
|
||||
)
|
||||
@@ -204,6 +233,7 @@ pub(super) fn dbus_create_tree() -> (
|
||||
aura_command_recv,
|
||||
animatrix_recv,
|
||||
fan_mode,
|
||||
charge_limit,
|
||||
effect_cancel_sig,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user