mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Fixes to slash merge
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use config_traits::{StdConfig, StdConfigLoad};
|
||||
use rog_slash::{DeviceState, SlashMode};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
const CONFIG_FILE: &str = "slash.ron";
|
||||
|
||||
@@ -48,4 +48,4 @@ impl From<&SlashConfig> for DeviceState {
|
||||
slash_mode: config.slash_mode,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ pub mod trait_impls;
|
||||
|
||||
use rog_platform::hid_raw::HidRaw;
|
||||
use rog_platform::usb_raw::USBRaw;
|
||||
use rog_slash::{SlashMode, SlashType};
|
||||
use rog_slash::error::SlashError;
|
||||
use rog_slash::usb::{get_slash_type, pkt_set_mode, pkt_set_options, pkts_for_init};
|
||||
use rog_slash::{SlashMode, SlashType};
|
||||
|
||||
use crate::ctrl_slash::config::SlashConfig;
|
||||
use crate::error::RogError;
|
||||
|
||||
@@ -54,7 +55,7 @@ impl CtrlSlash {
|
||||
};
|
||||
|
||||
let slash_type = get_slash_type()?;
|
||||
if slash_type == SlashType::Unknown {
|
||||
if slash_type == SlashType::Unknown {
|
||||
return Err(RogError::Slash(SlashError::NoDevice));
|
||||
}
|
||||
|
||||
@@ -71,13 +72,16 @@ impl CtrlSlash {
|
||||
}
|
||||
|
||||
fn do_initialization(&self) -> Result<(), RogError> {
|
||||
|
||||
let init_packets = pkts_for_init();
|
||||
self.node.write_bytes(&init_packets[0])?;
|
||||
self.node.write_bytes(&init_packets[1])?;
|
||||
|
||||
// Apply config upon initialization
|
||||
let option_packets = pkt_set_options(self.config.slash_enabled, self.config.slash_brightness, self.config.slash_interval);
|
||||
let option_packets = pkt_set_options(
|
||||
self.config.slash_enabled,
|
||||
self.config.slash_brightness,
|
||||
self.config.slash_interval,
|
||||
);
|
||||
self.node.write_bytes(&option_packets)?;
|
||||
|
||||
let mode_packets = pkt_set_mode(self.config.slash_mode);
|
||||
@@ -99,4 +103,4 @@ impl CtrlSlash {
|
||||
self.node.write_bytes(&command_packets[1])?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
use std::sync::Arc;
|
||||
use log::warn;
|
||||
use zbus::{Connection, interface, SignalContext};
|
||||
use zbus::export::futures_util::lock::Mutex;
|
||||
|
||||
use config_traits::StdConfig;
|
||||
use rog_slash::{DeviceState, SlashMode};
|
||||
use log::warn;
|
||||
use rog_slash::usb::{pkt_set_mode, pkt_set_options};
|
||||
use rog_slash::{DeviceState, SlashMode};
|
||||
use zbus::export::futures_util::lock::Mutex;
|
||||
use zbus::{interface, Connection, SignalContext};
|
||||
|
||||
use crate::ctrl_slash::CtrlSlash;
|
||||
use crate::error::RogError;
|
||||
|
||||
|
||||
pub const SLASH_ZBUS_NAME: &str = "Slash";
|
||||
pub const SLASH_ZBUS_PATH: &str = "/org/asuslinux";
|
||||
|
||||
@@ -24,7 +25,6 @@ impl crate::ZbusRun for CtrlSlashZbus {
|
||||
|
||||
#[interface(name = "org.asuslinux.Slash")]
|
||||
impl CtrlSlashZbus {
|
||||
|
||||
/// Get enabled or not
|
||||
#[zbus(property)]
|
||||
async fn enabled(&self) -> bool {
|
||||
@@ -35,9 +35,17 @@ impl CtrlSlashZbus {
|
||||
/// Set enabled true or false
|
||||
async fn set_enabled(&self, enabled: bool) {
|
||||
let mut lock = self.0.lock().await;
|
||||
let brightness = if enabled && lock.config.slash_brightness == 0 { 0x88 } else { lock.config.slash_brightness };
|
||||
let brightness = if enabled && lock.config.slash_brightness == 0 {
|
||||
0x88
|
||||
} else {
|
||||
lock.config.slash_brightness
|
||||
};
|
||||
lock.node
|
||||
.write_bytes(&pkt_set_options(enabled, brightness, lock.config.slash_interval))
|
||||
.write_bytes(&pkt_set_options(
|
||||
enabled,
|
||||
brightness,
|
||||
lock.config.slash_interval,
|
||||
))
|
||||
.map_err(|err| {
|
||||
warn!("ctrl_slash::set_options {}", err);
|
||||
})
|
||||
@@ -60,7 +68,11 @@ impl CtrlSlashZbus {
|
||||
let mut lock = self.0.lock().await;
|
||||
let enabled = brightness > 0;
|
||||
lock.node
|
||||
.write_bytes(&pkt_set_options(enabled, brightness, lock.config.slash_interval))
|
||||
.write_bytes(&pkt_set_options(
|
||||
enabled,
|
||||
brightness,
|
||||
lock.config.slash_interval,
|
||||
))
|
||||
.map_err(|err| {
|
||||
warn!("ctrl_slash::set_options {}", err);
|
||||
})
|
||||
@@ -81,7 +93,11 @@ impl CtrlSlashZbus {
|
||||
async fn set_interval(&self, interval: u8) {
|
||||
let mut lock = self.0.lock().await;
|
||||
lock.node
|
||||
.write_bytes(&pkt_set_options(lock.config.slash_enabled, lock.config.slash_brightness, interval))
|
||||
.write_bytes(&pkt_set_options(
|
||||
lock.config.slash_enabled,
|
||||
lock.config.slash_brightness,
|
||||
interval,
|
||||
))
|
||||
.map_err(|err| {
|
||||
warn!("ctrl_slash::set_options {}", err);
|
||||
})
|
||||
@@ -142,4 +158,4 @@ impl crate::Reloadable for CtrlSlashZbus {
|
||||
async fn reload(&mut self) -> Result<(), RogError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user