mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Combination for power state leds boot/sleep/all/keys/side LEDS
This commit is contained in:
@@ -14,8 +14,11 @@ use crate::{error::Error, LED_MSG_LEN};
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Deserialize, Serialize)]
|
||||
pub struct LedPowerStates {
|
||||
pub enabled: bool,
|
||||
pub sleep_anim_enabled: bool,
|
||||
pub boot_anim: bool,
|
||||
pub sleep_anim: bool,
|
||||
pub all_leds: bool,
|
||||
pub keys_leds: bool,
|
||||
pub side_leds: bool,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
use std::convert::TryFrom;
|
||||
use std::ops::{BitAnd, BitOr};
|
||||
use crate::usb::LedCfgState::{Off, On};
|
||||
|
||||
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];
|
||||
@@ -8,6 +12,13 @@ pub const LED_INIT5: [u8; 6] = [0x5e, 0x05, 0x20, 0x31, 0, 0x08];
|
||||
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];
|
||||
|
||||
pub const BOOT_MASK:i32 = 0xc31309;
|
||||
pub const SLEEP_MASK:i32 = 0x300904;
|
||||
pub const ALL_LEDS_MASK:i32 = 0x000002;
|
||||
pub const KBD_LEDS_MASK:i32 = 0x080000;
|
||||
pub const SIDE_LEDS_MASK:i32 = 0x040500;
|
||||
pub const LEDS_STATE_MASK:i32 = ALL_LEDS_MASK | KBD_LEDS_MASK | SIDE_LEDS_MASK;
|
||||
|
||||
/// Writes out the correct byte string for brightness
|
||||
pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
||||
[
|
||||
@@ -15,26 +26,92 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
||||
]
|
||||
}
|
||||
|
||||
pub const LED_AWAKE_ON_SLEEP_OFF: [u8; 17] = [
|
||||
0x5d, 0xbd, 0x01, 0xcf, 0x17, 0x0b, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum LedCfgState {
|
||||
On = 0xffffff,
|
||||
Off = 0x0
|
||||
}
|
||||
|
||||
pub const LED_AWAKE_ON_SLEEP_ON: [u8; 17] = [
|
||||
0x5d, 0xbd, 0x01, 0xff, 0x1f, 0x0f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
impl From<i32> for LedCfgState {
|
||||
fn from(state: i32) -> Self {
|
||||
match state {
|
||||
0xffffff => On,
|
||||
0x0 => Off,
|
||||
_ => Off
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const LED_AWAKE_OFF_SLEEP_OFF: [u8; 17] = [
|
||||
0x5d, 0xbd, 0x01, 0xc3, 0x13, 0x09, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
impl From<bool> for LedCfgState {
|
||||
fn from(state: bool) -> Self {
|
||||
match state {
|
||||
true => On,
|
||||
false => Off
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const LED_AWAKE_OFF_SLEEP_ON: [u8; 17] = [
|
||||
0x5d, 0xbd, 0x01, 0xf3, 0x1b, 0x0d, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
impl TryFrom <[u8; 3]> for LedCfgState {
|
||||
type Error = &'static str;
|
||||
|
||||
pub const SIDE_LEDS_OFF: [u8; 17] = [
|
||||
0x5d, 0xbd, 0x01, 0x08, 0x00, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
fn try_from(value: [u8; 3]) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
[0xff, 0xff, 0xff] => Ok(On),
|
||||
[0, 0, 0] => Ok(Off),
|
||||
_ => Err("Unconvertible value")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const SIDE_LEDS_ON: [u8; 17] = [
|
||||
0x5d, 0xbd, 0x01, 0x0c, 0x05, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
impl BitAnd<LedCfgState> for i32 {
|
||||
type Output = i32;
|
||||
|
||||
fn bitand(self, rhs: LedCfgState) -> i32 {
|
||||
return self & rhs as i32
|
||||
}
|
||||
}
|
||||
impl BitOr<LedCfgState> for i32 {
|
||||
type Output = i32;
|
||||
|
||||
fn bitor(self, rhs: LedCfgState) -> Self::Output {
|
||||
return self | rhs as i32
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOr<LedCfgState> for LedCfgState {
|
||||
type Output = i32;
|
||||
|
||||
fn bitor(self, rhs: LedCfgState) -> i32 {
|
||||
return self as i32 | rhs as i32;
|
||||
}
|
||||
}
|
||||
|
||||
impl BitAnd<LedCfgState> for LedCfgState {
|
||||
type Output = LedCfgState;
|
||||
|
||||
fn bitand(self, rhs: LedCfgState) -> LedCfgState {
|
||||
return (self as i32 & rhs as i32).into();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn leds_message (boot_state: bool, sleep_state: bool, all_leds_state: bool, kbd_leds_state: bool, side_leds_state: bool) -> [u8; 3] {
|
||||
let raw_message = _leds_message(boot_state.into(), sleep_state.into(), all_leds_state.into(), kbd_leds_state.into(), side_leds_state.into());
|
||||
|
||||
let [_, lows @ ..] = i32::to_be_bytes(raw_message);
|
||||
return lows;
|
||||
}
|
||||
|
||||
fn _leds_message (boot_state: LedCfgState, sleep_state: LedCfgState, all_leds_state: LedCfgState, kbd_leds_state: LedCfgState, side_leds_state: LedCfgState) -> i32 {
|
||||
|
||||
let full_leds_state = match all_leds_state {
|
||||
On => (ALL_LEDS_MASK & all_leds_state) | (KBD_LEDS_MASK & kbd_leds_state) | (SIDE_LEDS_MASK & side_leds_state),
|
||||
Off => 0x0100 & side_leds_state,
|
||||
};
|
||||
|
||||
let boot_xor_sleep = (BOOT_MASK & boot_state) ^ (SLEEP_MASK & sleep_state);
|
||||
|
||||
return match (all_leds_state | kbd_leds_state | side_leds_state).into() {
|
||||
On => boot_xor_sleep ^ ((boot_xor_sleep ^ full_leds_state) & LEDS_STATE_MASK),
|
||||
_ => boot_xor_sleep
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user