mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Unify the laptop aura power stuff
This commit is contained in:
@@ -31,7 +31,7 @@ pub struct LedSupportFile(Vec<LaptopLedData>);
|
||||
derive(Type, Value, OwnedValue),
|
||||
zvariant(signature = "u")
|
||||
)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default, Copy, Clone)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default, Copy, Clone)]
|
||||
pub enum PowerZones {
|
||||
/// The logo on some laptop lids
|
||||
#[default]
|
||||
@@ -44,6 +44,8 @@ pub enum PowerZones {
|
||||
Lid = 3,
|
||||
/// The led strip on the rear of some laptops
|
||||
RearGlow = 4,
|
||||
/// On pre-2021 laptops there is either 1 or 2 zones used
|
||||
KeyboardAndLightbar = 5,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize)]
|
||||
|
||||
@@ -8,15 +8,64 @@ use typeshare::typeshare;
|
||||
#[cfg(feature = "dbus")]
|
||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||
|
||||
use crate::aura_detection::PowerZones;
|
||||
use crate::aura_detection::{LaptopLedData, PowerZones};
|
||||
use crate::usb::AuraDevice;
|
||||
|
||||
// Possible API:
|
||||
// # Common parts:
|
||||
// - boot
|
||||
// - awake
|
||||
// - sleep
|
||||
// ## New only
|
||||
// - shutdown
|
||||
//
|
||||
// ## Only only
|
||||
// - keyboard
|
||||
// - lightbar
|
||||
// ## TUF only
|
||||
// - keyboard
|
||||
//
|
||||
// # New has parts:
|
||||
// - keyboard
|
||||
// - lightbar
|
||||
// - logo
|
||||
// - lid
|
||||
// - rear_glow
|
||||
|
||||
#[typeshare]
|
||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum LaptopAuraType {
|
||||
New = 0,
|
||||
Old = 1,
|
||||
Tuf = 2,
|
||||
}
|
||||
|
||||
impl From<AuraDevice> for LaptopAuraType {
|
||||
fn from(value: AuraDevice) -> Self {
|
||||
if value.is_old_style() {
|
||||
Self::Old
|
||||
} else if value.is_tuf_style() {
|
||||
Self::Tuf
|
||||
} else {
|
||||
Self::New
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Meaning of this struct depends on the laptop generation.
|
||||
/// - 2021+, the struct is a single zone with 4 states
|
||||
/// - pre-2021, the struct is 1 or 2 zones and 3 states
|
||||
/// - Tuf, the struct is 1 zone and 3 states
|
||||
#[typeshare]
|
||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct AuraPowerState {
|
||||
pub zone: PowerZones,
|
||||
pub boot: bool,
|
||||
pub awake: bool,
|
||||
pub sleep: bool,
|
||||
/// Ignored for pre-2021 and Tuf
|
||||
pub shutdown: bool,
|
||||
}
|
||||
|
||||
@@ -24,17 +73,77 @@ impl Default for AuraPowerState {
|
||||
/// Defaults all to off
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
boot: false,
|
||||
awake: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
zone: PowerZones::Keyboard,
|
||||
boot: true,
|
||||
awake: true,
|
||||
sleep: true,
|
||||
shutdown: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AuraPowerState {
|
||||
pub fn to_byte(&self, zone: PowerZones) -> u32 {
|
||||
match zone {
|
||||
fn default_for(zone: PowerZones) -> Self {
|
||||
Self {
|
||||
zone,
|
||||
boot: true,
|
||||
awake: true,
|
||||
sleep: true,
|
||||
shutdown: true,
|
||||
}
|
||||
}
|
||||
|
||||
fn tuf_to_bytes(&self) -> Vec<u8> {
|
||||
todo!("0s and 1s for bool array")
|
||||
}
|
||||
|
||||
/// # Bits for older 0x1866 keyboard model
|
||||
///
|
||||
/// Keybord and Lightbar require Awake, Boot and Sleep apply to both
|
||||
/// Keybord and Lightbar regardless of if either are enabled (or Awake is
|
||||
/// enabled)
|
||||
///
|
||||
/// | Byte 1 | Byte 2 | Byte 3 | function | hex |
|
||||
/// |------------|------------|------------|----------|----------|
|
||||
/// | 0000, 0000 | 0000, 0000 | 0000, 0010 | Awake | 00,00,02 |
|
||||
/// | 0000, 1000 | 0000, 0000 | 0000, 0000 | Keyboard | 08,00,00 |
|
||||
/// | 0000, 0100 | 0000, 0101 | 0000, 0000 | Lightbar | 04,05,00 |
|
||||
/// | 1100, 0011 | 0001, 0010 | 0000, 1001 | Boot/Sht | c3,12,09 |
|
||||
/// | 0011, 0000 | 0000, 1000 | 0000, 0100 | Sleep | 30,08,04 |
|
||||
/// | 1111, 1111 | 0001, 1111 | 0000, 1111 | all on | |
|
||||
fn old_to_bytes(&self) -> Vec<u8> {
|
||||
let mut a: u32 = 0;
|
||||
if self.awake {
|
||||
a |= OldAuraPower::Awake as u32;
|
||||
}
|
||||
if self.boot {
|
||||
a |= OldAuraPower::Boot as u32;
|
||||
}
|
||||
if self.sleep {
|
||||
a |= OldAuraPower::Sleep as u32;
|
||||
}
|
||||
if matches!(
|
||||
self.zone,
|
||||
PowerZones::Keyboard | PowerZones::KeyboardAndLightbar
|
||||
) {
|
||||
a |= OldAuraPower::Keyboard as u32;
|
||||
}
|
||||
if matches!(
|
||||
self.zone,
|
||||
PowerZones::Lightbar | PowerZones::KeyboardAndLightbar
|
||||
) {
|
||||
a |= OldAuraPower::Lightbar as u32;
|
||||
}
|
||||
vec![
|
||||
((a & 0xff0000) >> 16) as u8,
|
||||
((a & 0xff00) >> 8) as u8,
|
||||
(a & 0xff) as u8,
|
||||
0x00,
|
||||
]
|
||||
}
|
||||
|
||||
fn new_to_byte(&self) -> u32 {
|
||||
match self.zone {
|
||||
PowerZones::Logo => {
|
||||
self.boot as u32
|
||||
| (self.awake as u32) << 2
|
||||
@@ -65,126 +174,100 @@ impl AuraPowerState {
|
||||
| (self.sleep as u32) << (23 + 3)
|
||||
| (self.shutdown as u32) << (23 + 4)
|
||||
}
|
||||
PowerZones::KeyboardAndLightbar => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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, Value, OwnedValue))]
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct LaptopAuraPower {
|
||||
pub keyboard: AuraPowerState,
|
||||
pub logo: AuraPowerState,
|
||||
pub lightbar: AuraPowerState,
|
||||
pub lid: AuraPowerState,
|
||||
pub rear_glow: AuraPowerState,
|
||||
pub states: Vec<AuraPowerState>,
|
||||
}
|
||||
|
||||
impl LaptopAuraPower {
|
||||
pub fn new_all_on() -> Self {
|
||||
Self {
|
||||
keyboard: AuraPowerState {
|
||||
boot: true,
|
||||
awake: true,
|
||||
sleep: true,
|
||||
shutdown: true,
|
||||
},
|
||||
logo: AuraPowerState {
|
||||
boot: true,
|
||||
awake: true,
|
||||
sleep: true,
|
||||
shutdown: true,
|
||||
},
|
||||
lightbar: AuraPowerState {
|
||||
boot: true,
|
||||
awake: true,
|
||||
sleep: true,
|
||||
shutdown: true,
|
||||
},
|
||||
lid: AuraPowerState {
|
||||
boot: true,
|
||||
awake: true,
|
||||
sleep: true,
|
||||
shutdown: true,
|
||||
},
|
||||
rear_glow: AuraPowerState {
|
||||
boot: true,
|
||||
awake: true,
|
||||
sleep: true,
|
||||
shutdown: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_bytes(&self) -> [u8; 4] {
|
||||
/// # 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_|
|
||||
fn new_to_bytes(&self) -> Vec<u8> {
|
||||
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);
|
||||
[
|
||||
for state in self.states.iter() {
|
||||
a |= state.new_to_byte();
|
||||
}
|
||||
vec![
|
||||
(a & 0xff) as u8,
|
||||
((a & 0xff00) >> 8) as u8,
|
||||
((a & 0xff0000) >> 16) as u8,
|
||||
((a & 0xff000000) >> 24) as u8,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[cfg_attr(
|
||||
feature = "dbus",
|
||||
derive(Type, Value, OwnedValue),
|
||||
zvariant(signature = "u")
|
||||
)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[repr(u32)]
|
||||
pub enum LaptopTufAuraPower {
|
||||
Boot = 0,
|
||||
Awake = 1,
|
||||
Sleep = 2,
|
||||
Keyboard = 3,
|
||||
}
|
||||
// TODO: use support data to setup correct zones
|
||||
pub fn new(aura_type: LaptopAuraType, _support_data: &LaptopLedData) -> Self {
|
||||
match aura_type {
|
||||
LaptopAuraType::New => {
|
||||
let mut states = Vec::new();
|
||||
for zone in [
|
||||
PowerZones::Keyboard,
|
||||
PowerZones::Lid,
|
||||
PowerZones::Lightbar,
|
||||
PowerZones::Logo,
|
||||
PowerZones::RearGlow,
|
||||
] {
|
||||
states.push(AuraPowerState::default_for(zone))
|
||||
}
|
||||
Self { states }
|
||||
}
|
||||
LaptopAuraType::Old => Self {
|
||||
states: vec![AuraPowerState::default_for(PowerZones::KeyboardAndLightbar)],
|
||||
},
|
||||
LaptopAuraType::Tuf => Self {
|
||||
states: vec![AuraPowerState::default_for(PowerZones::Keyboard)],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
impl LaptopTufAuraPower {
|
||||
pub const fn dev_id() -> &'static str {
|
||||
"tuf"
|
||||
pub fn to_bytes(&self, aura_type: LaptopAuraType) -> Vec<u8> {
|
||||
match aura_type {
|
||||
LaptopAuraType::New => self.new_to_bytes(),
|
||||
LaptopAuraType::Old => self
|
||||
.states
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.old_to_bytes(),
|
||||
LaptopAuraType::Tuf => self
|
||||
.states
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.tuf_to_bytes(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// # Bits for older 0x1866 keyboard model
|
||||
///
|
||||
/// Keybord and Lightbar require Awake, Boot and Sleep apply to both
|
||||
/// Keybord and Lightbar regardless of if either are enabled (or Awake is
|
||||
/// enabled)
|
||||
///
|
||||
/// | Byte 1 | Byte 2 | Byte 3 | function | hex |
|
||||
/// |------------|------------|------------|----------|----------|
|
||||
/// | 0000, 0000 | 0000, 0000 | 0000, 0010 | Awake | 00,00,02 |
|
||||
@@ -193,98 +276,97 @@ impl LaptopTufAuraPower {
|
||||
/// | 1100, 0011 | 0001, 0010 | 0000, 1001 | Boot/Sht | c3,12,09 |
|
||||
/// | 0011, 0000 | 0000, 1000 | 0000, 0100 | Sleep | 30,08,04 |
|
||||
/// | 1111, 1111 | 0001, 1111 | 0000, 1111 | all on | |
|
||||
#[typeshare]
|
||||
#[cfg_attr(
|
||||
feature = "dbus",
|
||||
derive(Type, Value, OwnedValue),
|
||||
zvariant(signature = "u")
|
||||
)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[repr(u32)]
|
||||
pub enum LaptopOldAuraPower {
|
||||
enum OldAuraPower {
|
||||
Awake = 0x000002,
|
||||
Keyboard = 0x080000,
|
||||
Lightbar = 0x040500,
|
||||
Boot = 0xc31209,
|
||||
Sleep = 0x300804,
|
||||
Keyboard = 0x080000,
|
||||
Lightbar = 0x040500,
|
||||
}
|
||||
|
||||
impl From<LaptopOldAuraPower> for u32 {
|
||||
fn from(a: LaptopOldAuraPower) -> Self {
|
||||
a as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl LaptopOldAuraPower {
|
||||
pub fn to_bytes(control: &[Self]) -> [u8; 4] {
|
||||
let mut a: u32 = 0;
|
||||
for n in control {
|
||||
a |= *n as u32;
|
||||
}
|
||||
[
|
||||
((a & 0xff0000) >> 16) as u8,
|
||||
((a & 0xff00) >> 8) as u8,
|
||||
(a & 0xff) as u8,
|
||||
0x00,
|
||||
]
|
||||
}
|
||||
|
||||
pub const fn dev_id() -> &'static str {
|
||||
"0x1866"
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr<LaptopOldAuraPower> for LaptopOldAuraPower {
|
||||
impl BitOr<OldAuraPower> for OldAuraPower {
|
||||
type Output = u32;
|
||||
|
||||
fn bitor(self, rhs: LaptopOldAuraPower) -> Self::Output {
|
||||
fn bitor(self, rhs: OldAuraPower) -> Self::Output {
|
||||
self as u32 | rhs as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd<LaptopOldAuraPower> for LaptopOldAuraPower {
|
||||
impl BitAnd<OldAuraPower> for OldAuraPower {
|
||||
type Output = u32;
|
||||
|
||||
fn bitand(self, rhs: LaptopOldAuraPower) -> Self::Output {
|
||||
fn bitand(self, rhs: OldAuraPower) -> Self::Output {
|
||||
self as u32 & rhs as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl From<OldAuraPower> for u32 {
|
||||
fn from(a: OldAuraPower) -> Self {
|
||||
a as u32
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::keyboard::{AuraPowerState, LaptopAuraPower, LaptopOldAuraPower};
|
||||
use crate::aura_detection::{LaptopLedData, PowerZones};
|
||||
use crate::keyboard::{AuraPowerState, LaptopAuraPower, LaptopAuraType};
|
||||
|
||||
#[test]
|
||||
fn check_0x1866_control_bytes() {
|
||||
let bytes = [LaptopOldAuraPower::Keyboard, LaptopOldAuraPower::Awake];
|
||||
let bytes = LaptopOldAuraPower::to_bytes(&bytes);
|
||||
let state = AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
awake: true,
|
||||
boot: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
};
|
||||
let bytes = state.old_to_bytes();
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes, [0x08, 0x00, 0x02, 0x00]);
|
||||
|
||||
let bytes = [LaptopOldAuraPower::Lightbar, LaptopOldAuraPower::Awake];
|
||||
let bytes = LaptopOldAuraPower::to_bytes(&bytes);
|
||||
let state = AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
awake: true,
|
||||
boot: false,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
};
|
||||
let bytes = state.old_to_bytes();
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes, [0x04, 0x05, 0x02, 0x00]);
|
||||
|
||||
let bytes = [LaptopOldAuraPower::Sleep];
|
||||
let bytes = LaptopOldAuraPower::to_bytes(&bytes);
|
||||
let bytes = AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
awake: false,
|
||||
boot: false,
|
||||
sleep: true,
|
||||
shutdown: false,
|
||||
};
|
||||
let bytes = bytes.old_to_bytes();
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes, [0x30, 0x08, 0x04, 0x00]);
|
||||
|
||||
let bytes = [LaptopOldAuraPower::Boot];
|
||||
let bytes = LaptopOldAuraPower::to_bytes(&bytes);
|
||||
let bytes = AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
awake: false,
|
||||
boot: true,
|
||||
sleep: false,
|
||||
shutdown: false,
|
||||
};
|
||||
let bytes = bytes.old_to_bytes();
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes, [0xc3, 0x12, 0x09, 0x00]);
|
||||
|
||||
let bytes = [
|
||||
LaptopOldAuraPower::Keyboard,
|
||||
LaptopOldAuraPower::Lightbar,
|
||||
LaptopOldAuraPower::Awake,
|
||||
LaptopOldAuraPower::Sleep,
|
||||
LaptopOldAuraPower::Boot,
|
||||
];
|
||||
let power = AuraPowerState {
|
||||
zone: PowerZones::KeyboardAndLightbar,
|
||||
awake: true,
|
||||
boot: true,
|
||||
sleep: true,
|
||||
shutdown: false,
|
||||
};
|
||||
|
||||
let bytes = LaptopOldAuraPower::to_bytes(&bytes);
|
||||
let bytes = power.old_to_bytes();
|
||||
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
|
||||
assert_eq!(bytes, [0xff, 0x1f, 0x000f, 0x00]);
|
||||
}
|
||||
@@ -292,7 +374,7 @@ mod test {
|
||||
#[test]
|
||||
fn check_0x19b6_control_bytes_binary_rep() {
|
||||
fn to_binary_string(power: &LaptopAuraPower) -> String {
|
||||
let bytes = power.to_bytes();
|
||||
let bytes = power.to_bytes(LaptopAuraType::New);
|
||||
format!(
|
||||
"{:08b}, {:08b}, {:08b}, {:08b}",
|
||||
bytes[0], bytes[1], bytes[2], bytes[3]
|
||||
@@ -300,144 +382,144 @@ mod test {
|
||||
}
|
||||
|
||||
let boot_logo_ = to_binary_string(&LaptopAuraPower {
|
||||
logo: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let boot_keyb_ = to_binary_string(&LaptopAuraPower {
|
||||
keyboard: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let sleep_logo = to_binary_string(&LaptopAuraPower {
|
||||
logo: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let sleep_keyb = to_binary_string(&LaptopAuraPower {
|
||||
keyboard: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let awake_logo = to_binary_string(&LaptopAuraPower {
|
||||
logo: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let awake_keyb = to_binary_string(&LaptopAuraPower {
|
||||
keyboard: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let shut_logo_ = to_binary_string(&LaptopAuraPower {
|
||||
logo: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Logo,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let shut_keyb_ = to_binary_string(&LaptopAuraPower {
|
||||
keyboard: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Keyboard,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let boot_bar__ = to_binary_string(&LaptopAuraPower {
|
||||
lightbar: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let awake_bar_ = to_binary_string(&LaptopAuraPower {
|
||||
lightbar: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let sleep_bar_ = to_binary_string(&LaptopAuraPower {
|
||||
lightbar: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let shut_bar__ = to_binary_string(&LaptopAuraPower {
|
||||
lightbar: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lightbar,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let boot_lid__ = to_binary_string(&LaptopAuraPower {
|
||||
lid: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let awake_lid_ = to_binary_string(&LaptopAuraPower {
|
||||
lid: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let sleep_lid_ = to_binary_string(&LaptopAuraPower {
|
||||
lid: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let shut_lid__ = to_binary_string(&LaptopAuraPower {
|
||||
lid: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::Lid,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let boot_rear_ = to_binary_string(&LaptopAuraPower {
|
||||
rear_glow: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
boot: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let awake_rear = to_binary_string(&LaptopAuraPower {
|
||||
rear_glow: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
awake: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let sleep_rear = to_binary_string(&LaptopAuraPower {
|
||||
rear_glow: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
sleep: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
let shut_rear_ = to_binary_string(&LaptopAuraPower {
|
||||
rear_glow: AuraPowerState {
|
||||
states: vec![AuraPowerState {
|
||||
zone: PowerZones::RearGlow,
|
||||
shutdown: true,
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}],
|
||||
});
|
||||
|
||||
assert_eq!(boot_logo_, "00000001, 00000000, 00000000, 00000000");
|
||||
@@ -465,7 +547,7 @@ mod test {
|
||||
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
|
||||
|
||||
// All on
|
||||
let byte1 = LaptopAuraPower::new_all_on();
|
||||
let byte1 = LaptopAuraPower::new(LaptopAuraType::New, &LaptopLedData::default());
|
||||
let out = to_binary_string(&byte1);
|
||||
assert_eq!(out, "11111111, 00011110, 00001111, 00001111");
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ use typeshare::typeshare;
|
||||
#[cfg(feature = "dbus")]
|
||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||
|
||||
use crate::keyboard::{LaptopAuraPower, LaptopOldAuraPower, LaptopTufAuraPower};
|
||||
|
||||
// Only these two packets must be 17 bytes
|
||||
pub const LED_APPLY: [u8; 17] = [0x5d, 0xb4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
pub const LED_SET: [u8; 17] = [0x5d, 0xb5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
@@ -106,18 +104,3 @@ impl Debug for AuraDevice {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This struct is intended as a helper to pass args to generic dbus interface
|
||||
#[typeshare]
|
||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||
#[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<LaptopTufAuraPower>,
|
||||
/// Pre-0x19b6 devices use a different smaller scheme to the newer ROG
|
||||
/// devices
|
||||
pub old_rog: Vec<LaptopOldAuraPower>,
|
||||
/// ASUS standardised control scheme from 2020 onwards
|
||||
pub rog: LaptopAuraPower,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user