mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Adjust how thread exit is handled for anime controller
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::usb::LedCfgState::{Off, On};
|
||||
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
|
||||
@@ -12,12 +12,12 @@ 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;
|
||||
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] {
|
||||
@@ -29,7 +29,7 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum LedCfgState {
|
||||
On = 0xffffff,
|
||||
Off = 0x0
|
||||
Off = 0x0,
|
||||
}
|
||||
|
||||
impl From<i32> for LedCfgState {
|
||||
@@ -37,7 +37,7 @@ impl From<i32> for LedCfgState {
|
||||
match state {
|
||||
0xffffff => On,
|
||||
0x0 => Off,
|
||||
_ => Off
|
||||
_ => Off,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,19 +46,19 @@ impl From<bool> for LedCfgState {
|
||||
fn from(state: bool) -> Self {
|
||||
match state {
|
||||
true => On,
|
||||
false => Off
|
||||
false => Off,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom <[u8; 3]> for LedCfgState {
|
||||
impl TryFrom<[u8; 3]> for LedCfgState {
|
||||
type Error = &'static str;
|
||||
|
||||
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")
|
||||
_ => Err("Unconvertible value"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,14 +67,14 @@ impl BitAnd<LedCfgState> for i32 {
|
||||
type Output = i32;
|
||||
|
||||
fn bitand(self, rhs: LedCfgState) -> i32 {
|
||||
return self & rhs as 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
|
||||
return self | rhs as i32;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,17 +94,38 @@ impl BitAnd<LedCfgState> for LedCfgState {
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
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 {
|
||||
|
||||
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),
|
||||
On => {
|
||||
(ALL_LEDS_MASK & all_leds_state)
|
||||
| (KBD_LEDS_MASK & kbd_leds_state)
|
||||
| (SIDE_LEDS_MASK & side_leds_state)
|
||||
}
|
||||
Off => 0x0100 & side_leds_state,
|
||||
};
|
||||
|
||||
@@ -112,6 +133,6 @@ fn _leds_message (boot_state: LedCfgState, sleep_state: LedCfgState, all_leds_st
|
||||
|
||||
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
|
||||
}
|
||||
_ => boot_xor_sleep,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user