aura: refactor modern rog power settings

This commit is contained in:
Luke D. Jones
2023-07-11 20:52:46 +12:00
parent 8be0e7e6bf
commit 50152961c7
15 changed files with 701 additions and 516 deletions

22
Cargo.lock generated
View File

@@ -199,7 +199,7 @@ checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
[[package]]
name = "asusctl"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"asusd",
"cargo-husky",
@@ -218,7 +218,7 @@ dependencies = [
[[package]]
name = "asusd"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"async-trait",
"cargo-husky",
@@ -242,7 +242,7 @@ dependencies = [
[[package]]
name = "asusd-user"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"cargo-husky",
"config-traits",
@@ -781,7 +781,7 @@ dependencies = [
[[package]]
name = "config-traits"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"cargo-husky",
"log",
@@ -2656,7 +2656,7 @@ checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
[[package]]
name = "rog-control-center"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"asusd",
"cargo-husky",
@@ -2689,7 +2689,7 @@ dependencies = [
[[package]]
name = "rog_anime"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"cargo-husky",
"gif",
@@ -2706,7 +2706,7 @@ dependencies = [
[[package]]
name = "rog_aura"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"cargo-husky",
"log",
@@ -2720,7 +2720,7 @@ dependencies = [
[[package]]
name = "rog_dbus"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"cargo-husky",
"rog_anime",
@@ -2732,7 +2732,7 @@ dependencies = [
[[package]]
name = "rog_platform"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"cargo-husky",
"concat-idents",
@@ -2750,7 +2750,7 @@ dependencies = [
[[package]]
name = "rog_profiles"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"cargo-husky",
"serde",
@@ -2762,7 +2762,7 @@ dependencies = [
[[package]]
name = "rog_simulators"
version = "4.7.0-RC1"
version = "4.7.0-RC3"
dependencies = [
"glam",
"log",

View File

@@ -3,7 +3,7 @@ members = ["asusctl", "asusd", "asusd-user", "config-traits", "rog-platform", "r
default-members = ["asusctl", "asusd", "asusd-user", "rog-control-center"]
[workspace.package]
version = "4.7.0-RC1"
version = "4.7.0-RC3"
[workspace.dependencies]
async-trait = "^0.1"

View File

@@ -4,7 +4,7 @@ use gumdrop::Options;
use rog_aura::error::Error;
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour, Direction, Speed};
#[derive(Options)]
#[derive(Options, Debug)]
pub struct LedPowerCommand1 {
#[options(help = "print help message")]
pub help: bool,
@@ -20,63 +20,43 @@ pub struct LedPowerCommand1 {
pub sleep: Option<bool>,
}
#[derive(Options)]
#[derive(Options, Debug)]
pub struct LedPowerCommand2 {
#[options(help = "print help message")]
pub help: bool,
#[options(command)]
pub command: Option<SetAuraEnabled>,
pub command: Option<SetAuraZoneEnabled>,
}
#[derive(Options)]
pub enum SetAuraEnabled {
#[derive(Options, Debug)]
pub enum SetAuraZoneEnabled {
/// Applies to both old and new models
#[options(help = "set <keyboard, logo, lightbar, rearglow> to enabled while device is awake")]
Awake(AuraEnabled),
#[options(
help = "set <keyboard, logo, lightbar, rearglow> to enabled while the device is booting"
)]
Boot(AuraEnabled),
#[options(
help = "set <keyboard, logo, lightbar, rearglow> to animate while the device is suspended"
)]
Sleep(AuraEnabled),
#[options(
help = "set <keyboard, logo, lightbar, rearglow> to animate while the device is shutdown"
)]
Shutdown(AuraEnabled),
#[options(help = "")]
Keyboard(AuraPowerStates),
#[options(help = "")]
Logo(AuraPowerStates),
#[options(help = "")]
Lightbar(AuraPowerStates),
#[options(help = "")]
Lid(AuraPowerStates),
#[options(help = "")]
RearGlow(AuraPowerStates),
}
#[derive(Debug, Clone, Default, Options)]
pub struct AuraEnabled {
#[derive(Debug, Clone, Options)]
pub struct AuraPowerStates {
#[options(help = "print help message")]
pub help: bool,
#[options(meta = "", help = "<true/false>")]
pub keyboard: Option<bool>,
#[options(meta = "", help = "<true/false>")]
pub logo: Option<bool>,
#[options(meta = "", help = "<true/false>")]
pub frontglow: Option<bool>,
#[options(meta = "", help = "<true/false>")]
pub rearglow: Option<bool>,
#[options(meta = "", help = "<true/false>")]
pub lid: Option<bool>,
#[options(help = "defaults to false if option unused")]
pub boot: bool,
#[options(help = "defaults to false if option unused")]
pub awake: bool,
#[options(help = "defaults to false if option unused")]
pub sleep: bool,
#[options(help = "defaults to false if option unused")]
pub shutdown: bool,
}
// impl FromStr for AuraEnabled {
// type Err = Error;
// fn from_str(s: &str) -> Result<Self, Self::Err> {
// let s = s.to_lowercase();
// Ok(Self {
// help: false,
// keyboard: None,
// logo: None,
// lightbar: None,
// })
// }
// }
#[derive(Options)]
pub struct LedBrightness {
level: Option<u32>,

View File

@@ -10,14 +10,15 @@ use gumdrop::{Opt, Options};
use profiles_cli::{FanCurveCommand, ProfileCommand};
use rog_anime::usb::get_anime_type;
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType, Vec2};
use rog_aura::usb::{AuraDevRog1, AuraDevRog2, AuraDevTuf, AuraDevice, AuraPowerDev};
use rog_aura::power::KbAuraPowerState;
use rog_aura::usb::{AuraDevRog1, AuraDevTuf, AuraDevice, AuraPowerDev};
use rog_aura::{self, AuraEffect};
use rog_dbus::RogDbusClientBlocking;
use rog_platform::platform::GpuMode;
use rog_platform::supported::*;
use rog_profiles::error::ProfileError;
use crate::aura_cli::LedBrightness;
use crate::aura_cli::{AuraPowerStates, LedBrightness};
use crate::cli_opts::*;
mod anime_cli;
@@ -503,16 +504,14 @@ fn handle_led_power_1_do_1866(
check(power.lightbar, AuraDevRog1::Lightbar);
let data = AuraPowerDev {
x1866: enabled,
x19b6: vec![],
tuf: vec![],
old_rog: enabled,
..Default::default()
};
dbus.proxies().led().set_led_power(data, true)?;
let data = AuraPowerDev {
x1866: disabled,
x19b6: vec![],
tuf: vec![],
old_rog: disabled,
..Default::default()
};
dbus.proxies().led().set_led_power(data, false)?;
@@ -542,16 +541,14 @@ fn handle_led_power_1_do_tuf(
check(power.keyboard, AuraDevTuf::Keyboard);
let data = AuraPowerDev {
x1866: vec![],
x19b6: vec![],
tuf: enabled,
..Default::default()
};
dbus.proxies().led().set_led_power(data, true)?;
let data = AuraPowerDev {
x1866: vec![],
x19b6: vec![],
tuf: disabled,
..Default::default()
};
dbus.proxies().led().set_led_power(data, false)?;
@@ -591,66 +588,25 @@ fn handle_led_power2(
println!("This option applies only to keyboards with product ID 0x19b6");
}
let mut enabled: Vec<AuraDevRog2> = Vec::new();
let mut disabled: Vec<AuraDevRog2> = Vec::new();
let mut check = |e: Option<bool>, a: AuraDevRog2| {
if let Some(arg) = e {
if arg {
enabled.push(a);
} else {
disabled.push(a);
}
}
let set = |power: &mut KbAuraPowerState, set_to: &AuraPowerStates| {
power.boot = set_to.boot;
power.awake = set_to.awake;
power.sleep = set_to.sleep;
power.shutdown = set_to.shutdown;
};
match pow {
aura_cli::SetAuraEnabled::Boot(arg) => {
check(arg.keyboard, AuraDevRog2::BootKeyb);
check(arg.logo, AuraDevRog2::BootLogo);
check(arg.frontglow, AuraDevRog2::BootBar);
check(arg.rearglow, AuraDevRog2::BootRearGlow);
check(arg.lid, AuraDevRog2::AwakeLid);
}
aura_cli::SetAuraEnabled::Sleep(arg) => {
check(arg.keyboard, AuraDevRog2::SleepKeyb);
check(arg.logo, AuraDevRog2::SleepLogo);
check(arg.frontglow, AuraDevRog2::SleepBar);
check(arg.rearglow, AuraDevRog2::SleepRearGlow);
check(arg.lid, AuraDevRog2::SleepLid);
}
aura_cli::SetAuraEnabled::Awake(arg) => {
check(arg.keyboard, AuraDevRog2::AwakeKeyb);
check(arg.logo, AuraDevRog2::AwakeLogo);
check(arg.frontglow, AuraDevRog2::AwakeBar);
check(arg.rearglow, AuraDevRog2::AwakeRearGlow);
check(arg.lid, AuraDevRog2::AwakeLid);
}
aura_cli::SetAuraEnabled::Shutdown(arg) => {
check(arg.keyboard, AuraDevRog2::ShutdownKeyb);
check(arg.logo, AuraDevRog2::ShutdownLogo);
check(arg.frontglow, AuraDevRog2::ShutdownBar);
check(arg.rearglow, AuraDevRog2::ShutdownRearGlow);
check(arg.lid, AuraDevRog2::ShutdownLid);
let mut enabled = dbus.proxies().led().led_power()?;
if let Some(cmd) = &power.command {
match cmd {
aura_cli::SetAuraZoneEnabled::Keyboard(k) => set(&mut enabled.rog.keyboard, k),
aura_cli::SetAuraZoneEnabled::Logo(l) => set(&mut enabled.rog.logo, l),
aura_cli::SetAuraZoneEnabled::Lightbar(l) => set(&mut enabled.rog.lightbar, l),
aura_cli::SetAuraZoneEnabled::Lid(l) => set(&mut enabled.rog.lid, l),
aura_cli::SetAuraZoneEnabled::RearGlow(r) => set(&mut enabled.rog.rear_glow, r),
}
}
if !enabled.is_empty() {
let data = AuraPowerDev {
tuf: vec![],
x1866: vec![],
x19b6: enabled,
};
dbus.proxies().led().set_led_power(data, true)?;
}
if !disabled.is_empty() {
let data = AuraPowerDev {
tuf: vec![],
x1866: vec![],
x19b6: disabled,
};
dbus.proxies().led().set_led_power(data, false)?;
}
dbus.proxies().led().set_led_power(enabled, true)?;
}
Ok(())

View File

@@ -1,9 +1,12 @@
use std::collections::{BTreeMap, HashSet};
use config_traits::{StdConfig, StdConfigLoad};
use rog_aura::aura_detection::LaptopLedData;
use rog_aura::usb::{AuraDevRog1, AuraDevRog2, AuraDevTuf, AuraDevice, AuraPowerDev};
use log::warn;
use rog_aura::aura_detection::{LaptopLedData, ASUS_KEYBOARD_DEVICES};
use rog_aura::power::AuraPower;
use rog_aura::usb::{AuraDevRog1, AuraDevTuf, AuraDevice, AuraPowerDev};
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT};
use rog_platform::hid_raw::HidRaw;
use serde_derive::{Deserialize, Serialize};
const CONFIG_FILE: &str = "aura.ron";
@@ -15,7 +18,7 @@ const CONFIG_FILE: &str = "aura.ron";
pub enum AuraPowerConfig {
AuraDevTuf(HashSet<AuraDevTuf>),
AuraDevRog1(HashSet<AuraDevRog1>),
AuraDevRog2(HashSet<AuraDevRog2>),
AuraDevRog2(AuraPower),
}
impl AuraPowerConfig {
@@ -27,10 +30,7 @@ impl AuraPowerConfig {
let c: Vec<AuraDevRog1> = c.iter().copied().collect();
AuraDevRog1::to_bytes(&c)
}
AuraPowerConfig::AuraDevRog2(c) => {
let c: Vec<AuraDevRog2> = c.iter().copied().collect();
AuraDevRog2::to_bytes(&c)
}
AuraPowerConfig::AuraDevRog2(c) => c.to_bytes(),
}
}
@@ -78,13 +78,9 @@ impl AuraPowerConfig {
}
}
pub fn set_0x19b6(&mut self, power: AuraDevRog2, on: bool) {
pub fn set_0x19b6(&mut self, power: AuraPower) {
if let Self::AuraDevRog2(p) = self {
if on {
p.insert(power);
} else {
p.remove(&power);
}
*p = power;
}
}
}
@@ -94,18 +90,15 @@ impl From<&AuraPowerConfig> for AuraPowerDev {
match config {
AuraPowerConfig::AuraDevTuf(d) => AuraPowerDev {
tuf: d.iter().copied().collect(),
x1866: vec![],
x19b6: vec![],
..Default::default()
},
AuraPowerConfig::AuraDevRog1(d) => AuraPowerDev {
tuf: vec![],
x1866: d.iter().copied().collect(),
x19b6: vec![],
old_rog: d.iter().copied().collect(),
..Default::default()
},
AuraPowerConfig::AuraDevRog2(d) => AuraPowerDev {
tuf: vec![],
x1866: vec![],
x19b6: d.iter().copied().collect(),
rog: d.clone(),
..Default::default()
},
}
}
@@ -124,8 +117,15 @@ pub struct AuraConfig {
impl StdConfig for AuraConfig {
fn new() -> Self {
// Self::create_default(AuraDevice::X19b6, &LaptopLedData::get_data())
panic!("AuraConfig::new() should not be used, use AuraConfig::create_default() instead");
warn!("AuraConfig: creating new config");
let mut prod_id = AuraDevice::Unknown;
for prod in ASUS_KEYBOARD_DEVICES {
if HidRaw::new(prod.into()).is_ok() {
prod_id = prod;
break;
}
}
Self::create_default(prod_id, &LaptopLedData::get_data())
}
fn config_dir() -> std::path::PathBuf {
@@ -143,24 +143,7 @@ impl AuraConfig {
pub fn create_default(prod_id: AuraDevice, support_data: &LaptopLedData) -> Self {
// create a default config here
let enabled = if prod_id == AuraDevice::X19b6 {
AuraPowerConfig::AuraDevRog2(HashSet::from([
AuraDevRog2::BootLogo,
AuraDevRog2::BootKeyb,
AuraDevRog2::SleepLogo,
AuraDevRog2::SleepKeyb,
AuraDevRog2::AwakeLogo,
AuraDevRog2::AwakeKeyb,
AuraDevRog2::ShutdownLogo,
AuraDevRog2::ShutdownKeyb,
AuraDevRog2::BootBar,
AuraDevRog2::AwakeBar,
AuraDevRog2::SleepBar,
AuraDevRog2::ShutdownBar,
AuraDevRog2::BootRearGlow,
AuraDevRog2::AwakeRearGlow,
AuraDevRog2::SleepRearGlow,
AuraDevRog2::ShutdownRearGlow,
]))
AuraPowerConfig::AuraDevRog2(AuraPower::new_all_on())
} else if prod_id == AuraDevice::Tuf {
AuraPowerConfig::AuraDevTuf(HashSet::from([
AuraDevTuf::Awake,

View File

@@ -53,48 +53,7 @@ impl CtrlKbdLedZbus {
/// Set a variety of states, input is array of enum.
/// `enabled` sets if the sent array should be disabled or enabled
///
/// ```text
/// pub struct AuraPowerDev {
/// tuf: Vec<AuraDevTuf>,
/// x1866: Vec<AuraDevRog1>,
/// x19b6: Vec<AuraDevRog2>,
/// }
/// pub enum AuraDevTuf {
/// Boot,
/// Awake,
/// Sleep,
/// Keyboard,
/// }
/// pub enum AuraDevRog1 {
/// Awake = 0x000002,
/// Keyboard = 0x080000,
/// Lightbar = 0x040500,
/// Boot = 0xc31209,
/// Sleep = 0x300804,
/// }
/// pub enum AuraDevRog2 {
/// BootLogo = 1,
/// BootKeyb = 1 << 1,
/// AwakeLogo = 1 << 2,
/// AwakeKeyb = 1 << 3,
/// SleepLogo = 1 << 4,
/// SleepKeyb = 1 << 5,
/// ShutdownLogo = 1 << 6,
/// ShutdownKeyb = 1 << 7,
/// BootBar = 1 << (7 + 2),
/// AwakeBar = 1 << (7 + 3),
/// SleepBar = 1 << (7 + 4),
/// ShutdownBar = 1 << (7 + 5),
/// BootLid = 1 << (15 + 1),
/// AwakeLid = 1 << (15 + 2),
/// SleepLid = 1 << (15 + 3),
/// ShutdownLid = 1 << (15 + 4),
/// BootRearGlow = 1 << (23 + 1),
/// AwakeRearGlow = 1 << (23 + 2),
/// SleepRearGlow = 1 << (23 + 3),
/// ShutdownRearGlow = 1 << (23 + 4),
/// }
/// ```
/// For Modern ROG devices the "enabled" flag is ignored.
async fn set_led_power(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
@@ -105,12 +64,10 @@ impl CtrlKbdLedZbus {
for p in options.tuf {
ctrl.config.enabled.set_tuf(p, enabled);
}
for p in options.x1866 {
for p in options.old_rog {
ctrl.config.enabled.set_0x1866(p, enabled);
}
for p in options.x19b6 {
ctrl.config.enabled.set_0x19b6(p, enabled);
}
ctrl.config.enabled.set_0x19b6(options.rog);
ctrl.config.write();

View File

@@ -24,7 +24,7 @@ pub struct LedSupportFile(Vec<LaptopLedData>);
/// The powerr zones this laptop supports
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default, Clone)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default, Copy, Clone)]
pub enum PowerZones {
/// The logo on some laptop lids
#[default]

162
rog-aura/src/deprecated.rs Normal file
View File

@@ -0,0 +1,162 @@
//! Older code that is not useful but stillr elevant as a reference
/// # Bits for newer 0x18c6, 0x19B6, 0x1a30, keyboard models
///
/// | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Label |
/// |--------|---------|---------|---------|----------|
/// |00000001| 00000000| 00000000| 00000000|boot_logo_|
/// |00000010| 00000000| 00000000| 00000000|boot_keyb_|
/// |00000100| 00000000| 00000000| 00000000|awake_logo|
/// |00001000| 00000000| 00000000| 00000000|awake_keyb|
/// |00010000| 00000000| 00000000| 00000000|sleep_logo|
/// |00100000| 00000000| 00000000| 00000000|sleep_keyb|
/// |01000000| 00000000| 00000000| 00000000|shut_logo_|
/// |10000000| 00000000| 00000000| 00000000|shut_keyb_|
/// |00000000| 00000010| 00000000| 00000000|boot_bar__|
/// |00000000| 00000100| 00000000| 00000000|awake_bar_|
/// |00000000| 00001000| 00000000| 00000000|sleep_bar_|
/// |00000000| 00010000| 00000000| 00000000|shut_bar__|
/// |00000000| 00000000| 00000001| 00000000|boot_lid__|
/// |00000000| 00000000| 00000010| 00000000|awkae_lid_|
/// |00000000| 00000000| 00000100| 00000000|sleep_lid_|
/// |00000000| 00000000| 00001000| 00000000|shut_lid__|
/// |00000000| 00000000| 00000000| 00000001|boot_rear_|
/// |00000000| 00000000| 00000000| 00000010|awake_rear|
/// |00000000| 00000000| 00000000| 00000100|sleep_rear|
/// |00000000| 00000000| 00000000| 00001000|shut_rear_|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum AuraDevRog2 {
BootLogo = 1,
BootKeyb = 1 << 1,
AwakeLogo = 1 << 2,
AwakeKeyb = 1 << 3,
SleepLogo = 1 << 4,
SleepKeyb = 1 << 5,
ShutdownLogo = 1 << 6,
ShutdownKeyb = 1 << 7,
BootBar = 1 << (7 + 2),
AwakeBar = 1 << (7 + 3),
SleepBar = 1 << (7 + 4),
ShutdownBar = 1 << (7 + 5),
BootLid = 1 << (15 + 1),
AwakeLid = 1 << (15 + 2),
SleepLid = 1 << (15 + 3),
ShutdownLid = 1 << (15 + 4),
BootRearGlow = 1 << (23 + 1),
AwakeRearGlow = 1 << (23 + 2),
SleepRearGlow = 1 << (23 + 3),
ShutdownRearGlow = 1 << (23 + 4),
}
impl From<AuraDevRog2> for u32 {
fn from(a: AuraDevRog2) -> Self {
a as u32
}
}
impl AuraDevRog2 {
pub fn to_bytes(control: &[Self]) -> [u8; 4] {
let mut a: u32 = 0;
for n in control {
a |= *n as u32;
}
[
(a & 0xff) as u8,
((a & 0xff00) >> 8) as u8,
((a & 0xff0000) >> 16) as u8,
((a & 0xff000000) >> 24) as u8,
]
}
pub const fn dev_id() -> &'static str {
"0x196b"
}
}
#[cfg(test)]
mod tests {
use crate::deprecated::AuraDevRog2;
#[test]
fn check_0x19b6_control_bytes_binary_rep() {
fn to_binary_string(bytes: &[AuraDevRog2]) -> String {
let bytes = AuraDevRog2::to_bytes(bytes);
format!(
"{:08b}, {:08b}, {:08b}, {:08b}",
bytes[0], bytes[1], bytes[2], bytes[3]
)
}
let boot_logo_ = to_binary_string(&[AuraDevRog2::BootLogo]);
let boot_keyb_ = to_binary_string(&[AuraDevRog2::BootKeyb]);
let sleep_logo = to_binary_string(&[AuraDevRog2::SleepLogo]);
let sleep_keyb = to_binary_string(&[AuraDevRog2::SleepKeyb]);
let awake_logo = to_binary_string(&[AuraDevRog2::AwakeLogo]);
let awake_keyb = to_binary_string(&[AuraDevRog2::AwakeKeyb]);
let shut_logo_ = to_binary_string(&[AuraDevRog2::ShutdownLogo]);
let shut_keyb_ = to_binary_string(&[AuraDevRog2::ShutdownKeyb]);
let boot_bar__ = to_binary_string(&[AuraDevRog2::BootBar]);
let awake_bar_ = to_binary_string(&[AuraDevRog2::AwakeBar]);
let sleep_bar_ = to_binary_string(&[AuraDevRog2::SleepBar]);
let shut_bar__ = to_binary_string(&[AuraDevRog2::ShutdownBar]);
let boot_lid__ = to_binary_string(&[AuraDevRog2::BootLid]);
let awkae_lid_ = to_binary_string(&[AuraDevRog2::AwakeLid]);
let sleep_lid_ = to_binary_string(&[AuraDevRog2::SleepLid]);
let shut_lid__ = to_binary_string(&[AuraDevRog2::ShutdownLid]);
let boot_rear_ = to_binary_string(&[AuraDevRog2::BootRearGlow]);
let awake_rear = to_binary_string(&[AuraDevRog2::AwakeRearGlow]);
let sleep_rear = to_binary_string(&[AuraDevRog2::SleepRearGlow]);
let shut_rear_ = to_binary_string(&[AuraDevRog2::ShutdownRearGlow]);
assert_eq!(boot_logo_, "00000001, 00000000, 00000000, 00000000");
assert_eq!(boot_keyb_, "00000010, 00000000, 00000000, 00000000");
assert_eq!(awake_logo, "00000100, 00000000, 00000000, 00000000");
assert_eq!(awake_keyb, "00001000, 00000000, 00000000, 00000000");
assert_eq!(sleep_logo, "00010000, 00000000, 00000000, 00000000");
assert_eq!(sleep_keyb, "00100000, 00000000, 00000000, 00000000");
assert_eq!(shut_logo_, "01000000, 00000000, 00000000, 00000000");
assert_eq!(shut_keyb_, "10000000, 00000000, 00000000, 00000000");
//
assert_eq!(boot_bar__, "00000000, 00000010, 00000000, 00000000");
assert_eq!(awake_bar_, "00000000, 00000100, 00000000, 00000000");
assert_eq!(sleep_bar_, "00000000, 00001000, 00000000, 00000000");
assert_eq!(shut_bar__, "00000000, 00010000, 00000000, 00000000");
//
assert_eq!(boot_lid__, "00000000, 00000000, 00000001, 00000000");
assert_eq!(awkae_lid_, "00000000, 00000000, 00000010, 00000000");
assert_eq!(sleep_lid_, "00000000, 00000000, 00000100, 00000000");
assert_eq!(shut_lid__, "00000000, 00000000, 00001000, 00000000");
//
assert_eq!(boot_rear_, "00000000, 00000000, 00000000, 00000001");
assert_eq!(awake_rear, "00000000, 00000000, 00000000, 00000010");
assert_eq!(sleep_rear, "00000000, 00000000, 00000000, 00000100");
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
// All on
let byte1 = [
AuraDevRog2::BootLogo,
AuraDevRog2::BootKeyb,
AuraDevRog2::SleepLogo,
AuraDevRog2::SleepKeyb,
AuraDevRog2::AwakeLogo,
AuraDevRog2::AwakeKeyb,
AuraDevRog2::ShutdownLogo,
AuraDevRog2::ShutdownKeyb,
AuraDevRog2::BootBar,
AuraDevRog2::AwakeBar,
AuraDevRog2::SleepBar,
AuraDevRog2::ShutdownBar,
AuraDevRog2::AwakeLid,
AuraDevRog2::BootLid,
AuraDevRog2::SleepLid,
AuraDevRog2::ShutdownLid,
AuraDevRog2::AwakeRearGlow,
AuraDevRog2::BootRearGlow,
AuraDevRog2::SleepRearGlow,
AuraDevRog2::ShutdownRearGlow,
];
let out = to_binary_string(&byte1);
assert_eq!(out, "11111111, 00011110, 00001111, 00001111");
}
}

View File

@@ -18,6 +18,10 @@ pub mod aura_detection;
pub mod layouts;
pub mod usb;
pub mod power;
mod deprecated;
pub const LED_MSG_LEN: usize = 17;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

343
rog-aura/src/power.rs Normal file
View File

@@ -0,0 +1,343 @@
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
#[cfg(feature = "dbus")]
use zbus::zvariant::Type;
use crate::aura_detection::PowerZones;
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct KbAuraPowerState {
pub zone: PowerZones,
pub boot: bool,
pub awake: bool,
pub sleep: bool,
pub shutdown: bool,
}
impl Default for KbAuraPowerState {
fn default() -> Self {
Self {
zone: PowerZones::Keyboard,
boot: false,
awake: false,
sleep: false,
shutdown: false,
}
}
}
impl KbAuraPowerState {
pub fn to_byte(&self, zone: PowerZones) -> u32 {
match zone {
PowerZones::Logo => {
self.boot as u32
| (self.awake as u32) << 2
| (self.sleep as u32) << 4
| (self.shutdown as u32) << 6
}
PowerZones::Keyboard => {
(self.boot as u32) << 1
| (self.awake as u32) << 3
| (self.sleep as u32) << 5
| (self.shutdown as u32) << 7
}
PowerZones::Lightbar => {
(self.boot as u32) << (7 + 2)
| (self.awake as u32) << (7 + 3)
| (self.sleep as u32) << (7 + 4)
| (self.shutdown as u32) << (7 + 5)
}
PowerZones::Lid => {
(self.boot as u32) << (15 + 1)
| (self.awake as u32) << (15 + 2)
| (self.sleep as u32) << (15 + 3)
| (self.shutdown as u32) << (15 + 4)
}
PowerZones::RearGlow => {
(self.boot as u32) << (23 + 1)
| (self.awake as u32) << (23 + 2)
| (self.sleep as u32) << (23 + 3)
| (self.shutdown as u32) << (23 + 4)
}
}
}
}
/// Track and control the Aura keyboard power state
///
/// # Bits for newer 0x18c6, 0x19B6, 0x1a30, keyboard models
///
/// | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Label |
/// |--------|---------|---------|---------|----------|
/// |00000001| 00000000| 00000000| 00000000|boot_logo_|
/// |00000010| 00000000| 00000000| 00000000|boot_keyb_|
/// |00000100| 00000000| 00000000| 00000000|awake_logo|
/// |00001000| 00000000| 00000000| 00000000|awake_keyb|
/// |00010000| 00000000| 00000000| 00000000|sleep_logo|
/// |00100000| 00000000| 00000000| 00000000|sleep_keyb|
/// |01000000| 00000000| 00000000| 00000000|shut_logo_|
/// |10000000| 00000000| 00000000| 00000000|shut_keyb_|
/// |00000000| 00000010| 00000000| 00000000|boot_bar__|
/// |00000000| 00000100| 00000000| 00000000|awake_bar_|
/// |00000000| 00001000| 00000000| 00000000|sleep_bar_|
/// |00000000| 00010000| 00000000| 00000000|shut_bar__|
/// |00000000| 00000000| 00000001| 00000000|boot_lid__|
/// |00000000| 00000000| 00000010| 00000000|awkae_lid_|
/// |00000000| 00000000| 00000100| 00000000|sleep_lid_|
/// |00000000| 00000000| 00001000| 00000000|shut_lid__|
/// |00000000| 00000000| 00000000| 00000001|boot_rear_|
/// |00000000| 00000000| 00000000| 00000010|awake_rear|
/// |00000000| 00000000| 00000000| 00000100|sleep_rear|
/// |00000000| 00000000| 00000000| 00001000|shut_rear_|
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct AuraPower {
pub keyboard: KbAuraPowerState,
pub logo: KbAuraPowerState,
pub lightbar: KbAuraPowerState,
pub lid: KbAuraPowerState,
pub rear_glow: KbAuraPowerState,
}
impl AuraPower {
pub fn new_all_on() -> Self {
Self {
keyboard: KbAuraPowerState {
zone: PowerZones::Keyboard,
boot: true,
awake: true,
sleep: true,
shutdown: true,
},
logo: KbAuraPowerState {
zone: PowerZones::Logo,
boot: true,
awake: true,
sleep: true,
shutdown: true,
},
lightbar: KbAuraPowerState {
zone: PowerZones::Lightbar,
boot: true,
awake: true,
sleep: true,
shutdown: true,
},
lid: KbAuraPowerState {
zone: PowerZones::Lid,
boot: true,
awake: true,
sleep: true,
shutdown: true,
},
rear_glow: KbAuraPowerState {
zone: PowerZones::RearGlow,
boot: true,
awake: true,
sleep: true,
shutdown: true,
},
}
}
pub fn to_bytes(&self) -> [u8; 4] {
let mut a: u32 = 0;
a |= self.keyboard.to_byte(PowerZones::Keyboard);
a |= self.logo.to_byte(PowerZones::Logo);
a |= self.lid.to_byte(PowerZones::Lid);
a |= self.lightbar.to_byte(PowerZones::Lightbar);
a |= self.rear_glow.to_byte(PowerZones::RearGlow);
[
(a & 0xff) as u8,
((a & 0xff00) >> 8) as u8,
((a & 0xff0000) >> 16) as u8,
((a & 0xff000000) >> 24) as u8,
]
}
}
#[test]
fn check_0x19b6_control_bytes_binary_rep() {
fn to_binary_string(power: &AuraPower) -> String {
let bytes = power.to_bytes();
format!(
"{:08b}, {:08b}, {:08b}, {:08b}",
bytes[0], bytes[1], bytes[2], bytes[3]
)
}
let boot_logo_ = to_binary_string(&AuraPower {
logo: KbAuraPowerState {
boot: true,
..Default::default()
},
..Default::default()
});
let boot_keyb_ = to_binary_string(&AuraPower {
keyboard: KbAuraPowerState {
boot: true,
..Default::default()
},
..Default::default()
});
let sleep_logo = to_binary_string(&AuraPower {
logo: KbAuraPowerState {
sleep: true,
..Default::default()
},
..Default::default()
});
let sleep_keyb = to_binary_string(&AuraPower {
keyboard: KbAuraPowerState {
sleep: true,
..Default::default()
},
..Default::default()
});
let awake_logo = to_binary_string(&AuraPower {
logo: KbAuraPowerState {
awake: true,
..Default::default()
},
..Default::default()
});
let awake_keyb = to_binary_string(&AuraPower {
keyboard: KbAuraPowerState {
awake: true,
..Default::default()
},
..Default::default()
});
let shut_logo_ = to_binary_string(&AuraPower {
logo: KbAuraPowerState {
shutdown: true,
..Default::default()
},
..Default::default()
});
let shut_keyb_ = to_binary_string(&AuraPower {
keyboard: KbAuraPowerState {
shutdown: true,
..Default::default()
},
..Default::default()
});
let boot_bar__ = to_binary_string(&AuraPower {
lightbar: KbAuraPowerState {
boot: true,
..Default::default()
},
..Default::default()
});
let awake_bar_ = to_binary_string(&AuraPower {
lightbar: KbAuraPowerState {
awake: true,
..Default::default()
},
..Default::default()
});
let sleep_bar_ = to_binary_string(&AuraPower {
lightbar: KbAuraPowerState {
sleep: true,
..Default::default()
},
..Default::default()
});
let shut_bar__ = to_binary_string(&AuraPower {
lightbar: KbAuraPowerState {
shutdown: true,
..Default::default()
},
..Default::default()
});
let boot_lid__ = to_binary_string(&AuraPower {
lid: KbAuraPowerState {
boot: true,
..Default::default()
},
..Default::default()
});
let awkae_lid_ = to_binary_string(&AuraPower {
lid: KbAuraPowerState {
awake: true,
..Default::default()
},
..Default::default()
});
let sleep_lid_ = to_binary_string(&AuraPower {
lid: KbAuraPowerState {
sleep: true,
..Default::default()
},
..Default::default()
});
let shut_lid__ = to_binary_string(&AuraPower {
lid: KbAuraPowerState {
shutdown: true,
..Default::default()
},
..Default::default()
});
let boot_rear_ = to_binary_string(&AuraPower {
rear_glow: KbAuraPowerState {
boot: true,
..Default::default()
},
..Default::default()
});
let awake_rear = to_binary_string(&AuraPower {
rear_glow: KbAuraPowerState {
awake: true,
..Default::default()
},
..Default::default()
});
let sleep_rear = to_binary_string(&AuraPower {
rear_glow: KbAuraPowerState {
sleep: true,
..Default::default()
},
..Default::default()
});
let shut_rear_ = to_binary_string(&AuraPower {
rear_glow: KbAuraPowerState {
shutdown: true,
..Default::default()
},
..Default::default()
});
assert_eq!(boot_logo_, "00000001, 00000000, 00000000, 00000000");
assert_eq!(boot_keyb_, "00000010, 00000000, 00000000, 00000000");
assert_eq!(awake_logo, "00000100, 00000000, 00000000, 00000000");
assert_eq!(awake_keyb, "00001000, 00000000, 00000000, 00000000");
assert_eq!(sleep_logo, "00010000, 00000000, 00000000, 00000000");
assert_eq!(sleep_keyb, "00100000, 00000000, 00000000, 00000000");
assert_eq!(shut_logo_, "01000000, 00000000, 00000000, 00000000");
assert_eq!(shut_keyb_, "10000000, 00000000, 00000000, 00000000");
//
assert_eq!(boot_bar__, "00000000, 00000010, 00000000, 00000000");
assert_eq!(awake_bar_, "00000000, 00000100, 00000000, 00000000");
assert_eq!(sleep_bar_, "00000000, 00001000, 00000000, 00000000");
assert_eq!(shut_bar__, "00000000, 00010000, 00000000, 00000000");
//
assert_eq!(boot_lid__, "00000000, 00000000, 00000001, 00000000");
assert_eq!(awkae_lid_, "00000000, 00000000, 00000010, 00000000");
assert_eq!(sleep_lid_, "00000000, 00000000, 00000100, 00000000");
assert_eq!(shut_lid__, "00000000, 00000000, 00001000, 00000000");
//
assert_eq!(boot_rear_, "00000000, 00000000, 00000000, 00000001");
assert_eq!(awake_rear, "00000000, 00000000, 00000000, 00000010");
assert_eq!(sleep_rear, "00000000, 00000000, 00000000, 00000100");
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
// All on
let byte1 = AuraPower::new_all_on();
let out = to_binary_string(&byte1);
assert_eq!(out, "11111111, 00011110, 00001111, 00001111");
}

View File

@@ -6,6 +6,8 @@ use typeshare::typeshare;
#[cfg(feature = "dbus")]
use zbus::zvariant::Type;
use crate::power::AuraPower;
pub const LED_INIT1: [u8; 2] = [0x5d, 0xb9];
pub const LED_INIT2: &str = "]ASUS Tech.Inc."; // ] == 0x5d
pub const LED_INIT3: [u8; 6] = [0x5d, 0x05, 0x20, 0x31, 0, 0x08];
@@ -88,9 +90,14 @@ impl Debug for AuraDevice {
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
pub struct AuraPowerDev {
/// TUF laptops use a similar style of control to the older ROG devices but
/// through WMI
pub tuf: Vec<AuraDevTuf>,
pub x1866: Vec<AuraDevRog1>,
pub x19b6: Vec<AuraDevRog2>,
/// Pre-0x19b6 devices use a different smaller scheme to the newer ROG
/// devices
pub old_rog: Vec<AuraDevRog1>,
/// ASUS standardised control scheme from 2020 onwards
pub rog: AuraPower,
}
#[typeshare]
@@ -177,102 +184,9 @@ impl BitAnd<AuraDevRog1> for AuraDevRog1 {
}
}
/// # Bits for newer 0x18c6, 0x19B6, 0x1a30, keyboard models
///
/// | Byte 1 | Byte 2 | Byte 3 | Byte 4 | Label |
/// |--------|---------|---------|---------|----------|
/// |00000001| 00000000| 00000000| 00000000|boot_logo_|
/// |00000010| 00000000| 00000000| 00000000|boot_keyb_|
/// |00000100| 00000000| 00000000| 00000000|awake_logo|
/// |00001000| 00000000| 00000000| 00000000|awake_keyb|
/// |00010000| 00000000| 00000000| 00000000|sleep_logo|
/// |00100000| 00000000| 00000000| 00000000|sleep_keyb|
/// |01000000| 00000000| 00000000| 00000000|shut_logo_|
/// |10000000| 00000000| 00000000| 00000000|shut_keyb_|
/// |00000000| 00000010| 00000000| 00000000|boot_bar__|
/// |00000000| 00000100| 00000000| 00000000|awake_bar_|
/// |00000000| 00001000| 00000000| 00000000|sleep_bar_|
/// |00000000| 00010000| 00000000| 00000000|shut_bar__|
/// |00000000| 00000000| 00000001| 00000000|boot_lid__|
/// |00000000| 00000000| 00000010| 00000000|awkae_lid_|
/// |00000000| 00000000| 00000100| 00000000|sleep_lid_|
/// |00000000| 00000000| 00001000| 00000000|shut_lid__|
/// |00000000| 00000000| 00000000| 00000001|boot_rear_|
/// |00000000| 00000000| 00000000| 00000010|awake_rear|
/// |00000000| 00000000| 00000000| 00000100|sleep_rear|
/// |00000000| 00000000| 00000000| 00001000|shut_rear_|
#[typeshare]
#[cfg_attr(feature = "dbus", derive(Type), zvariant(signature = "s"))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum AuraDevRog2 {
BootLogo = 1,
BootKeyb = 1 << 1,
AwakeLogo = 1 << 2,
AwakeKeyb = 1 << 3,
SleepLogo = 1 << 4,
SleepKeyb = 1 << 5,
ShutdownLogo = 1 << 6,
ShutdownKeyb = 1 << 7,
BootBar = 1 << (7 + 2),
AwakeBar = 1 << (7 + 3),
SleepBar = 1 << (7 + 4),
ShutdownBar = 1 << (7 + 5),
BootLid = 1 << (15 + 1),
AwakeLid = 1 << (15 + 2),
SleepLid = 1 << (15 + 3),
ShutdownLid = 1 << (15 + 4),
BootRearGlow = 1 << (23 + 1),
AwakeRearGlow = 1 << (23 + 2),
SleepRearGlow = 1 << (23 + 3),
ShutdownRearGlow = 1 << (23 + 4),
}
impl From<AuraDevRog2> for u32 {
fn from(a: AuraDevRog2) -> Self {
a as u32
}
}
impl AuraDevRog2 {
pub fn to_bytes(control: &[Self]) -> [u8; 4] {
let mut a: u32 = 0;
for n in control {
a |= *n as u32;
}
[
(a & 0xff) as u8,
((a & 0xff00) >> 8) as u8,
((a & 0xff0000) >> 16) as u8,
((a & 0xff000000) >> 24) as u8,
]
}
pub const fn dev_id() -> &'static str {
"0x196b"
}
}
impl BitOr<AuraDevRog2> for AuraDevRog2 {
type Output = u16;
fn bitor(self, rhs: AuraDevRog2) -> Self::Output {
self as u16 | rhs as u16
}
}
impl BitAnd<AuraDevRog2> for AuraDevRog2 {
type Output = u16;
fn bitand(self, rhs: AuraDevRog2) -> Self::Output {
self as u16 & rhs as u16
}
}
#[cfg(test)]
mod tests {
use super::AuraDevRog1;
use crate::usb::AuraDevRog2;
#[test]
fn check_0x1866_control_bytes() {
@@ -308,86 +222,4 @@ mod tests {
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
assert_eq!(bytes, [0xff, 0x1f, 0x000f, 0x00]);
}
#[test]
fn check_0x19b6_control_bytes_binary_rep() {
fn to_binary_string(bytes: &[AuraDevRog2]) -> String {
let bytes = AuraDevRog2::to_bytes(bytes);
format!(
"{:08b}, {:08b}, {:08b}, {:08b}",
bytes[0], bytes[1], bytes[2], bytes[3]
)
}
let boot_logo_ = to_binary_string(&[AuraDevRog2::BootLogo]);
let boot_keyb_ = to_binary_string(&[AuraDevRog2::BootKeyb]);
let sleep_logo = to_binary_string(&[AuraDevRog2::SleepLogo]);
let sleep_keyb = to_binary_string(&[AuraDevRog2::SleepKeyb]);
let awake_logo = to_binary_string(&[AuraDevRog2::AwakeLogo]);
let awake_keyb = to_binary_string(&[AuraDevRog2::AwakeKeyb]);
let shut_logo_ = to_binary_string(&[AuraDevRog2::ShutdownLogo]);
let shut_keyb_ = to_binary_string(&[AuraDevRog2::ShutdownKeyb]);
let boot_bar__ = to_binary_string(&[AuraDevRog2::BootBar]);
let awake_bar_ = to_binary_string(&[AuraDevRog2::AwakeBar]);
let sleep_bar_ = to_binary_string(&[AuraDevRog2::SleepBar]);
let shut_bar__ = to_binary_string(&[AuraDevRog2::ShutdownBar]);
let boot_lid__ = to_binary_string(&[AuraDevRog2::BootLid]);
let awkae_lid_ = to_binary_string(&[AuraDevRog2::AwakeLid]);
let sleep_lid_ = to_binary_string(&[AuraDevRog2::SleepLid]);
let shut_lid__ = to_binary_string(&[AuraDevRog2::ShutdownLid]);
let boot_rear_ = to_binary_string(&[AuraDevRog2::BootRearGlow]);
let awake_rear = to_binary_string(&[AuraDevRog2::AwakeRearGlow]);
let sleep_rear = to_binary_string(&[AuraDevRog2::SleepRearGlow]);
let shut_rear_ = to_binary_string(&[AuraDevRog2::ShutdownRearGlow]);
assert_eq!(boot_logo_, "00000001, 00000000, 00000000, 00000000");
assert_eq!(boot_keyb_, "00000010, 00000000, 00000000, 00000000");
assert_eq!(awake_logo, "00000100, 00000000, 00000000, 00000000");
assert_eq!(awake_keyb, "00001000, 00000000, 00000000, 00000000");
assert_eq!(sleep_logo, "00010000, 00000000, 00000000, 00000000");
assert_eq!(sleep_keyb, "00100000, 00000000, 00000000, 00000000");
assert_eq!(shut_logo_, "01000000, 00000000, 00000000, 00000000");
assert_eq!(shut_keyb_, "10000000, 00000000, 00000000, 00000000");
//
assert_eq!(boot_bar__, "00000000, 00000010, 00000000, 00000000");
assert_eq!(awake_bar_, "00000000, 00000100, 00000000, 00000000");
assert_eq!(sleep_bar_, "00000000, 00001000, 00000000, 00000000");
assert_eq!(shut_bar__, "00000000, 00010000, 00000000, 00000000");
//
assert_eq!(boot_lid__, "00000000, 00000000, 00000001, 00000000");
assert_eq!(awkae_lid_, "00000000, 00000000, 00000010, 00000000");
assert_eq!(sleep_lid_, "00000000, 00000000, 00000100, 00000000");
assert_eq!(shut_lid__, "00000000, 00000000, 00001000, 00000000");
//
assert_eq!(boot_rear_, "00000000, 00000000, 00000000, 00000001");
assert_eq!(awake_rear, "00000000, 00000000, 00000000, 00000010");
assert_eq!(sleep_rear, "00000000, 00000000, 00000000, 00000100");
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
// All on
let byte1 = [
AuraDevRog2::BootLogo,
AuraDevRog2::BootKeyb,
AuraDevRog2::SleepLogo,
AuraDevRog2::SleepKeyb,
AuraDevRog2::AwakeLogo,
AuraDevRog2::AwakeKeyb,
AuraDevRog2::ShutdownLogo,
AuraDevRog2::ShutdownKeyb,
AuraDevRog2::BootBar,
AuraDevRog2::AwakeBar,
AuraDevRog2::SleepBar,
AuraDevRog2::ShutdownBar,
AuraDevRog2::AwakeLid,
AuraDevRog2::BootLid,
AuraDevRog2::SleepLid,
AuraDevRog2::ShutdownLid,
AuraDevRog2::AwakeRearGlow,
AuraDevRog2::BootRearGlow,
AuraDevRog2::SleepRearGlow,
AuraDevRog2::ShutdownRearGlow,
];
let out = to_binary_string(&byte1);
assert_eq!(out, "11111111, 00011110, 00001111, 00001111");
}
}

View File

@@ -177,7 +177,7 @@ impl AuraState {
} else {
BTreeMap::new()
},
enabled: dbus.proxies().led().led_powered().unwrap_or_default(),
enabled: dbus.proxies().led().led_power().unwrap_or_default(),
bright: dbus.proxies().led().led_brightness().unwrap_or_default(),
wave_red: [0u8; 22],
wave_green: [0u8; 22],
@@ -427,11 +427,7 @@ impl Default for SystemState {
aura: AuraState {
current_mode: AuraModeNum::Static,
modes: Default::default(),
enabled: AuraPowerDev {
tuf: vec![],
x1866: vec![],
x19b6: vec![],
},
enabled: AuraPowerDev::default(),
..Default::default()
},
anime: AnimeState::default(),

View File

@@ -274,19 +274,48 @@ pub fn start_notifications(
let conn = zbus::Connection::system()
.await
.map_err(|e| {
error!("zbus signal: receive_power_states: {e}");
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
let proxy = LedProxy::new(&conn)
.await
.map_err(|e| {
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
if let Ok(mut p) = proxy.receive_notify_power_states().await {
info!("Started zbus signal thread: receive_notify_power_states");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
if let Ok(mut lock) = page_states1.lock() {
lock.aura.enabled = out.data;
lock.set_notified();
}
}
}
};
});
let page_states1 = page_states.clone();
tokio::spawn(async move {
let conn = zbus::Connection::system()
.await
.map_err(|e| {
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
let proxy = AnimeProxy::new(&conn)
.await
.map_err(|e| {
error!("zbus signal: receive_power_states: {e}");
error!("zbus signal: receive_device_state: {e}");
e
})
.unwrap();
if let Ok(p) = proxy.receive_device_state().await {
info!("Started zbus signal thread: receive_power_states");
info!("Started zbus signal thread: receive_device_state");
p.for_each(|_| {
if let Ok(_lock) = page_states1.lock() {
// TODO: lock.anime.
@@ -320,7 +349,7 @@ pub fn start_notifications(
}
if let Ok(mut p) = proxy.receive_notify_gpu_mux_mode().await {
info!("Started zbus signal thread: receive_power_states");
info!("Started zbus signal thread: receive_notify_gpu_mux_mode");
while let Some(e) = p.next().await {
if let Ok(out) = e.args() {
if out.mode == actual_mux_mode {

View File

@@ -1,12 +1,12 @@
use egui::{RichText, Ui};
use rog_aura::usb::{AuraDevRog1, AuraDevRog2, AuraDevTuf, AuraDevice, AuraPowerDev};
use rog_aura::AuraZone;
use rog_aura::power::{AuraPower, KbAuraPowerState};
use rog_aura::usb::{AuraDevRog1, AuraDevTuf, AuraDevice, AuraPowerDev};
use rog_platform::supported::SupportedFunctions;
use crate::system_state::SystemState;
pub fn aura_power_group(supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
ui.heading("LED settings");
ui.heading("Keyboard LED power settings");
match supported.keyboard_led.dev_id {
AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866 => {
@@ -22,10 +22,10 @@ pub fn aura_power_group(supported: &SupportedFunctions, states: &mut SystemState
fn aura_power1(supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
let enabled_states = &mut states.aura.enabled;
let mut boot = enabled_states.x1866.contains(&AuraDevRog1::Boot);
let mut sleep = enabled_states.x1866.contains(&AuraDevRog1::Sleep);
let mut keyboard = enabled_states.x1866.contains(&AuraDevRog1::Keyboard);
let mut lightbar = enabled_states.x1866.contains(&AuraDevRog1::Lightbar);
let mut boot = enabled_states.old_rog.contains(&AuraDevRog1::Boot);
let mut sleep = enabled_states.old_rog.contains(&AuraDevRog1::Sleep);
let mut keyboard = enabled_states.old_rog.contains(&AuraDevRog1::Keyboard);
let mut lightbar = enabled_states.old_rog.contains(&AuraDevRog1::Lightbar);
if supported.keyboard_led.dev_id == AuraDevice::Tuf {
boot = enabled_states.tuf.contains(&AuraDevTuf::Boot);
sleep = enabled_states.tuf.contains(&AuraDevTuf::Sleep);
@@ -130,8 +130,7 @@ fn aura_power1(supported: &SupportedFunctions, states: &mut SystemState, ui: &mu
let mut send = |enable: bool, data: Vec<AuraDevTuf>| {
let options = AuraPowerDev {
tuf: data,
x1866: vec![],
x19b6: vec![],
..Default::default()
};
// build data to send
states
@@ -153,21 +152,21 @@ fn aura_power1(supported: &SupportedFunctions, states: &mut SystemState, ui: &mu
let mut modify_x1866 = |b: bool, a: AuraDevRog1| {
if b {
enabled.push(a);
if !enabled_states.x1866.contains(&a) {
enabled_states.x1866.push(a);
if !enabled_states.old_rog.contains(&a) {
enabled_states.old_rog.push(a);
}
} else {
disabled.push(a);
// This would be so much better as a hashset
if enabled_states.x1866.contains(&a) {
if enabled_states.old_rog.contains(&a) {
let mut idx = 0;
for (i, n) in enabled_states.x1866.iter().enumerate() {
for (i, n) in enabled_states.old_rog.iter().enumerate() {
if *n == a {
idx = i;
break;
}
}
enabled_states.x1866.remove(idx);
enabled_states.old_rog.remove(idx);
}
}
};
@@ -180,9 +179,8 @@ fn aura_power1(supported: &SupportedFunctions, states: &mut SystemState, ui: &mu
let mut send = |enable: bool, data: Vec<AuraDevRog1>| {
let options = AuraPowerDev {
tuf: vec![],
x1866: data,
x19b6: vec![],
old_rog: data,
..Default::default()
};
// build data to send
states
@@ -202,115 +200,52 @@ fn aura_power1(supported: &SupportedFunctions, states: &mut SystemState, ui: &mu
}
fn aura_power2(supported: &SupportedFunctions, states: &mut SystemState, ui: &mut Ui) {
let enabled_states = &mut states.aura.enabled;
let has_logo = supported.keyboard_led.basic_zones.contains(&AuraZone::Logo);
let has_lightbar = supported
.keyboard_led
.basic_zones
.contains(&AuraZone::BarLeft)
|| supported
.keyboard_led
.basic_zones
.contains(&AuraZone::BarRight);
let AuraPower {
keyboard,
logo,
lightbar,
lid,
rear_glow,
} = &mut states.aura.enabled.rog;
let boot_bar = &mut enabled_states.x19b6.contains(&AuraDevRog2::AwakeBar);
let boot_logo = &mut enabled_states.x19b6.contains(&AuraDevRog2::BootLogo);
let boot_keyb = &mut enabled_states.x19b6.contains(&AuraDevRog2::BootKeyb);
let awake_bar = &mut enabled_states.x19b6.contains(&AuraDevRog2::BootBar);
let awake_logo = &mut enabled_states.x19b6.contains(&AuraDevRog2::AwakeLogo);
let awake_keyb = &mut enabled_states.x19b6.contains(&AuraDevRog2::AwakeKeyb);
let sleep_bar = &mut enabled_states.x19b6.contains(&AuraDevRog2::SleepBar);
let sleep_logo = &mut enabled_states.x19b6.contains(&AuraDevRog2::SleepLogo);
let sleep_keyb = &mut enabled_states.x19b6.contains(&AuraDevRog2::SleepKeyb);
const LABELS: [&str; 4] = ["Boot", "Awake", "Sleep", "Shutdown"];
let mut changed = false;
let mut item = |keyboard: &mut bool, logo: &mut bool, lightbar: &mut bool, ui: &mut Ui| {
ui.horizontal_wrapped(|ui| {
if ui.checkbox(keyboard, "Keyboard").changed() {
changed = true;
}
if has_logo && ui.checkbox(logo, "Logo").changed() {
changed = true;
}
if has_lightbar && ui.checkbox(lightbar, "Lightbar").changed() {
changed = true;
let mut item = |power: &mut KbAuraPowerState, ui: &mut Ui| {
ui.vertical(|ui| {
if supported.keyboard_led.power_zones.contains(&power.zone) {
ui.horizontal_wrapped(|ui| {
ui.label(RichText::new(format!("{:?}", power.zone)).size(14.0));
});
if ui.checkbox(&mut power.boot, LABELS[0]).changed() {
changed = true;
}
if ui.checkbox(&mut power.awake, LABELS[1]).changed() {
changed = true;
}
if ui.checkbox(&mut power.sleep, LABELS[2]).changed() {
changed = true;
}
if ui.checkbox(&mut power.shutdown, LABELS[3]).changed() {
changed = true;
}
}
});
};
ui.horizontal_wrapped(|ui| {
ui.vertical(|ui| {
let h = 16.0;
ui.set_row_height(22.0);
ui.horizontal_wrapped(|ui| {
ui.label(RichText::new("Boot").size(h));
});
ui.horizontal_wrapped(|ui| {
ui.label(RichText::new("Awake").size(h));
});
ui.horizontal_wrapped(|ui| {
ui.label(RichText::new("Sleep").size(h));
});
});
ui.vertical(|ui| {
ui.set_row_height(22.0);
item(boot_keyb, boot_logo, boot_bar, ui);
item(awake_keyb, awake_logo, awake_bar, ui);
item(sleep_keyb, sleep_logo, sleep_bar, ui);
});
item(lid, ui);
item(logo, ui);
item(keyboard, ui);
item(lightbar, ui);
item(rear_glow, ui);
});
if changed {
let mut enabled = Vec::new();
let mut disabled = Vec::new();
let mut modify = |b: bool, a: AuraDevRog2| {
if b {
enabled.push(a);
if !enabled_states.x19b6.contains(&a) {
enabled_states.x19b6.push(a);
}
} else {
disabled.push(a);
// This would be so much better as a hashset
if enabled_states.x19b6.contains(&a) {
let mut idx = 0;
for (i, n) in enabled_states.x19b6.iter().enumerate() {
if *n == a {
idx = i;
break;
}
}
enabled_states.x19b6.remove(idx);
}
}
};
modify(*boot_keyb, AuraDevRog2::BootKeyb);
modify(*sleep_keyb, AuraDevRog2::SleepKeyb);
modify(*awake_keyb, AuraDevRog2::AwakeKeyb);
if supported.keyboard_led.basic_zones.contains(&AuraZone::Logo) {
modify(*boot_logo, AuraDevRog2::BootLogo);
modify(*sleep_logo, AuraDevRog2::SleepLogo);
modify(*awake_logo, AuraDevRog2::AwakeLogo);
}
if supported
.keyboard_led
.basic_zones
.contains(&AuraZone::BarLeft)
{
modify(*boot_bar, AuraDevRog2::AwakeBar);
modify(*sleep_bar, AuraDevRog2::SleepBar);
modify(*awake_bar, AuraDevRog2::BootBar);
}
let mut send = |enable: bool, data: Vec<AuraDevRog2>| {
let mut send = |enable: bool, data: AuraPower| {
let options = AuraPowerDev {
tuf: vec![],
x1866: vec![],
x19b6: data,
rog: data,
..Default::default()
};
// build data to send
states
@@ -323,7 +258,15 @@ fn aura_power2(supported: &SupportedFunctions, states: &mut SystemState, ui: &mu
})
.ok();
};
send(true, enabled);
send(false, disabled);
send(
true,
AuraPower {
keyboard: *keyboard,
logo: *logo,
lightbar: *lightbar,
lid: *lid,
rear_glow: *rear_glow,
},
);
}
}

View File

@@ -79,7 +79,7 @@ trait Led {
// As property doesn't work for AuraPowerDev (complexity of serialization?)
// #[dbus_proxy(property)]
fn led_powered(&self) -> zbus::Result<AuraPowerDev>;
fn led_power(&self) -> zbus::Result<AuraPowerDev>;
}
pub struct LedProxyPerkey<'a>(LedProxyBlocking<'a>);