Update readme, slash configs

This commit is contained in:
Luke D. Jones
2025-01-12 17:36:10 +13:00
parent 2123f369ad
commit 128bc3fce1
113 changed files with 1545 additions and 1305 deletions

View File

@@ -9,20 +9,30 @@ const CONFIG_FILE: &str = "slash.ron";
pub struct SlashConfig {
#[serde(skip)]
pub slash_type: SlashType,
pub slash_enabled: bool,
pub slash_brightness: u8,
pub slash_interval: u8,
pub slash_mode: SlashMode,
pub enabled: bool,
pub brightness: u8,
pub display_interval: u8,
pub display_mode: SlashMode,
pub show_on_boot: bool,
pub show_on_shutdown: bool,
pub show_on_sleep: bool,
pub show_on_battery: bool,
pub show_battery_warning: bool
}
impl Default for SlashConfig {
fn default() -> Self {
SlashConfig {
slash_enabled: true,
slash_brightness: 255,
slash_interval: 0,
slash_mode: SlashMode::Bounce,
enabled: true,
brightness: 255,
display_interval: 0,
display_mode: SlashMode::Bounce,
slash_type: SlashType::Unsupported,
show_on_boot: true,
show_on_shutdown: true,
show_on_sleep: true,
show_on_battery: true,
show_battery_warning: true
}
}
}
@@ -45,10 +55,10 @@ impl StdConfigLoad for SlashConfig {}
impl From<&SlashConfig> for DeviceState {
fn from(config: &SlashConfig) -> Self {
DeviceState {
slash_enabled: config.slash_enabled,
slash_brightness: config.slash_brightness,
slash_interval: config.slash_interval,
slash_mode: config.slash_mode,
slash_enabled: config.enabled,
slash_brightness: config.brightness,
slash_interval: config.display_interval,
slash_mode: config.display_mode
}
}
}

View File

@@ -3,7 +3,7 @@ use std::sync::Arc;
use config::SlashConfig;
use rog_platform::hid_raw::HidRaw;
use rog_platform::usb_raw::USBRaw;
use rog_slash::usb::{pkt_set_mode, pkt_set_options, pkts_for_init};
use rog_slash::usb::{get_options_packet, pkt_set_mode, pkts_for_init};
use rog_slash::SlashType;
use tokio::sync::{Mutex, MutexGuard};
@@ -16,14 +16,14 @@ pub mod trait_impls;
pub struct Slash {
hid: Option<Arc<Mutex<HidRaw>>>,
usb: Option<Arc<Mutex<USBRaw>>>,
config: Arc<Mutex<SlashConfig>>,
config: Arc<Mutex<SlashConfig>>
}
impl Slash {
pub fn new(
hid: Option<Arc<Mutex<HidRaw>>>,
usb: Option<Arc<Mutex<USBRaw>>>,
config: Arc<Mutex<SlashConfig>>,
config: Arc<Mutex<SlashConfig>>
) -> Self {
Self { hid, usb, config }
}
@@ -53,15 +53,15 @@ impl Slash {
}
// Apply config upon initialization
let option_packets = pkt_set_options(
let option_packets = get_options_packet(
config.slash_type,
config.slash_enabled,
config.slash_brightness,
config.slash_interval,
config.enabled,
config.brightness,
config.display_interval
);
self.write_bytes(&option_packets).await?;
let mode_packets = pkt_set_mode(config.slash_type, config.slash_mode);
let mode_packets = pkt_set_mode(config.slash_type, config.display_mode);
// self.node.write_bytes(&mode_packets[0])?;
self.write_bytes(&mode_packets[1]).await?;

View File

@@ -1,6 +1,9 @@
use config_traits::StdConfig;
use log::{debug, error, warn};
use rog_slash::usb::{pkt_save, pkt_set_mode, pkt_set_options};
use rog_slash::usb::{
get_battery_saver_packet, get_boot_packet, get_low_battery_packet, get_options_packet,
get_shutdown_packet, get_sleep_packet, pkt_save, pkt_set_mode
};
use rog_slash::{DeviceState, SlashMode};
use zbus::zvariant::OwnedObjectPath;
use zbus::{interface, Connection};
@@ -20,7 +23,7 @@ impl SlashZbus {
pub async fn start_tasks(
mut self,
connection: &Connection,
path: OwnedObjectPath,
path: OwnedObjectPath
) -> Result<(), RogError> {
// let task = zbus.clone();
self.reload()
@@ -42,24 +45,24 @@ impl SlashZbus {
#[zbus(property)]
async fn enabled(&self) -> bool {
let lock = self.0.lock_config().await;
lock.slash_enabled
lock.enabled
}
/// Set enabled true or false
#[zbus(property)]
async fn set_enabled(&self, enabled: bool) {
let mut config = self.0.lock_config().await;
let brightness = if enabled && config.slash_brightness == 0 {
let brightness = if enabled && config.brightness == 0 {
0x88
} else {
config.slash_brightness
config.brightness
};
self.0
.write_bytes(&pkt_set_options(
.write_bytes(&get_options_packet(
config.slash_type,
enabled,
brightness,
config.slash_interval,
config.display_interval
))
.await
.map_err(|err| {
@@ -67,8 +70,8 @@ impl SlashZbus {
})
.ok();
config.slash_enabled = enabled;
config.slash_brightness = brightness;
config.enabled = enabled;
config.brightness = brightness;
config.write();
}
@@ -76,7 +79,7 @@ impl SlashZbus {
#[zbus(property)]
async fn brightness(&self) -> u8 {
let config = self.0.lock_config().await;
config.slash_brightness
config.brightness
}
/// Set brightness level
@@ -85,11 +88,11 @@ impl SlashZbus {
let mut config = self.0.lock_config().await;
let enabled = brightness > 0;
self.0
.write_bytes(&pkt_set_options(
.write_bytes(&get_options_packet(
config.slash_type,
enabled,
brightness,
config.slash_interval,
config.display_interval
))
.await
.map_err(|err| {
@@ -97,15 +100,15 @@ impl SlashZbus {
})
.ok();
config.slash_enabled = enabled;
config.slash_brightness = brightness;
config.enabled = enabled;
config.brightness = brightness;
config.write();
}
#[zbus(property)]
async fn interval(&self) -> u8 {
let config = self.0.lock_config().await;
config.slash_interval
config.display_interval
}
/// Set interval between slash animations (0-255)
@@ -113,11 +116,8 @@ impl SlashZbus {
async fn set_interval(&self, interval: u8) {
let mut config = self.0.lock_config().await;
self.0
.write_bytes(&pkt_set_options(
config.slash_type,
config.slash_enabled,
config.slash_brightness,
interval,
.write_bytes(&get_options_packet(
config.slash_type, config.enabled, config.brightness, interval
))
.await
.map_err(|err| {
@@ -125,40 +125,29 @@ impl SlashZbus {
})
.ok();
config.slash_interval = interval;
config.display_interval = interval;
config.write();
}
#[zbus(property)]
async fn slash_mode(&self) -> u8 {
async fn mode(&self) -> zbus::fdo::Result<u8> {
let config = self.0.lock_config().await;
config.slash_interval
Ok(config.display_interval)
}
/// Set interval between slash animations (0-255)
#[zbus(property)]
async fn set_slash_mode(&self, slash_mode: SlashMode) {
async fn set_mode(&self, mode: SlashMode) -> zbus::Result<()> {
let mut config = self.0.lock_config().await;
let command_packets = pkt_set_mode(config.slash_type, slash_mode);
let command_packets = pkt_set_mode(config.slash_type, mode);
// self.node.write_bytes(&command_packets[0])?;
self.0
.write_bytes(&command_packets[1])
.await
.map_err(|err| {
warn!("ctrl_slash::set_options {}", err);
})
.ok();
self.0
.write_bytes(&pkt_save(config.slash_type))
.await
.map_err(|err| {
warn!("ctrl_slash::set_options {}", err);
})
.ok();
self.0.write_bytes(&command_packets[1]).await?;
self.0.write_bytes(&pkt_save(config.slash_type)).await?;
config.slash_mode = slash_mode;
config.display_mode = mode;
config.write();
Ok(())
}
/// Get the device state as stored by asusd
@@ -167,6 +156,91 @@ impl SlashZbus {
let config = self.0.lock_config().await;
DeviceState::from(&*config)
}
#[zbus(property)]
async fn show_on_boot(&self) -> zbus::fdo::Result<bool> {
let config = self.0.lock_config().await;
Ok(config.show_on_boot)
}
#[zbus(property)]
async fn set_show_on_boot(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await;
self.0
.write_bytes(&get_boot_packet(config.slash_type, enable))
.await?;
config.show_on_boot = enable;
config.write();
Ok(())
}
#[zbus(property)]
async fn show_on_sleep(&self) -> zbus::fdo::Result<bool> {
let config = self.0.lock_config().await;
Ok(config.show_on_sleep)
}
#[zbus(property)]
async fn set_show_on_sleep(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await;
self.0
.write_bytes(&get_sleep_packet(config.slash_type, enable))
.await?;
config.show_on_sleep = enable;
config.write();
Ok(())
}
#[zbus(property)]
async fn show_on_shutdown(&self) -> zbus::fdo::Result<bool> {
let config = self.0.lock_config().await;
Ok(config.show_on_shutdown)
}
#[zbus(property)]
async fn set_show_on_shutdown(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await;
self.0
.write_bytes(&get_shutdown_packet(config.slash_type, enable))
.await?;
config.show_on_shutdown = enable;
config.write();
Ok(())
}
#[zbus(property)]
async fn show_on_battery(&self) -> zbus::fdo::Result<bool> {
let config = self.0.lock_config().await;
Ok(config.show_on_battery)
}
#[zbus(property)]
async fn set_show_on_battery(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await;
self.0
.write_bytes(&get_battery_saver_packet(config.slash_type, enable))
.await?;
config.show_on_battery = enable;
config.write();
Ok(())
}
#[zbus(property)]
async fn show_battery_warning(&self) -> zbus::fdo::Result<bool> {
let config = self.0.lock_config().await;
Ok(config.show_battery_warning)
}
#[zbus(property)]
async fn set_show_battery_warning(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await;
self.0
.write_bytes(&get_low_battery_packet(config.slash_type, enable))
.await?;
config.show_battery_warning = enable;
config.write();
Ok(())
}
}
impl Reloadable for SlashZbus {
@@ -174,17 +248,40 @@ impl Reloadable for SlashZbus {
debug!("reloading slash settings");
let config = self.0.lock_config().await;
self.0
.write_bytes(&pkt_set_options(
.write_bytes(&get_options_packet(
config.slash_type,
config.slash_enabled,
config.slash_brightness,
config.slash_interval,
config.enabled,
config.brightness,
config.display_interval
))
.await
.map_err(|err| {
warn!("ctrl_slash::set_options {}", err);
warn!("set_options {}", err);
})
.ok();
macro_rules! write_bytes_with_warning {
($packet_fn:expr, $cfg:ident, $warn_msg:expr) => {
self.0
.write_bytes(&$packet_fn(config.slash_type, config.$cfg))
.await
.map_err(|err| {
warn!("{} {}", $warn_msg, err);
})
.ok();
};
}
write_bytes_with_warning!(get_boot_packet, show_on_boot, "show_on_boot");
write_bytes_with_warning!(get_sleep_packet, show_on_sleep, "show_on_sleep");
write_bytes_with_warning!(get_shutdown_packet, show_on_shutdown, "show_on_shutdown");
write_bytes_with_warning!(get_battery_saver_packet, show_on_battery, "show_on_battery");
write_bytes_with_warning!(
get_low_battery_packet,
show_battery_warning,
"show_battery_warning"
);
Ok(())
}
}