Fixes to slash merge

This commit is contained in:
Luke D. Jones
2024-04-10 09:13:26 +12:00
parent a737d240be
commit 564992719e
15 changed files with 194 additions and 174 deletions

5
Cargo.lock generated
View File

@@ -3517,6 +3517,7 @@ dependencies = [
"rog_aura",
"rog_platform",
"rog_profiles",
"rog_slash",
"zbus 4.1.2",
]
@@ -3564,7 +3565,7 @@ dependencies = [
[[package]]
name = "rog_slash"
version = "6.0.0-alpha1"
version = "6.0.0-alpha3"
dependencies = [
"cargo-husky",
"dmi_id",
@@ -3576,7 +3577,7 @@ dependencies = [
"serde",
"serde_derive",
"typeshare",
"zbus 4.0.1",
"zbus 4.1.2",
]
[[package]]

View File

@@ -19,6 +19,7 @@ use rog_dbus::zbus_anime::AnimeProxyBlocking;
use rog_dbus::zbus_aura::AuraProxyBlocking;
use rog_dbus::zbus_fan_curves::FanCurvesProxyBlocking;
use rog_dbus::zbus_platform::PlatformProxyBlocking;
use rog_dbus::zbus_slash::SlashProxyBlocking;
use rog_platform::platform::{GpuMode, Properties, ThrottlePolicy};
use rog_profiles::error::ProfileError;
use rog_slash::SlashMode;
@@ -26,7 +27,7 @@ use zbus::blocking::Connection;
use crate::aura_cli::{AuraPowerStates, LedBrightness};
use crate::cli_opts::*;
use crate::slash_cli::{SlashCommand};
use crate::slash_cli::SlashCommand;
mod anime_cli;
mod aura_cli;
@@ -486,38 +487,35 @@ fn verify_brightness(brightness: f32) {
}
}
fn handle_slash(
dbus: &RogDbusClientBlocking<'_>,
cmd: &SlashCommand,
) -> Result<(), Box<dyn std::error::Error>> {
if (
cmd.brightness.is_none() &&
cmd.interval.is_none() &&
cmd.slash_mode.is_none() &&
!cmd.list &&
!cmd.enable &&
!cmd.disable
) || cmd.help
fn handle_slash(conn: &Connection, cmd: &SlashCommand) -> Result<(), Box<dyn std::error::Error>> {
if (cmd.brightness.is_none()
&& cmd.interval.is_none()
&& cmd.slash_mode.is_none()
&& !cmd.list
&& !cmd.enable
&& !cmd.disable)
|| cmd.help
{
println!("Missing arg or command\n\n{}", cmd.self_usage());
if let Some(lst) = cmd.self_command_list() {
println!("\n{}", lst);
}
}
let proxy = SlashProxyBlocking::new(conn)?;
if cmd.enable {
dbus.proxies().slash().set_enabled(true)?;
proxy.set_enabled(true)?;
}
if cmd.disable {
dbus.proxies().slash().set_enabled(false)?;
proxy.set_enabled(false)?;
}
if let Some(brightness) = cmd.brightness {
dbus.proxies().slash().set_brightness(brightness)?;
proxy.set_brightness(brightness)?;
}
if let Some(interval) = cmd.interval {
dbus.proxies().slash().set_interval(interval)?;
proxy.set_interval(interval)?;
}
if let Some(slash_mode) = cmd.slash_mode {
dbus.proxies().slash().set_slash_mode(slash_mode)?;
proxy.set_slash_mode(slash_mode)?;
}
if cmd.list {
let res = SlashMode::list();

View File

@@ -15,9 +15,9 @@ use crate::config::Config;
use crate::ctrl_anime::trait_impls::{CtrlAnimeZbus, ANIME_ZBUS_NAME, ANIME_ZBUS_PATH};
use crate::ctrl_aura::trait_impls::{CtrlAuraZbus, AURA_ZBUS_NAME, AURA_ZBUS_PATH};
use crate::ctrl_fancurves::{CtrlFanCurveZbus, FAN_CURVE_ZBUS_NAME, FAN_CURVE_ZBUS_PATH};
use crate::ctrl_slash::trait_impls::{CtrlSlashZbus, SLASH_ZBUS_NAME, SLASH_ZBUS_PATH};
use crate::error::RogError;
use crate::{task_watch_item, task_watch_item_notify, CtrlTask, ReloadAndNotify};
use crate::ctrl_slash::trait_impls::{CtrlSlashZbus, SLASH_ZBUS_NAME, SLASH_ZBUS_PATH};
const PLATFORM_ZBUS_NAME: &str = "Platform";
const PLATFORM_ZBUS_PATH: &str = "/org/asuslinux";

View File

@@ -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";

View File

@@ -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;
@@ -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);

View File

@@ -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);
})

View File

@@ -11,13 +11,13 @@ use asusd::ctrl_anime::CtrlAnime;
use asusd::ctrl_aura::manager::AuraManager;
use asusd::ctrl_fancurves::CtrlFanCurveZbus;
use asusd::ctrl_platform::CtrlPlatform;
use asusd::ctrl_slash::config::SlashConfig;
use asusd::ctrl_slash::trait_impls::CtrlSlashZbus;
use asusd::ctrl_slash::CtrlSlash;
use asusd::{print_board_info, start_tasks, CtrlTask, DBUS_NAME};
use config_traits::{StdConfig, StdConfigLoad, StdConfigLoad2, StdConfigLoad3};
use log::{error, info};
use zbus::fdo::ObjectManager;
use asusd::ctrl_slash::config::SlashConfig;
use asusd::ctrl_slash::CtrlSlash;
use asusd::ctrl_slash::trait_impls::CtrlSlashZbus;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
@@ -114,7 +114,8 @@ async fn start_daemon() -> Result<(), Box<dyn Error>> {
let zbus = CtrlSlashZbus(Arc::new(Mutex::new(ctrl)));
// Currently, the Slash has no need for a loop watching power events, however,
// it could be cool to have the slash do some power-on/off animation
// (It has a built-in power on animation which plays when u plug in the power supply)
// (It has a built-in power on animation which plays when u plug in the power
// supply)
let sig_ctx = CtrlSlashZbus::signal_context(&connection)?;
start_tasks(zbus, &mut connection, sig_ctx).await?;
}

View File

@@ -3,14 +3,14 @@
pub mod config;
/// Control of anime matrix display
pub mod ctrl_anime;
/// Control of Slash led bar
pub mod ctrl_slash;
/// Keyboard LED brightness control, RGB, and LED display modes
pub mod ctrl_aura;
/// Control platform profiles + fan-curves if available
pub mod ctrl_fancurves;
/// Control ASUS bios function such as boot sound, Optimus/Dedicated gfx mode
pub mod ctrl_platform;
/// Control of Slash led bar
pub mod ctrl_slash;
pub mod error;
@@ -146,8 +146,7 @@ pub trait ReloadAndNotify {
}
pub trait ZbusRun {
fn add_to_server(self, server: &mut Connection)
-> impl Future<Output = ()> + Send;
fn add_to_server(self, server: &mut Connection) -> impl Future<Output = ()> + Send;
fn add_to_server_helper(
iface: impl zbus::Interface,

View File

@@ -41,13 +41,17 @@ async fn main() -> Result<()> {
let board_name = dmi.board_name;
let prod_family = dmi.product_family;
info!("Running on {board_name}, product: {prod_family}");
// let is_rog_ally = prod_family == "RC71L";
let is_rog_ally = prod_family == "RC71L";
// tmp-dir must live to the end of program life
let _tmp_dir = tempfile::Builder::new()
let _tmp_dir = match tempfile::Builder::new()
.prefix("rog-gui")
.rand_bytes(0)
.tempdir().unwrap_or_else(|_| on_tmp_dir_exists().unwrap());
.tempdir()
{
Ok(tmp) => tmp,
Err(_) => on_tmp_dir_exists().unwrap(),
};
let args: Vec<String> = args().skip(1).collect();
@@ -80,7 +84,8 @@ async fn main() -> Result<()> {
Err(_e) => {
// TODO: show an error window
Vec::default()
});
}
};
// Startup
let mut config = Config::new().load();
@@ -122,8 +127,7 @@ async fn main() -> Result<()> {
init_tray(supported_properties, states.clone(), config.clone());
}
thread_local! { pub static UI: std::cell::RefCell<Option<MainWindow>> = Default::default()}
;
thread_local! { pub static UI: std::cell::RefCell<Option<MainWindow>> = Default::default()};
i_slint_backend_selector::with_platform(|_| Ok(())).unwrap();
let mut do_once = !startup_in_background;

View File

@@ -2,7 +2,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-04-09 09:23+0000\n"
"POT-Creation-Date: 2024-04-09 21:13+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -12,46 +12,6 @@ msgstr ""
"Language: \n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: rog-control-center/ui/main_window.slint:50
msgctxt "MainWindow"
msgid "ROG"
msgstr ""
#: rog-control-center/ui/main_window.slint:52
msgctxt "Menu1"
msgid "System Control"
msgstr ""
#: rog-control-center/ui/main_window.slint:53
msgctxt "Menu2"
msgid "Keyboard Aura"
msgstr ""
#: rog-control-center/ui/main_window.slint:54
msgctxt "Menu3"
msgid "AniMe Matrix"
msgstr ""
#: rog-control-center/ui/main_window.slint:55
msgctxt "Menu4"
msgid "Fan Curves"
msgstr ""
#: rog-control-center/ui/main_window.slint:56
msgctxt "Menu5"
msgid "App Settings"
msgstr ""
#: rog-control-center/ui/main_window.slint:57
msgctxt "Menu6"
msgid "About"
msgstr ""
#: rog-control-center/ui/main_window.slint:69
msgctxt "MainWindow"
msgid "Quit"
msgstr ""
#: rog-control-center/ui/pages/anime.slint:6
msgctxt "Anime Brightness"
msgid "Off"
@@ -197,46 +157,6 @@ msgctxt "PageAppSettings"
msgid "Enable change notifications"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:27
msgctxt "PageAura"
msgid "Brightness"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:38
msgctxt "PageAura"
msgid "Aura mode"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:56
msgctxt "PageAura"
msgid "Colour 1"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:82
msgctxt "PageAura"
msgid "Colour 2"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:114
msgctxt "PageAura"
msgid "Zone"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:137
msgctxt "PageAura"
msgid "Direction"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:159
msgctxt "PageAura"
msgid "Speed"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:180
msgctxt "PageAura"
msgid "Power Settings"
msgstr ""
#: rog-control-center/ui/pages/fans.slint:27
msgctxt "FanTab"
msgid "This fan is not avilable on this machine"
@@ -442,6 +362,46 @@ msgctxt "PageSystem"
msgid "Throttle Policy on AC"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:27
msgctxt "PageAura"
msgid "Brightness"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:38
msgctxt "PageAura"
msgid "Aura mode"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:56
msgctxt "PageAura"
msgid "Colour 1"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:82
msgctxt "PageAura"
msgid "Colour 2"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:114
msgctxt "PageAura"
msgid "Zone"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:137
msgctxt "PageAura"
msgid "Direction"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:159
msgctxt "PageAura"
msgid "Speed"
msgstr ""
#: rog-control-center/ui/pages/aura.slint:180
msgctxt "PageAura"
msgid "Power Settings"
msgstr ""
#: rog-control-center/ui/types/aura_types.slint:46
msgctxt "Aura power zone"
msgid "Logo"
@@ -652,3 +612,43 @@ msgctxt "AuraPowerGroup"
msgid "Shutdown"
msgstr ""
#: rog-control-center/ui/main_window.slint:50
msgctxt "MainWindow"
msgid "ROG"
msgstr ""
#: rog-control-center/ui/main_window.slint:52
msgctxt "Menu1"
msgid "System Control"
msgstr ""
#: rog-control-center/ui/main_window.slint:53
msgctxt "Menu2"
msgid "Keyboard Aura"
msgstr ""
#: rog-control-center/ui/main_window.slint:54
msgctxt "Menu3"
msgid "AniMe Matrix"
msgstr ""
#: rog-control-center/ui/main_window.slint:55
msgctxt "Menu4"
msgid "Fan Curves"
msgstr ""
#: rog-control-center/ui/main_window.slint:56
msgctxt "Menu5"
msgid "App Settings"
msgstr ""
#: rog-control-center/ui/main_window.slint:57
msgctxt "Menu6"
msgid "About"
msgstr ""
#: rog-control-center/ui/main_window.slint:69
msgctxt "MainWindow"
msgid "Quit"
msgstr ""

View File

@@ -1,5 +1,5 @@
use zbus::proxy;
use rog_slash::SlashMode;
use zbus::proxy;
#[proxy(
interface = "org.asuslinux.Slash",
@@ -10,25 +10,24 @@ trait Slash {
/// EnableDisplay property
#[zbus(property)]
fn enabled(&self) -> zbus::Result<bool>;
// #[zbus(property)]
#[zbus(property)]
fn set_enabled(&self, value: bool) -> zbus::Result<()>;
/// Brightness property
#[zbus(property)]
fn brightness(&self) -> zbus::Result<u8>;
// #[zbus(property)]
#[zbus(property)]
fn set_brightness(&self, value: u8) -> zbus::Result<()>;
/// Interval property
#[zbus(property)]
fn interval(&self) -> zbus::Result<u8>;
// #[zbus(property)]
#[zbus(property)]
fn set_interval(&self, value: u8) -> zbus::Result<()>;
/// Slash modes property
#[zbus(property)]
fn slash_mode(&self) -> zbus::Result<SlashMode>;
// #[zbus(property)]
#[zbus(property)]
fn set_slash_mode(&self, value: SlashMode) -> zbus::Result<()>;
}

View File

@@ -17,6 +17,7 @@ pub enum SlashType {
impl FromStr for SlashType {
type Err = SlashError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(match s {
"ga403" | "GA403" => Self::GA403,
@@ -32,8 +33,8 @@ pub enum SlashMode {
Bounce = 0x10,
Slash = 0x12,
Loading = 0x13,
BitStream = 0x1D,
Transmission = 0x1A,
BitStream = 0x1d,
Transmission = 0x1a,
Flow = 0x19,
Flux = 0x25,
Phantom = 0x24,
@@ -77,7 +78,6 @@ impl FromStr for SlashMode {
}
}
impl Display for SlashMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match &self {
@@ -102,7 +102,6 @@ impl Display for SlashMode {
}
impl SlashMode {
pub fn list() -> [String; 15] {
[
SlashMode::Bounce.to_string(),
@@ -134,4 +133,3 @@ pub struct DeviceState {
pub slash_interval: u8,
pub slash_mode: SlashMode,
}

View File

@@ -9,18 +9,18 @@
//! Step 1 needs to be applied only on fresh system boot.
use dmi_id::DMIID;
#[cfg(feature = "dbus")]
use crate::error::SlashError;
use crate::{SlashMode, SlashType};
const PACKET_SIZE: usize = 128;
const DEV_PAGE: u8 = 0x5e;
pub const VENDOR_ID: u16 = 0x0B05;
pub const PROD_ID: u16 = 0x193B;
pub const VENDOR_ID: u16 = 0x0b05;
pub const PROD_ID: u16 = 0x193b;
pub const PROD_ID_STR: &str = "193B";
pub type SlashUsbPacket = [u8;PACKET_SIZE];
pub type SlashUsbPacket = [u8; PACKET_SIZE];
/// `get_anime_type` is very broad, matching on part of the laptop board name
/// only. For this reason `find_node()` must be used also to verify if the USB
@@ -43,53 +43,53 @@ pub fn get_slash_type() -> Result<SlashType, SlashError> {
/// start after the laptop boots.
#[inline]
pub const fn pkts_for_init() -> [SlashUsbPacket; 2] {
let mut pkt1 = [0;PACKET_SIZE];
let mut pkt1 = [0; PACKET_SIZE];
pkt1[0] = DEV_PAGE;
pkt1[1] = 0xD7;
pkt1[1] = 0xd7;
pkt1[2] = 0x00;
pkt1[3] = 0x00;
pkt1[4] = 0x01;
pkt1[5] = 0xAC;
pkt1[5] = 0xac;
let mut pkt2 = [0;PACKET_SIZE];
let mut pkt2 = [0; PACKET_SIZE];
pkt2[0] = DEV_PAGE;
pkt2[1] = 0xD2;
pkt2[1] = 0xd2;
pkt2[2] = 0x02;
pkt2[3] = 0x01;
pkt2[4] = 0x08;
pkt2[5] = 0xAB;
pkt2[5] = 0xab;
[pkt1, pkt2]
}
#[inline]
pub const fn pkt_save() -> SlashUsbPacket {
let mut pkt = [0;PACKET_SIZE];
let mut pkt = [0; PACKET_SIZE];
pkt[0] = DEV_PAGE;
pkt[1] = 0xD4;
pkt[1] = 0xd4;
pkt[2] = 0x00;
pkt[3] = 0x00;
pkt[4] = 0x01;
pkt[5] = 0xAB;
pkt[5] = 0xab;
pkt
}
#[inline]
pub const fn pkt_set_mode(mode: SlashMode) -> [SlashUsbPacket; 2] {
let mut pkt1 = [0;PACKET_SIZE];
let mut pkt1 = [0; PACKET_SIZE];
pkt1[0] = DEV_PAGE;
pkt1[1] = 0x02;
pkt1[2] = 0x03;
pkt1[3] = 0x00;
pkt1[4] = 0x0C;
pkt1[4] = 0x0c;
let mut pkt2 = [0;PACKET_SIZE];
let mut pkt2 = [0; PACKET_SIZE];
pkt2[0] = DEV_PAGE;
pkt2[1] = 0xD3;
pkt2[1] = 0xd3;
pkt2[2] = 0x04;
pkt2[3] = 0x00;
pkt2[4] = 0x0C;
pkt2[4] = 0x0c;
pkt2[5] = 0x01;
pkt2[6] = mode as u8;
pkt2[7] = 0x02;
@@ -110,19 +110,19 @@ pub const fn pkt_set_mode(mode: SlashMode) -> [SlashUsbPacket; 2] {
pub const fn pkt_set_options(enabled: bool, brightness: u8, interval: u8) -> SlashUsbPacket {
let status_byte = if enabled { 0x01 } else { 0x00 };
let mut pkt = [0;PACKET_SIZE];
let mut pkt = [0; PACKET_SIZE];
pkt[0] = DEV_PAGE;
pkt[1] = 0xD3;
pkt[1] = 0xd3;
pkt[2] = 0x03;
pkt[3] = 0x01;
pkt[4] = 0x08;
pkt[5] = 0xAB;
pkt[6] = 0xFF;
pkt[5] = 0xab;
pkt[6] = 0xff;
pkt[7] = 0x01;
pkt[8] = status_byte;
pkt[9] = 0x06;
pkt[10] = brightness;
pkt[11] = 0xFF;
pkt[11] = 0xff;
pkt[12] = interval;
pkt