mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 17:33:19 +01:00
Complete building
This commit is contained in:
@@ -5,21 +5,10 @@ use typeshare::typeshare;
|
||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||
|
||||
use crate::keyboard::AdvancedAuraType;
|
||||
use crate::usb::AuraDevice;
|
||||
use crate::{AuraModeNum, AuraZone};
|
||||
|
||||
pub const ASUS_LED_MODE_CONF: &str = "/usr/share/asusd/aura_support.ron";
|
||||
pub const ASUS_LED_MODE_USER_CONF: &str = "/etc/asusd/asusd_user_ledmodes.ron";
|
||||
pub const ASUS_KEYBOARD_DEVICES: [AuraDevice; 8] = [
|
||||
AuraDevice::Tuf,
|
||||
AuraDevice::X1854,
|
||||
AuraDevice::X1869,
|
||||
AuraDevice::X1866,
|
||||
AuraDevice::X18c6,
|
||||
AuraDevice::X19b6,
|
||||
AuraDevice::X1a30,
|
||||
AuraDevice::X1abe,
|
||||
];
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct LedSupportFile(Vec<LaptopLedData>);
|
||||
|
||||
@@ -3,55 +3,14 @@
|
||||
use std::fmt::Debug;
|
||||
use std::ops::{BitAnd, BitOr};
|
||||
|
||||
use log::warn;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
#[cfg(feature = "dbus")]
|
||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
use crate::AuraDeviceType;
|
||||
|
||||
/// Meaning of this struct depends on the laptop generation.
|
||||
/// - 2021+, the struct is a single zone with 4 states
|
||||
@@ -225,45 +184,53 @@ impl LaptopAuraPower {
|
||||
}
|
||||
|
||||
// TODO: use support data to setup correct zones
|
||||
pub fn new(aura_type: LaptopAuraType, _support_data: &LaptopLedData) -> Self {
|
||||
pub fn new(aura_type: AuraDeviceType, support_data: &LaptopLedData) -> Self {
|
||||
match aura_type {
|
||||
LaptopAuraType::New => {
|
||||
AuraDeviceType::Unknown | AuraDeviceType::LaptopPost2021 => {
|
||||
let mut states = Vec::new();
|
||||
for zone in [
|
||||
PowerZones::Keyboard,
|
||||
PowerZones::Lid,
|
||||
PowerZones::Lightbar,
|
||||
PowerZones::Logo,
|
||||
PowerZones::RearGlow,
|
||||
] {
|
||||
states.push(AuraPowerState::default_for(zone))
|
||||
for zone in support_data.power_zones.iter() {
|
||||
states.push(AuraPowerState::default_for(*zone))
|
||||
}
|
||||
Self { states }
|
||||
}
|
||||
LaptopAuraType::Old => Self {
|
||||
states: vec![AuraPowerState::default_for(PowerZones::KeyboardAndLightbar)],
|
||||
},
|
||||
LaptopAuraType::Tuf => Self {
|
||||
AuraDeviceType::LaptopPre2021 => {
|
||||
if support_data.power_zones.contains(&PowerZones::Lightbar) {
|
||||
Self {
|
||||
states: vec![AuraPowerState::default_for(PowerZones::KeyboardAndLightbar)],
|
||||
}
|
||||
} else {
|
||||
Self {
|
||||
states: vec![AuraPowerState::default_for(PowerZones::Keyboard)],
|
||||
}
|
||||
}
|
||||
}
|
||||
AuraDeviceType::LaptopTuf => Self {
|
||||
states: vec![AuraPowerState::default_for(PowerZones::Keyboard)],
|
||||
},
|
||||
AuraDeviceType::ScsiExtDisk => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_bytes(&self, aura_type: LaptopAuraType) -> Vec<u8> {
|
||||
pub fn to_bytes(&self, aura_type: AuraDeviceType) -> Vec<u8> {
|
||||
match aura_type {
|
||||
LaptopAuraType::New => self.new_to_bytes(),
|
||||
LaptopAuraType::Old => self
|
||||
AuraDeviceType::LaptopPost2021 => self.new_to_bytes(),
|
||||
AuraDeviceType::LaptopPre2021 => self
|
||||
.states
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.old_to_bytes(),
|
||||
LaptopAuraType::Tuf => self
|
||||
AuraDeviceType::LaptopTuf => self
|
||||
.states
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.tuf_to_bytes(),
|
||||
AuraDeviceType::Unknown => {
|
||||
warn!("Trying to create bytes for an unknown device");
|
||||
self.new_to_bytes()
|
||||
}
|
||||
AuraDeviceType::ScsiExtDisk => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,7 +277,8 @@ impl From<OldAuraPower> for u32 {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::aura_detection::{LaptopLedData, PowerZones};
|
||||
use crate::keyboard::{AuraPowerState, LaptopAuraPower, LaptopAuraType};
|
||||
use crate::keyboard::{AuraPowerState, LaptopAuraPower};
|
||||
use crate::AuraDeviceType;
|
||||
|
||||
#[test]
|
||||
fn check_0x1866_control_bytes() {
|
||||
@@ -374,7 +342,7 @@ mod test {
|
||||
#[test]
|
||||
fn check_0x19b6_control_bytes_binary_rep() {
|
||||
fn to_binary_string(power: &LaptopAuraPower) -> String {
|
||||
let bytes = power.to_bytes(LaptopAuraType::New);
|
||||
let bytes = power.to_bytes(AuraDeviceType::LaptopPost2021);
|
||||
format!(
|
||||
"{:08b}, {:08b}, {:08b}, {:08b}",
|
||||
bytes[0], bytes[1], bytes[2], bytes[3]
|
||||
@@ -547,7 +515,7 @@ mod test {
|
||||
assert_eq!(shut_rear_, "00000000, 00000000, 00000000, 00001000");
|
||||
|
||||
// All on
|
||||
let byte1 = LaptopAuraPower::new(LaptopAuraType::New, &LaptopLedData::default());
|
||||
let byte1 = LaptopAuraPower::new(AuraDeviceType::LaptopPost2021, &LaptopLedData::default());
|
||||
let out = to_binary_string(&byte1);
|
||||
assert_eq!(out, "11111111, 00011110, 00001111, 00001111");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
// TODO: Traits for writing aura_sync
|
||||
// TODO: separate keyboard and laptop parts?
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
#[cfg(feature = "dbus")]
|
||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||
|
||||
/// A container of images/grids/gifs/pauses which can be iterated over to
|
||||
/// generate cool effects
|
||||
pub mod effects;
|
||||
@@ -56,3 +63,45 @@ pub const ORANGE: Colour = Colour {
|
||||
b: 0x00,
|
||||
};
|
||||
pub const GRADIENT: [Colour; 7] = [RED, VIOLET, BLUE, TEAL, GREEN, YELLOW, ORANGE];
|
||||
|
||||
#[typeshare]
|
||||
#[cfg_attr(feature = "dbus", derive(Type, Value, OwnedValue))]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum AuraDeviceType {
|
||||
/// Most new laptops
|
||||
#[default]
|
||||
LaptopPost2021 = 0,
|
||||
LaptopPre2021 = 1,
|
||||
LaptopTuf = 2,
|
||||
ScsiExtDisk = 3,
|
||||
Unknown = 255,
|
||||
}
|
||||
|
||||
impl AuraDeviceType {
|
||||
pub fn is_old_laptop(&self) -> bool {
|
||||
*self == Self::LaptopPre2021
|
||||
}
|
||||
|
||||
pub fn is_tuf_laptop(&self) -> bool {
|
||||
*self == Self::LaptopTuf
|
||||
}
|
||||
|
||||
pub fn is_new_laptop(&self) -> bool {
|
||||
*self == Self::LaptopPost2021
|
||||
}
|
||||
|
||||
pub fn is_scsi(&self) -> bool {
|
||||
*self == Self::ScsiExtDisk
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for AuraDeviceType {
|
||||
fn from(s: &str) -> Self {
|
||||
match s.to_lowercase().trim_start_matches("0x") {
|
||||
"tuf" => AuraDeviceType::LaptopTuf,
|
||||
"1932" => AuraDeviceType::ScsiExtDisk,
|
||||
"1866" | "18c6" | "1869" | "1854" => Self::LaptopPre2021,
|
||||
_ => Self::LaptopPost2021,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use typeshare::typeshare;
|
||||
#[cfg(feature = "dbus")]
|
||||
use zbus::zvariant::{OwnedValue, Type, Value};
|
||||
|
||||
// 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];
|
||||
@@ -15,92 +8,3 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
||||
0x5a, 0xba, 0xc5, 0xc4, brightness, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
]
|
||||
}
|
||||
|
||||
#[typeshare]
|
||||
#[cfg_attr(
|
||||
feature = "dbus",
|
||||
derive(Type, Value, OwnedValue),
|
||||
zvariant(signature = "s")
|
||||
)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
|
||||
pub enum AuraDevice {
|
||||
Tuf = 0,
|
||||
X1854 = 1,
|
||||
X1869 = 2,
|
||||
/// Pre-2020 laptops
|
||||
X1866 = 3,
|
||||
/// Z13 lightbar
|
||||
X18c6 = 4,
|
||||
/// Most modern laptops
|
||||
#[default]
|
||||
X19b6 = 5,
|
||||
X1a30 = 6,
|
||||
/// The ROG Ally
|
||||
X1abe = 7,
|
||||
Unknown = 99,
|
||||
}
|
||||
|
||||
impl AuraDevice {
|
||||
pub fn is_tuf_style(&self) -> bool {
|
||||
matches!(self, AuraDevice::Tuf)
|
||||
}
|
||||
|
||||
pub fn is_old_style(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
AuraDevice::X1854 | AuraDevice::X1869 | AuraDevice::X1866 | AuraDevice::X1abe
|
||||
)
|
||||
}
|
||||
|
||||
pub fn is_new_style(&self) -> bool {
|
||||
!self.is_old_style() && !self.is_tuf_style()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<AuraDevice> for &str {
|
||||
fn from(a: AuraDevice) -> Self {
|
||||
match a {
|
||||
AuraDevice::Tuf => "tuf",
|
||||
AuraDevice::X1854 => "1854",
|
||||
AuraDevice::X1869 => "1869",
|
||||
AuraDevice::X1866 => "1866",
|
||||
AuraDevice::X18c6 => "18c6",
|
||||
AuraDevice::X19b6 => "19b6",
|
||||
AuraDevice::X1a30 => "1a30",
|
||||
AuraDevice::X1abe => "1abe",
|
||||
AuraDevice::Unknown => "unknown",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for AuraDevice {
|
||||
fn from(s: &str) -> Self {
|
||||
match s.to_lowercase().as_str() {
|
||||
"tuf" => AuraDevice::Tuf,
|
||||
"1866" | "0x1866" => AuraDevice::X1866,
|
||||
"18c6" | "0x18c6" => AuraDevice::X18c6,
|
||||
"1869" | "0x1869" => AuraDevice::X1869,
|
||||
"1854" | "0x1854" => AuraDevice::X1854,
|
||||
"19b6" | "0x19b6" => AuraDevice::X19b6,
|
||||
"1a30" | "0x1a30" => AuraDevice::X1a30,
|
||||
"1abe" | "0x1abe" => AuraDevice::X1abe,
|
||||
_ => AuraDevice::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for AuraDevice {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Tuf => write!(f, "Tuf"),
|
||||
Self::X1854 => write!(f, "0x1854"),
|
||||
Self::X1869 => write!(f, "0x1869"),
|
||||
Self::X1866 => write!(f, "0x1866"),
|
||||
Self::X18c6 => write!(f, "0x18c6"),
|
||||
Self::X19b6 => write!(f, "0x19B6"),
|
||||
Self::X1a30 => write!(f, "0x1A30"),
|
||||
Self::X1abe => write!(f, "0x1ABE"),
|
||||
Self::Unknown => write!(f, "Unknown"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user