Fix slash enable

This commit is contained in:
Luke Jones
2025-02-17 11:38:29 +13:00
parent 5c3348a9f5
commit ae8ce83583
10 changed files with 112 additions and 51 deletions

View File

@@ -2,6 +2,11 @@
## [Unreleased] ## [Unreleased]
## [v6.1.7]
### Changed
- Fix Slash display enable
## [v6.1.6] ## [v6.1.6]
### Changed ### Changed

28
Cargo.lock generated
View File

@@ -250,7 +250,7 @@ checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b"
[[package]] [[package]]
name = "asusctl" name = "asusctl"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"dmi_id", "dmi_id",
"env_logger", "env_logger",
@@ -269,7 +269,7 @@ dependencies = [
[[package]] [[package]]
name = "asusd" name = "asusd"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"cargo-husky", "cargo-husky",
"concat-idents", "concat-idents",
@@ -296,7 +296,7 @@ dependencies = [
[[package]] [[package]]
name = "asusd-user" name = "asusd-user"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"config-traits", "config-traits",
"dirs", "dirs",
@@ -1084,7 +1084,7 @@ dependencies = [
[[package]] [[package]]
name = "config-traits" name = "config-traits"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"log", "log",
"ron", "ron",
@@ -1476,7 +1476,7 @@ dependencies = [
[[package]] [[package]]
name = "dmi_id" name = "dmi_id"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"log", "log",
"udev 0.8.0", "udev 0.8.0",
@@ -4743,7 +4743,7 @@ dependencies = [
[[package]] [[package]]
name = "rog-control-center" name = "rog-control-center"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"asusd", "asusd",
"concat-idents", "concat-idents",
@@ -4774,7 +4774,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_anime" name = "rog_anime"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"dmi_id", "dmi_id",
"gif 0.12.0", "gif 0.12.0",
@@ -4788,7 +4788,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_aura" name = "rog_aura"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"dmi_id", "dmi_id",
"log", "log",
@@ -4799,7 +4799,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_dbus" name = "rog_dbus"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"asusd", "asusd",
"rog_anime", "rog_anime",
@@ -4813,7 +4813,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_platform" name = "rog_platform"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"concat-idents", "concat-idents",
"inotify", "inotify",
@@ -4826,7 +4826,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_profiles" name = "rog_profiles"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"log", "log",
"rog_platform", "rog_platform",
@@ -4837,7 +4837,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_scsi" name = "rog_scsi"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"ron", "ron",
"serde", "serde",
@@ -4847,7 +4847,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_simulators" name = "rog_simulators"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"log", "log",
"rog_anime", "rog_anime",
@@ -4857,7 +4857,7 @@ dependencies = [
[[package]] [[package]]
name = "rog_slash" name = "rog_slash"
version = "6.1.6" version = "6.1.7"
dependencies = [ dependencies = [
"dmi_id", "dmi_id",
"serde", "serde",

View File

@@ -1,5 +1,5 @@
[workspace.package] [workspace.package]
version = "6.1.6" version = "6.1.7"
rust-version = "1.82" rust-version = "1.82"
license = "MPL-2.0" license = "MPL-2.0"
readme = "README.md" readme = "README.md"

View File

@@ -575,6 +575,7 @@ fn handle_slash(cmd: &SlashCommand) -> Result<(), Box<dyn std::error::Error>> {
&& cmd.show_on_sleep.is_none() && cmd.show_on_sleep.is_none()
&& cmd.show_on_battery.is_none() && cmd.show_on_battery.is_none()
&& cmd.show_battery_warning.is_none() && cmd.show_battery_warning.is_none()
// && cmd.show_on_lid_closed.is_none()
&& cmd.mode.is_none() && cmd.mode.is_none()
&& !cmd.list && !cmd.list
&& !cmd.enable && !cmd.enable
@@ -620,6 +621,9 @@ fn handle_slash(cmd: &SlashCommand) -> Result<(), Box<dyn std::error::Error>> {
if let Some(show) = cmd.show_battery_warning { if let Some(show) = cmd.show_battery_warning {
proxy.set_show_battery_warning(show)?; proxy.set_show_battery_warning(show)?;
} }
// if let Some(show) = cmd.show_on_lid_closed {
// proxy.set_show_on_lid_closed(show)?;
// }
} }
if cmd.list { if cmd.list {
let res = SlashMode::list(); let res = SlashMode::list();

View File

@@ -26,6 +26,8 @@ pub struct SlashCommand {
pub show_on_sleep: Option<bool>, pub show_on_sleep: Option<bool>,
#[options(short = "b", meta = "", help = "Show the animation on battery")] #[options(short = "b", meta = "", help = "Show the animation on battery")]
pub show_on_battery: Option<bool>, pub show_on_battery: Option<bool>,
// #[options(short = "L", meta = "", help = "Show the animation on lid closed")]
// pub show_on_lid_closed: Option<bool>,
#[options( #[options(
short = "w", short = "w",
meta = "", meta = "",

View File

@@ -18,6 +18,7 @@ pub struct SlashConfig {
pub show_on_sleep: bool, pub show_on_sleep: bool,
pub show_on_battery: bool, pub show_on_battery: bool,
pub show_battery_warning: bool, pub show_battery_warning: bool,
pub show_on_lid_closed: bool,
} }
impl Default for SlashConfig { impl Default for SlashConfig {
@@ -33,6 +34,7 @@ impl Default for SlashConfig {
show_on_sleep: true, show_on_sleep: true,
show_on_battery: true, show_on_battery: true,
show_battery_warning: true, show_battery_warning: true,
show_on_lid_closed: true,
} }
} }
} }

View File

@@ -4,8 +4,7 @@ use config::SlashConfig;
use futures_util::lock::{Mutex, MutexGuard}; use futures_util::lock::{Mutex, MutexGuard};
use rog_platform::hid_raw::HidRaw; use rog_platform::hid_raw::HidRaw;
use rog_platform::usb_raw::USBRaw; use rog_platform::usb_raw::USBRaw;
use rog_slash::usb::{get_options_packet, pkt_set_mode, pkts_for_init}; use rog_slash::usb::{slash_pkt_enable, slash_pkt_init, slash_pkt_options, slash_pkt_set_mode};
use rog_slash::SlashType;
use crate::error::RogError; use crate::error::RogError;
@@ -46,14 +45,14 @@ impl Slash {
pub async fn do_initialization(&self) -> Result<(), RogError> { pub async fn do_initialization(&self) -> Result<(), RogError> {
// Don't try to initialise these models as the asus drivers already did // Don't try to initialise these models as the asus drivers already did
let config = self.config.lock().await; let config = self.config.lock().await;
if !matches!(config.slash_type, SlashType::GA605 | SlashType::GU605) { for pkt in &slash_pkt_init(config.slash_type) {
for pkt in &pkts_for_init(config.slash_type) {
self.write_bytes(pkt).await?; self.write_bytes(pkt).await?;
} }
} self.write_bytes(&slash_pkt_enable(config.slash_type, config.enabled))
.await?;
// Apply config upon initialization // Apply config upon initialization
let option_packets = get_options_packet( let option_packets = slash_pkt_options(
config.slash_type, config.slash_type,
config.enabled, config.enabled,
config.brightness, config.brightness,
@@ -61,7 +60,7 @@ impl Slash {
); );
self.write_bytes(&option_packets).await?; self.write_bytes(&option_packets).await?;
let mode_packets = pkt_set_mode(config.slash_type, config.display_mode); let mode_packets = slash_pkt_set_mode(config.slash_type, config.display_mode);
// self.node.write_bytes(&mode_packets[0])?; // self.node.write_bytes(&mode_packets[0])?;
self.write_bytes(&mode_packets[1]).await?; self.write_bytes(&mode_packets[1]).await?;

View File

@@ -1,8 +1,9 @@
use config_traits::StdConfig; use config_traits::StdConfig;
use log::{debug, error, warn}; use log::{debug, error, warn};
use rog_slash::usb::{ use rog_slash::usb::{
get_battery_saver_packet, get_boot_packet, get_low_battery_packet, get_options_packet, slash_pkt_battery_saver, slash_pkt_boot, slash_pkt_enable, slash_pkt_lid_closed,
get_shutdown_packet, get_sleep_packet, pkt_save, pkt_set_mode, slash_pkt_low_battery, slash_pkt_options, slash_pkt_save, slash_pkt_set_mode,
slash_pkt_shutdown, slash_pkt_sleep,
}; };
use rog_slash::{DeviceState, SlashMode}; use rog_slash::{DeviceState, SlashMode};
use zbus::zvariant::OwnedObjectPath; use zbus::zvariant::OwnedObjectPath;
@@ -58,7 +59,14 @@ impl SlashZbus {
config.brightness config.brightness
}; };
self.0 self.0
.write_bytes(&get_options_packet( .write_bytes(&slash_pkt_enable(config.slash_type, enabled))
.await
.map_err(|err| {
warn!("ctrl_slash::enable {}", err);
})
.ok();
self.0
.write_bytes(&slash_pkt_options(
config.slash_type, config.slash_type,
enabled, enabled,
brightness, brightness,
@@ -88,7 +96,7 @@ impl SlashZbus {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
let enabled = brightness > 0; let enabled = brightness > 0;
self.0 self.0
.write_bytes(&get_options_packet( .write_bytes(&slash_pkt_options(
config.slash_type, config.slash_type,
enabled, enabled,
brightness, brightness,
@@ -116,7 +124,7 @@ impl SlashZbus {
async fn set_interval(&self, interval: u8) { async fn set_interval(&self, interval: u8) {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
self.0 self.0
.write_bytes(&get_options_packet( .write_bytes(&slash_pkt_options(
config.slash_type, config.enabled, config.brightness, interval, config.slash_type, config.enabled, config.brightness, interval,
)) ))
.await .await
@@ -140,10 +148,12 @@ impl SlashZbus {
async fn set_mode(&self, mode: SlashMode) -> zbus::Result<()> { async fn set_mode(&self, mode: SlashMode) -> zbus::Result<()> {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
let command_packets = pkt_set_mode(config.slash_type, mode); let command_packets = slash_pkt_set_mode(config.slash_type, mode);
// self.node.write_bytes(&command_packets[0])?; // self.node.write_bytes(&command_packets[0])?;
self.0.write_bytes(&command_packets[1]).await?; self.0.write_bytes(&command_packets[1]).await?;
self.0.write_bytes(&pkt_save(config.slash_type)).await?; self.0
.write_bytes(&slash_pkt_save(config.slash_type))
.await?;
config.display_mode = mode; config.display_mode = mode;
config.write(); config.write();
@@ -167,7 +177,7 @@ impl SlashZbus {
async fn set_show_on_boot(&self, enable: bool) -> zbus::Result<()> { async fn set_show_on_boot(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
self.0 self.0
.write_bytes(&get_boot_packet(config.slash_type, enable)) .write_bytes(&slash_pkt_boot(config.slash_type, enable))
.await?; .await?;
config.show_on_boot = enable; config.show_on_boot = enable;
config.write(); config.write();
@@ -184,7 +194,7 @@ impl SlashZbus {
async fn set_show_on_sleep(&self, enable: bool) -> zbus::Result<()> { async fn set_show_on_sleep(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
self.0 self.0
.write_bytes(&get_sleep_packet(config.slash_type, enable)) .write_bytes(&slash_pkt_sleep(config.slash_type, enable))
.await?; .await?;
config.show_on_sleep = enable; config.show_on_sleep = enable;
config.write(); config.write();
@@ -201,7 +211,7 @@ impl SlashZbus {
async fn set_show_on_shutdown(&self, enable: bool) -> zbus::Result<()> { async fn set_show_on_shutdown(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
self.0 self.0
.write_bytes(&get_shutdown_packet(config.slash_type, enable)) .write_bytes(&slash_pkt_shutdown(config.slash_type, enable))
.await?; .await?;
config.show_on_shutdown = enable; config.show_on_shutdown = enable;
config.write(); config.write();
@@ -218,7 +228,7 @@ impl SlashZbus {
async fn set_show_on_battery(&self, enable: bool) -> zbus::Result<()> { async fn set_show_on_battery(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
self.0 self.0
.write_bytes(&get_battery_saver_packet(config.slash_type, enable)) .write_bytes(&slash_pkt_battery_saver(config.slash_type, enable))
.await?; .await?;
config.show_on_battery = enable; config.show_on_battery = enable;
config.write(); config.write();
@@ -235,12 +245,32 @@ impl SlashZbus {
async fn set_show_battery_warning(&self, enable: bool) -> zbus::Result<()> { async fn set_show_battery_warning(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await; let mut config = self.0.lock_config().await;
self.0 self.0
.write_bytes(&get_low_battery_packet(config.slash_type, enable)) .write_bytes(&slash_pkt_low_battery(config.slash_type, enable))
.await?; .await?;
config.show_battery_warning = enable; config.show_battery_warning = enable;
config.write(); config.write();
Ok(()) Ok(())
} }
#[zbus(property)]
async fn show_on_lid_closed(&self) -> zbus::fdo::Result<bool> {
let config = self.0.lock_config().await;
Ok(config.show_on_lid_closed)
}
#[zbus(property)]
async fn set_show_on_lid_closed(&self, enable: bool) -> zbus::Result<()> {
let mut config = self.0.lock_config().await;
self.0
.write_bytes(&slash_pkt_lid_closed(config.slash_type, enable))
.await?;
self.0
.write_bytes(&slash_pkt_save(config.slash_type))
.await?;
config.show_on_lid_closed = enable;
config.write();
Ok(())
}
} }
impl Reloadable for SlashZbus { impl Reloadable for SlashZbus {
@@ -248,7 +278,7 @@ impl Reloadable for SlashZbus {
debug!("reloading slash settings"); debug!("reloading slash settings");
let config = self.0.lock_config().await; let config = self.0.lock_config().await;
self.0 self.0
.write_bytes(&get_options_packet( .write_bytes(&slash_pkt_options(
config.slash_type, config.slash_type,
config.enabled, config.enabled,
config.brightness, config.brightness,
@@ -272,12 +302,12 @@ impl Reloadable for SlashZbus {
}; };
} }
write_bytes_with_warning!(get_boot_packet, show_on_boot, "show_on_boot"); write_bytes_with_warning!(slash_pkt_boot, show_on_boot, "show_on_boot");
write_bytes_with_warning!(get_sleep_packet, show_on_sleep, "show_on_sleep"); write_bytes_with_warning!(slash_pkt_sleep, show_on_sleep, "show_on_sleep");
write_bytes_with_warning!(get_shutdown_packet, show_on_shutdown, "show_on_shutdown"); write_bytes_with_warning!(slash_pkt_shutdown, show_on_shutdown, "show_on_shutdown");
write_bytes_with_warning!(get_battery_saver_packet, show_on_battery, "show_on_battery"); write_bytes_with_warning!(slash_pkt_battery_saver, show_on_battery, "show_on_battery");
write_bytes_with_warning!( write_bytes_with_warning!(
get_low_battery_packet, slash_pkt_low_battery,
show_battery_warning, show_battery_warning,
"show_battery_warning" "show_battery_warning"
); );

View File

@@ -60,4 +60,10 @@ pub trait Slash {
fn show_on_sleep(&self) -> zbus::Result<bool>; fn show_on_sleep(&self) -> zbus::Result<bool>;
#[zbus(property)] #[zbus(property)]
fn set_show_on_sleep(&self, value: bool) -> zbus::Result<()>; fn set_show_on_sleep(&self, value: bool) -> zbus::Result<()>;
/// ShowOnLidClosed property
#[zbus(property)]
fn show_on_lid_closed(&self) -> zbus::Result<bool>;
#[zbus(property)]
fn set_show_on_lid_closed(&self, value: bool) -> zbus::Result<()>;
} }

View File

@@ -62,7 +62,7 @@ pub const fn report_id(slash_type: SlashType) -> u8 {
/// Get the two device initialization packets. These are required for device /// Get the two device initialization packets. These are required for device
/// start after the laptop boots. /// start after the laptop boots.
#[inline] #[inline]
pub fn pkts_for_init(slash_type: SlashType) -> [SlashUsbPacket; 2] { pub fn slash_pkt_init(slash_type: SlashType) -> [SlashUsbPacket; 2] {
let report_id = report_id(slash_type); let report_id = report_id(slash_type);
let mut pkt1 = [0; PACKET_SIZE]; let mut pkt1 = [0; PACKET_SIZE];
@@ -87,7 +87,20 @@ pub fn pkts_for_init(slash_type: SlashType) -> [SlashUsbPacket; 2] {
} }
#[inline] #[inline]
pub const fn pkt_save(slash_type: SlashType) -> SlashUsbPacket { pub const fn slash_pkt_enable(slash_type: SlashType, enabled: bool) -> SlashUsbPacket {
let mut pkt = [0; PACKET_SIZE];
pkt[0] = report_id(slash_type);
pkt[1] = 0xd8;
pkt[2] = 0x02;
pkt[3] = 0x00;
pkt[4] = 0x01;
pkt[5] = if enabled { 0x00 } else { 0x80 };
pkt
}
#[inline]
pub const fn slash_pkt_save(slash_type: SlashType) -> SlashUsbPacket {
let mut pkt = [0; PACKET_SIZE]; let mut pkt = [0; PACKET_SIZE];
pkt[0] = report_id(slash_type); pkt[0] = report_id(slash_type);
pkt[1] = 0xd4; pkt[1] = 0xd4;
@@ -100,7 +113,7 @@ pub const fn pkt_save(slash_type: SlashType) -> SlashUsbPacket {
} }
#[inline] #[inline]
pub const fn pkt_set_mode(slash_type: SlashType, mode: SlashMode) -> [SlashUsbPacket; 2] { pub const fn slash_pkt_set_mode(slash_type: SlashType, mode: SlashMode) -> [SlashUsbPacket; 2] {
let report_id = report_id(slash_type); let report_id = report_id(slash_type);
let mut pkt1 = [0; PACKET_SIZE]; let mut pkt1 = [0; PACKET_SIZE];
pkt1[0] = report_id; pkt1[0] = report_id;
@@ -133,7 +146,7 @@ pub const fn pkt_set_mode(slash_type: SlashType, mode: SlashMode) -> [SlashUsbPa
] ]
} }
pub const fn get_options_packet( pub const fn slash_pkt_options(
slash_type: SlashType, slash_type: SlashType,
enabled: bool, enabled: bool,
brightness: u8, brightness: u8,
@@ -146,7 +159,7 @@ pub const fn get_options_packet(
] ]
} }
pub const fn get_boot_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { pub const fn slash_pkt_boot(slash_type: SlashType, enabled: bool) -> [u8; 12] {
let typ = report_id(slash_type); let typ = report_id(slash_type);
let status = enabled as u8; let status = enabled as u8;
[ [
@@ -154,7 +167,7 @@ pub const fn get_boot_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] {
] ]
} }
pub const fn get_sleep_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { pub const fn slash_pkt_sleep(slash_type: SlashType, enabled: bool) -> [u8; 12] {
let typ = report_id(slash_type); let typ = report_id(slash_type);
let status = (!enabled) as u8; let status = (!enabled) as u8;
[ [
@@ -162,7 +175,7 @@ pub const fn get_sleep_packet(slash_type: SlashType, enabled: bool) -> [u8; 12]
] ]
} }
pub const fn get_low_battery_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { pub const fn slash_pkt_low_battery(slash_type: SlashType, enabled: bool) -> [u8; 12] {
let typ = report_id(slash_type); let typ = report_id(slash_type);
let status = enabled as u8; let status = enabled as u8;
[ [
@@ -170,7 +183,7 @@ pub const fn get_low_battery_packet(slash_type: SlashType, enabled: bool) -> [u8
] ]
} }
pub const fn get_shutdown_packet(slash_type: SlashType, enabled: bool) -> [u8; 12] { pub const fn slash_pkt_shutdown(slash_type: SlashType, enabled: bool) -> [u8; 12] {
let typ = report_id(slash_type); let typ = report_id(slash_type);
let status = enabled as u8; let status = enabled as u8;
[ [
@@ -178,7 +191,7 @@ pub const fn get_shutdown_packet(slash_type: SlashType, enabled: bool) -> [u8; 1
] ]
} }
pub const fn get_battery_saver_packet(slash_type: SlashType, enabled: bool) -> [u8; 6] { pub const fn slash_pkt_battery_saver(slash_type: SlashType, enabled: bool) -> [u8; 6] {
let typ = report_id(slash_type); let typ = report_id(slash_type);
let status = if enabled { 0x00 } else { 0x80 }; let status = if enabled { 0x00 } else { 0x80 };
[ [
@@ -186,7 +199,7 @@ pub const fn get_battery_saver_packet(slash_type: SlashType, enabled: bool) -> [
] ]
} }
pub const fn get_lid_closed_packet(slash_type: SlashType, enabled: bool) -> [u8; 7] { pub const fn slash_pkt_lid_closed(slash_type: SlashType, enabled: bool) -> [u8; 7] {
let typ = report_id(slash_type); let typ = report_id(slash_type);
let status = if enabled { 0x00 } else { 0x80 }; let status = if enabled { 0x00 } else { 0x80 };
[ [