diff --git a/README.md b/README.md index 91dacc42..718e8739 100644 --- a/README.md +++ b/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 --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 + -f, --fan-mode FAN + +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. diff --git a/rog-client/src/aura_dbus.rs b/rog-client/src/aura_dbus.rs index 8aef63dc..4346b191 100644 --- a/rog-client/src/aura_dbus.rs +++ b/rog-client/src/aura_dbus.rs @@ -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> { + 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, diff --git a/rog-core/src/daemon.rs b/rog-core/src/daemon.rs index 8a8e9015..11ae0b74 100644 --- a/rog-core/src/daemon.rs +++ b/rog-core/src/daemon.rs @@ -16,7 +16,7 @@ use std::error::Error; use std::sync::Arc; use tokio::sync::Mutex; -pub(super) type FanModeType = Arc>>; +pub(super) type DbusU8Type = Arc>>; // Timing is such that: // - interrupt write is minimum 1ms (sometimes lower) @@ -93,6 +93,7 @@ pub async fn start_daemon() -> Result<(), Box> { 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> { .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 diff --git a/rog-core/src/main.rs b/rog-core/src/main.rs index 858b0886..c51d3d1c 100644 --- a/rog-core/src/main.rs +++ b/rog-core/src/main.rs @@ -22,6 +22,8 @@ struct CLIStart { bright: Option, #[options(meta = "FAN", help = "")] fan_mode: Option, + #[options(meta = "CHRG", help = "<20-100>")] + charge_limit: Option, #[options(command)] command: Option, } @@ -87,5 +89,11 @@ pub async fn main() -> Result<(), Box> { 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(()) } diff --git a/rog-core/src/rog_dbus.rs b/rog-core/src/rog_dbus.rs index 731f2012..e4a0be30 100644 --- a/rog-core/src/rog_dbus.rs +++ b/rog-core/src/rog_dbus.rs @@ -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 { +pub(super) fn dbus_create_fan_mode_method(data: DbusU8Type) -> Method { 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("byte") } +pub(super) fn dbus_create_charge_limit_method(data: DbusU8Type) -> Method { + 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::("byte") +} + #[allow(clippy::type_complexity)] pub(super) fn dbus_create_tree() -> ( Tree, Sender, Receiver, Receiver>>, - FanModeType, + DbusU8Type, + DbusU8Type, Arc>, ) { let (aura_command_send, aura_command_recv) = channel::(1); let (animatrix_send, animatrix_recv) = channel::>>(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, ) }