Refactor dbus commands and internal data structures

This commit is contained in:
Luke
2020-06-29 15:52:49 +12:00
parent f85c8cbc50
commit 32e9e63809
26 changed files with 720 additions and 653 deletions

View File

@@ -1,4 +1,4 @@
use rog_client::BuiltInModeBytes;
use rog_client::aura_modes::AuraModes;
use serde_derive::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
@@ -10,15 +10,15 @@ pub struct Config {
pub fan_mode: u8,
pub bat_charge_limit: u8,
pub brightness: u8,
pub current_mode: [u8; 4],
pub builtin_modes: BuiltInModeBytes,
pub current_mode: u8,
pub builtin_modes: Vec<AuraModes>,
pub mode_performance: FanModeSettings,
}
impl Config {
/// `load` will attempt to read the config, but if it is not found it
/// will create a new default config and write that out.
pub fn load(mut self) -> Self {
pub fn load(mut self, supported_led_modes: &[u8]) -> Self {
let mut file = OpenOptions::new()
.read(true)
.write(true)
@@ -31,15 +31,20 @@ impl Config {
// create a default config here
let mut c = Config::default();
c.bat_charge_limit = 100;
c.current_mode[0] = 0x5d;
c.current_mode[1] = 0xb3;
c.current_mode = 0;
for n in supported_led_modes {
c.builtin_modes.push(AuraModes::from(*n))
}
dbg!(&c.builtin_modes);
// Should be okay to unwrap this as is since it is a Default
let toml = toml::to_string(&c).unwrap();
file.write_all(toml.as_bytes())
let json = serde_json::to_string_pretty(&c).unwrap();
file.write_all(json.as_bytes())
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
self = c;
} else {
self = toml::from_str(&buf)
self = serde_json::from_str(&buf)
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
}
}
@@ -56,7 +61,7 @@ impl Config {
if l == 0 {
panic!("Missing {}", CONFIG_PATH);
} else {
let x: Config = toml::from_str(&buf)
let x: Config = serde_json::from_str(&buf)
.unwrap_or_else(|_| panic!("Could not deserialise {}", CONFIG_PATH));
*self = x;
}
@@ -65,19 +70,29 @@ impl Config {
pub fn write(&self) {
let mut file = File::create(CONFIG_PATH).expect("Couldn't overwrite config");
let toml = toml::to_string(self).expect("Parse config to JSON failed");
file.write_all(toml.as_bytes())
let json = serde_json::to_string_pretty(self).expect("Parse config to JSON failed");
file.write_all(json.as_bytes())
.expect("Saving config failed");
}
pub fn set_field_from(&mut self, bytes: &[u8]) {
if bytes[0] == 0x5a && bytes[1] == 0xba {
self.brightness = bytes[4];
} else if bytes[0] == 0x5d && bytes[1] == 0xb3 {
self.current_mode.copy_from_slice(&bytes[0..4]);
self.builtin_modes.set_field_from(bytes);
pub fn set_mode_data(&mut self, mode: AuraModes) {
let byte: u8 = (&mode).into();
for (index, n) in self.builtin_modes.iter().enumerate() {
if byte == u8::from(n) {
self.builtin_modes[index] = mode;
break;
}
}
}
pub fn get_led_mode_data(&self, num: u8) -> Option<&AuraModes> {
for mode in &self.builtin_modes {
if u8::from(mode) == num {
return Some(mode);
}
}
None
}
}
#[derive(Default, Deserialize, Serialize)]

View File

@@ -11,7 +11,7 @@ use dbus::{channel::Sender, nonblock::Process};
use dbus_tokio::connection;
use log::{error, info, warn};
use rog_client::{DBUS_IFACE, DBUS_NAME, DBUS_PATH};
use rog_client::{aura_modes::AuraModes, DBUS_IFACE, DBUS_NAME, DBUS_PATH};
use std::error::Error;
use std::sync::Arc;
use tokio::sync::Mutex;
@@ -29,7 +29,8 @@ pub(super) type DbusU8Type = Arc<Mutex<Option<u8>>>;
// DBUS processing takes 6ms if not tokiod
pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
let laptop = match_laptop();
let mut config = Config::default().load();
let mut config = Config::default().load(laptop.supported_modes());
info!("Config loaded");
let mut rogcore = RogCore::new(
@@ -59,12 +60,9 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
let mut led_writer = LedWriter::new(
rogcore.get_raw_device_handle(),
laptop.led_endpoint(),
(laptop.min_led_bright(), laptop.max_led_bright()),
laptop.supported_modes().to_owned(),
);
led_writer
.do_command(AuraCommand::ReloadLast, &mut config)
.await?;
led_writer.reload_last_builtin(&mut config).await?;
// Set up the mutexes
let config = Arc::new(Mutex::new(config));
@@ -148,6 +146,7 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
}
});
// For helping with processing signals
let connection1 = connection.clone();
let config1 = config.clone();
tokio::spawn(async move {
@@ -188,20 +187,39 @@ pub async fn start_daemon() -> Result<(), Box<dyn Error>> {
while let Some(command) = aura_command_recv.recv().await {
let mut config = config.lock().await;
match command {
match &command {
AuraCommand::WriteEffect(_) | AuraCommand::WriteMultizone(_) => led_writer
.do_command(command, &mut config)
.await
.unwrap_or_else(|err| warn!("{:?}", err)),
_ => {
led_writer
.do_command(command, &mut config)
.await
.unwrap_or_else(|err| warn!("{:?}", err));
connection
.send(effect_cancel_signal.msg(&DBUS_PATH.into(), &DBUS_IFACE.into()))
.unwrap_or_else(|_| 0);
}
AuraCommand::WriteMode(mode) => match mode {
AuraModes::Aura => {
led_writer
.do_command(command, &mut config)
.await
.unwrap_or_else(|err| warn!("{:?}", err));
}
_ => {
led_writer
.do_command(command, &mut config)
.await
.unwrap_or_else(|err| warn!("{:?}", err));
connection
.send(
effect_cancel_signal
.msg(&DBUS_PATH.into(), &DBUS_IFACE.into())
.append1(true),
)
.unwrap_or_else(|_| 0);
connection
.send(
effect_cancel_signal
.msg(&DBUS_PATH.into(), &DBUS_IFACE.into())
.append1(false),
)
.unwrap_or_else(|_| 0);
}
},
}
}
}

View File

@@ -1,5 +1,11 @@
use crate::{config::Config, led_control::AuraCommand, rogcore::RogCore};
use rog_client::{error::AuraError, BuiltInModeByte};
use rog_client::{
aura_modes::{
AuraModes, BREATHING, COMET, FLASH, HIGHLIGHT, LASER, PULSE, RAIN, RAINBOW, RIPPLE, SINGLE,
STAR, STROBE,
},
error::AuraError,
};
//use keycode::{KeyMap, KeyMappingId, KeyState, KeyboardState};
use crate::virt_device::ConsumerKeys;
use log::{info, warn};
@@ -22,11 +28,7 @@ pub(crate) fn match_laptop() -> LaptopBase {
led_endpoint: 0x04,
//from `lsusb -vd 0b05:1866`
key_endpoint: 0x83,
supported_modes: vec![
BuiltInModeByte::Single,
BuiltInModeByte::Breathing,
BuiltInModeByte::Strobe,
],
supported_modes: vec![SINGLE, BREATHING, STROBE],
support_animatrix: false,
// backlight: Backlight::new("intel_backlight").unwrap(),
};
@@ -71,39 +73,18 @@ fn choose_1866_device(prod: u16) -> LaptopBase {
// GX502, G712
} else if board_name.starts_with("GX502") {
laptop.supported_modes = vec![
BuiltInModeByte::Single,
BuiltInModeByte::Breathing,
BuiltInModeByte::Strobe,
BuiltInModeByte::Rainbow,
BuiltInModeByte::Star,
BuiltInModeByte::Rain,
BuiltInModeByte::Highlight,
BuiltInModeByte::Laser,
BuiltInModeByte::Ripple,
BuiltInModeByte::Pulse,
BuiltInModeByte::Comet,
BuiltInModeByte::Flash,
SINGLE, BREATHING, STROBE, RAINBOW, STAR, RAIN, HIGHLIGHT, LASER, RIPPLE, PULSE, COMET,
FLASH,
];
// GM501
} else if board_name.starts_with("GM501") {
laptop.supported_modes = vec![
BuiltInModeByte::Single,
BuiltInModeByte::Breathing,
BuiltInModeByte::Strobe,
BuiltInModeByte::Rainbow,
];
laptop.supported_modes = vec![SINGLE, BREATHING, STROBE, RAINBOW];
// G531
} else if board_name.starts_with("GX531")
|| board_name.starts_with("G531")
|| board_name.starts_with("G712")
{
laptop.supported_modes = vec![
BuiltInModeByte::Single,
BuiltInModeByte::Breathing,
BuiltInModeByte::Strobe,
BuiltInModeByte::Rainbow,
BuiltInModeByte::Pulse,
];
laptop.supported_modes = vec![SINGLE, BREATHING, STROBE, RAINBOW, PULSE];
} else {
panic!(
"Unsupported laptop, please request support at\nhttps://github.com/flukejones/rog-core"
@@ -121,7 +102,7 @@ pub(super) struct LaptopBase {
max_led_bright: u8,
led_endpoint: u8,
key_endpoint: u8,
supported_modes: Vec<BuiltInModeByte>,
supported_modes: Vec<u8>,
support_animatrix: bool,
//backlight: Backlight,
}
@@ -137,30 +118,68 @@ impl LaptopBase {
key_buf: [u8; 32],
mut aura_command: mpsc::Sender<AuraCommand>,
) -> Result<(), AuraError> {
let mut config = config.lock().await;
match FnKeys::from(key_buf[1]) {
FnKeys::LedBrightUp => {
let mut bright = config.brightness;
if bright < self.max_led_bright {
bright += 1;
info!("Increased LED brightness to {:#?}", bright);
}
aura_command
.send(AuraCommand::BrightInc)
.send(AuraCommand::WriteMode(AuraModes::LedBrightness(bright)))
.await
.unwrap_or_else(|err| warn!("LedBrightUp: {}", err));
}
FnKeys::LedBrightDown => {
let mut bright = config.brightness;
if bright > self.min_led_bright {
bright -= 1;
}
aura_command
.send(AuraCommand::BrightDec)
.send(AuraCommand::WriteMode(AuraModes::LedBrightness(bright)))
.await
.unwrap_or_else(|err| warn!("LedBrightDown: {}", err));
}
FnKeys::AuraNext => {
aura_command
.send(AuraCommand::BuiltinNext)
.await
.unwrap_or_else(|_| {});
if let Ok(idx) = self
.supported_modes
.binary_search(&config.current_mode.into())
{
let idx_next = if idx < self.supported_modes.len() - 1 {
idx + 1
} else {
0
};
if let Some(data) = config.get_led_mode_data(self.supported_modes[idx_next]) {
aura_command
.send(AuraCommand::WriteMode(data.to_owned()))
.await
.unwrap_or_else(|_| {});
}
} else {
warn!("Tried to step to next LED mode while in non-supported mode");
}
}
FnKeys::AuraPrevious => {
aura_command
.send(AuraCommand::BuiltinPrev)
.await
.unwrap_or_else(|_| {});
if let Ok(idx) = self
.supported_modes
.binary_search(&config.current_mode.into())
{
let idx_next = if idx > 0 {
idx - 1
} else {
self.supported_modes.len() - 1
};
if let Some(data) = config.get_led_mode_data(self.supported_modes[idx_next]) {
aura_command
.send(AuraCommand::WriteMode(data.to_owned()))
.await
.unwrap_or_else(|_| {});
}
} else {
warn!("Tried to step to next LED mode while in non-supported mode");
}
}
FnKeys::ScreenBrightUp => rogcore.virt_keys().press(ConsumerKeys::BacklightInc.into()), //self.backlight.step_up(),
FnKeys::ScreenBrightDn => rogcore.virt_keys().press(ConsumerKeys::BacklightDec.into()),
@@ -169,7 +188,6 @@ impl LaptopBase {
FnKeys::AirplaneMode => rogcore.toggle_airplane_mode(),
FnKeys::MicToggle => {}
FnKeys::Fan => {
let mut config = config.lock().await;
rogcore.fan_mode_step(&mut config).unwrap_or_else(|err| {
warn!("Couldn't toggle fan mode: {:?}", err);
});
@@ -199,12 +217,6 @@ impl LaptopBase {
Ok(())
}
pub(super) fn min_led_bright(&self) -> u8 {
self.min_led_bright
}
pub(super) fn max_led_bright(&self) -> u8 {
self.max_led_bright
}
pub(super) fn led_endpoint(&self) -> u8 {
self.led_endpoint
}
@@ -220,7 +232,7 @@ impl LaptopBase {
pub(super) fn usb_product(&self) -> u16 {
self.usb_product
}
pub(super) fn supported_modes(&self) -> &[BuiltInModeByte] {
pub(super) fn supported_modes(&self) -> &[u8] {
&self.supported_modes
}
pub(super) fn support_animatrix(&self) -> bool {

View File

@@ -10,7 +10,10 @@ static LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
use crate::config::Config;
use log::{error, info, warn};
use rog_client::{aura_brightness_bytes, error::AuraError, BuiltInModeByte};
use rog_client::{
aura_brightness_bytes, aura_modes::AuraModes, error::AuraError, fancy::KeyColourArray,
LED_MSG_LEN,
};
use rusb::DeviceHandle;
use std::marker::PhantomData;
use std::ptr::NonNull;
@@ -18,13 +21,8 @@ use std::time::Duration;
#[derive(Clone)]
pub enum AuraCommand {
BrightInc,
BrightDec,
BuiltinNext,
BuiltinPrev,
WriteBytes(Vec<u8>),
WriteMode(AuraModes),
WriteEffect(Vec<Vec<u8>>),
ReloadLast,
WriteMultizone(Vec<Vec<u8>>),
}
@@ -38,8 +36,7 @@ where
C: rusb::UsbContext,
{
handle: NonNull<DeviceHandle<C>>,
bright_min_max: (u8, u8),
supported_modes: Vec<BuiltInModeByte>,
supported_modes: Vec<u8>,
led_endpoint: u8,
initialised: bool,
flip_effect_write: bool,
@@ -58,13 +55,11 @@ where
pub fn new(
device_handle: NonNull<DeviceHandle<C>>,
led_endpoint: u8,
bright_min_max: (u8, u8),
supported_modes: Vec<BuiltInModeByte>,
supported_modes: Vec<u8>,
) -> Self {
LedWriter {
handle: device_handle,
led_endpoint,
bright_min_max,
supported_modes,
initialised: false,
flip_effect_write: false,
@@ -87,60 +82,9 @@ where
}
match command {
AuraCommand::BrightInc => {
let mut bright = config.brightness;
if bright < self.bright_min_max.1 {
bright += 1;
config.brightness = bright;
let bytes = aura_brightness_bytes(bright);
self.set_and_save(&bytes, config).await?;
info!("Increased LED brightness to {:#?}", bright);
}
}
AuraCommand::BrightDec => {
let mut bright = config.brightness;
if bright > self.bright_min_max.0 {
bright -= 1;
config.brightness = bright;
let bytes = aura_brightness_bytes(bright);
self.set_and_save(&bytes, config).await?;
info!("Decreased LED brightness to {:#?}", bright);
}
}
AuraCommand::BuiltinNext => {
// TODO: different path for multi-zone (byte 2 controlled, non-zero)
let mode_curr = config.current_mode[3];
if let Ok(idx) = self.supported_modes.binary_search(&mode_curr.into()) {
let idx_next = if idx < self.supported_modes.len() - 1 {
idx + 1
} else {
0
};
self.set_builtin(config, idx_next).await?;
} else {
warn!("Tried to step to next LED mode while in non-supported mode");
self.set_builtin(config, 0).await?;
}
}
AuraCommand::BuiltinPrev => {
// TODO: different path for multi-zone (byte 2 controlled, non-zero)
let mode_curr = config.current_mode[3];
if let Ok(idx) = self.supported_modes.binary_search(&mode_curr.into()) {
let idx_next = if idx > 0 {
idx - 1
} else {
self.supported_modes.len() - 1
};
self.set_builtin(config, idx_next).await?;
} else {
warn!("Tried to step to next LED mode while in non-supported mode");
self.set_builtin(config, 0).await?;
}
}
AuraCommand::WriteBytes(bytes) => self.set_and_save(&bytes, config).await?,
AuraCommand::WriteMode(mode) => self.set_and_save(mode, config).await?,
AuraCommand::WriteMultizone(effect) => self.write_multizone(effect).await?,
AuraCommand::WriteEffect(effect) => self.write_effect(effect).await?,
AuraCommand::ReloadLast => self.reload_last_builtin(&config).await?,
}
Ok(())
}
@@ -162,17 +106,6 @@ where
Ok(())
}
#[inline]
async fn write_array_of_bytes(&self, messages: &[&[u8]]) -> Result<(), AuraError> {
for message in messages {
self.write_bytes(*message).await?;
self.write_bytes(&LED_SET).await?;
}
// Changes won't persist unless apply is set
self.write_bytes(&LED_APPLY).await?;
Ok(())
}
/// Write an effect block
///
/// `aura_effect_init` must be called any effect routine, and called only once.
@@ -202,34 +135,55 @@ where
}
/// Used to set a builtin mode and save the settings for it
///
/// This needs to be universal so that settings applied by dbus stick
#[inline]
async fn set_and_save(&self, bytes: &[u8], config: &mut Config) -> Result<(), AuraError> {
let mode = BuiltInModeByte::from(bytes[3]);
// safety pass-through of possible effect write
if bytes[1] == 0xbc {
self.write_bytes(bytes).await?;
return Ok(());
} else if self.supported_modes.contains(&mode) || bytes[1] == 0xba {
let messages = [bytes];
self.write_array_of_bytes(&messages).await?;
config.set_field_from(bytes);
config.write();
return Ok(());
async fn set_and_save(&self, mode: AuraModes, config: &mut Config) -> Result<(), AuraError> {
match mode {
AuraModes::Aura => {
let bytes = KeyColourArray::get_init_msg();
self.write_bytes(&bytes).await?;
return Ok(());
}
AuraModes::LedBrightness(n) => {
let bytes: [u8; LED_MSG_LEN] = (&mode).into();
self.write_bytes(&bytes).await?;
config.brightness = n;
config.write();
info!("LED brightness set to {:#?}", n);
return Ok(());
}
_ => {
let mode_num: u8 = u8::from(&mode).into();
if self.supported_modes.contains(&mode_num) {
let bytes: [u8; LED_MSG_LEN] = (&mode).into();
self.write_bytes(&bytes).await?;
self.write_bytes(&LED_SET).await?;
// Changes won't persist unless apply is set
self.write_bytes(&LED_APPLY).await?;
config.current_mode = mode_num;
config.set_mode_data(mode);
config.write();
info!("Switched LED mode to {:#?}", config.current_mode);
return Ok(());
}
}
}
warn!("{:?} not supported", mode);
Err(AuraError::NotSupported)
}
#[inline]
async fn reload_last_builtin(&self, config: &Config) -> Result<(), AuraError> {
pub async fn reload_last_builtin(&self, config: &Config) -> Result<(), AuraError> {
// set current mode (if any)
if self.supported_modes.len() > 1 {
let mode_curr = config.current_mode[3];
let mode = config
.builtin_modes
.get_field_from(mode_curr)
.get_led_mode_data(config.current_mode)
.ok_or(AuraError::NotSupported)?
.to_owned();
let mode: [u8; LED_MSG_LEN] = mode.into();
self.write_bytes(&mode).await?;
info!("Reloaded last used mode");
}
@@ -241,19 +195,4 @@ where
info!("Reloaded last used brightness");
Ok(())
}
#[inline]
async fn set_builtin(&self, config: &mut Config, index: usize) -> Result<(), AuraError> {
if let Some(mode) = self.supported_modes.get(index) {
let mode_next = config
.builtin_modes
.get_field_from(mode.to_owned().into())
.ok_or(AuraError::NotSupported)?
.to_owned();
self.set_and_save(&mode_next, config).await?;
info!("Switched LED mode to {:#?}", self.supported_modes[index]);
return Ok(());
}
Err(AuraError::NotSupported)
}
}

View File

@@ -4,8 +4,10 @@ use env_logger::{Builder, Target};
use gumdrop::Options;
use log::LevelFilter;
use rog_client::{
aura_modes::AuraModes,
cli_options::{LedBrightness, SetAuraBuiltin},
AuraDbusWriter, LED_MSG_LEN,
core_dbus::AuraDbusWriter,
LED_MSG_LEN,
};
static VERSION: &str = "0.12.2";
@@ -67,33 +69,22 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Check for special modes here, eg, per-key or multi-zone
match command {
SetAuraBuiltin::MultiStatic(_) => {
let command: AuraModes = command.into();
let byte_arr = <[[u8; LED_MSG_LEN]; 4]>::from(command);
writer.write_multizone(&byte_arr)?;
}
_ => match writer.write_builtin_mode(&command) {
Ok(msg) => println!("Daemon response: {}", msg),
Err(err) => println!("Error: {}", err),
},
_ => writer.write_builtin_mode(&command.into())?,
}
}
}
if let Some(brightness) = parsed.bright {
match writer.write_brightness(brightness.level()) {
Ok(msg) => println!("Daemon response: {}", msg),
Err(err) => println!("Error: {}", err),
}
writer.write_brightness(brightness.level())?;
}
if let Some(fan_level) = parsed.fan_mode {
match writer.write_fan_mode(fan_level.into()) {
Ok(msg) => println!("Daemon response: {}", msg),
Err(err) => println!("Error: {}", err),
}
writer.write_fan_mode(fan_level.into())?;
}
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),
}
writer.write_charge_limit(charge_limit)?;
}
Ok(())
}

View File

@@ -1,7 +1,6 @@
use crate::config::Config;
use crate::daemon::DbusU8Type;
use crate::led_control::AuraCommand;
use crate::rogcore::FanLevel;
use dbus::tree::{Factory, MTSync, Method, MethodErr, Signal, Tree};
use log::warn;
use rog_client::{DBUS_IFACE, DBUS_PATH};
@@ -15,25 +14,26 @@ pub(super) fn dbus_set_ledmsg(sender: Mutex<Sender<AuraCommand>>) -> Method<MTSy
let factory = Factory::new_sync::<()>();
factory
// method for ledmessage
.method("LedWriteBytes", (), {
.method("SetKeyBacklight", (), {
move |m| {
let bytes: Vec<u8> = m.msg.read1()?;
let json: &str = m.msg.read1()?;
if let Ok(mut lock) = sender.try_lock() {
let command = AuraCommand::WriteBytes(bytes.to_vec());
lock.try_send(command)
.unwrap_or_else(|err| warn!("LedWriteBytes over mpsc failed: {}", err));
let mret = m
.msg
.method_return()
.append1(&format!("Wrote {:x?}", bytes));
Ok(vec![mret])
if let Ok(data) = serde_json::from_str(json) {
let command = AuraCommand::WriteMode(data);
lock.try_send(command).unwrap_or_else(|err| {
warn!("SetKeyBacklight over mpsc failed: {}", err)
});
} else {
warn!("SetKeyBacklight could not deserialise");
}
Ok(vec![])
} else {
Err(MethodErr::failed("Could not lock daemon for access"))
}
}
})
.outarg::<&str, _>("reply")
.inarg::<Vec<u8>, _>("bytearray")
.inarg::<&str, _>("json")
.annotate("org.freedesktop.DBus.Method.NoReply", "true")
}
pub(super) fn dbus_set_ledmultizone(sender: Mutex<Sender<AuraCommand>>) -> Method<MTSync, ()> {
@@ -145,18 +145,14 @@ pub(super) fn dbus_set_fan_mode(data: DbusU8Type) -> Method<MTSync, ()> {
let mut iter = m.msg.iter_init();
let byte: u8 = iter.read()?;
*lock = Some(byte);
let mret = m
.msg
.method_return()
.append1(format!("Fan level set to {:?}", FanLevel::from(byte)));
Ok(vec![mret])
Ok(vec![])
} else {
Err(MethodErr::failed("Could not lock daemon for access"))
}
}
})
.outarg::<&str, _>("reply")
.inarg::<u8, _>("byte")
.annotate("org.freedesktop.DBus.Method.NoReply", "true")
}
pub(super) fn dbus_get_fan_mode(config: Arc<Mutex<Config>>) -> Method<MTSync, ()> {
@@ -201,18 +197,14 @@ pub(super) fn dbus_set_charge_limit(data: DbusU8Type) -> Method<MTSync, ()> {
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])
Ok(vec![])
} else {
Err(MethodErr::failed("Could not lock daemon for access"))
}
}
})
.outarg::<&str, _>("reply")
.inarg::<u8, _>("byte")
.annotate("org.freedesktop.DBus.Method.NoReply", "true")
}
#[allow(clippy::type_complexity)]
@@ -236,7 +228,11 @@ pub(super) fn dbus_create_tree(
let factory = Factory::new_sync::<()>();
let effect_cancel_sig = Arc::new(factory.signal("LedCancelEffect", ()));
let builtin_mode_sig = Arc::new(
factory
.signal("KeyBacklightChanged", ())
.sarg::<bool, _>("value"),
);
let fanmode_changed_sig = Arc::new(factory.signal("FanModeChanged", ()).sarg::<u8, _>("value"));
let chrg_limit_changed_sig = Arc::new(
factory
@@ -258,7 +254,7 @@ pub(super) fn dbus_create_tree(
.add_m(dbus_set_charge_limit(charge_limit.clone()))
.add_m(dbus_get_fan_mode(config.clone()))
.add_m(dbus_get_charge_limit(config))
.add_s(effect_cancel_sig.clone())
.add_s(builtin_mode_sig.clone())
.add_s(fanmode_changed_sig.clone())
.add_s(chrg_limit_changed_sig.clone()),
),
@@ -271,7 +267,7 @@ pub(super) fn dbus_create_tree(
animatrix_recv,
fan_mode,
charge_limit,
effect_cancel_sig,
builtin_mode_sig,
fanmode_changed_sig,
chrg_limit_changed_sig,
)