Advanced Aura feature

Groundwork for 'advanced' aura modes
Add single zone + Doom light flash
Fix mocking for ROGCC
Better prepare & change to mapping of keyboard layouts to models and functions
Refactor and begin using new key layout stuff
Enable first arg to rogcc to set layout in mocking feature mode
Complete refactor of key layouts, and to RON serde
This commit is contained in:
Luke D. Jones
2022-12-11 11:50:47 +13:00
parent e3ecaa92bd
commit 1cbffedaeb
134 changed files with 8249 additions and 4390 deletions

View File

@@ -36,7 +36,12 @@ impl fmt::Display for PlatformError {
PlatformError::AttrNotFound(deets) => write!(f, "Attribute not found: {}", deets),
PlatformError::Io(deets) => write!(f, "std::io error: {}", deets),
PlatformError::MissingFunction(deets) => write!(f, "Missing functionality: {}", deets),
PlatformError::MissingLedBrightNode(path, error) => write!(f, "Led node at {} is missing, please check you have the required patch or dkms module installed: {}", path, error),
PlatformError::MissingLedBrightNode(path, error) => write!(
f,
"Led node at {} is missing, please check you have the required patch or dkms \
module installed: {}",
path, error
),
PlatformError::IoPath(path, detail) => write!(f, "{} {}", path, detail),
PlatformError::NoAuraKeyboard => write!(f, "No supported Aura keyboard"),
PlatformError::NoAuraNode => write!(f, "No Aura keyboard node found"),

View File

@@ -1,4 +1,6 @@
use std::{fs::OpenOptions, io::Write, path::PathBuf};
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;
use log::{info, warn};

View File

@@ -2,11 +2,8 @@ use std::path::PathBuf;
use log::{info, warn};
use crate::{
attr_u8,
error::{PlatformError, Result},
has_attr, set_attr_u8_array, to_device,
};
use crate::error::{PlatformError, Result};
use crate::{attr_u8, has_attr, set_attr_u8_array, to_device};
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Clone)]
pub struct KeyboardLed {
@@ -14,6 +11,24 @@ pub struct KeyboardLed {
}
impl KeyboardLed {
attr_u8!("brightness", path);
has_attr!("kbd_rgb_mode" path);
set_attr_u8_array!(
/// kbd_rgb_mode can only be set, not read back
"kbd_rgb_mode"
path
);
has_attr!("kbd_rgb_state" path);
set_attr_u8_array!(
/// kbd_rgb_state can only be set, not read back
"kbd_rgb_state"
path
);
pub fn new() -> Result<Self> {
let mut enumerator = udev::Enumerator::new().map_err(|err| {
warn!("{}", err);
@@ -47,20 +62,4 @@ impl KeyboardLed {
"asus::kbd_backlight not found".into(),
))
}
attr_u8!("brightness", path);
has_attr!("kbd_rgb_mode" path);
set_attr_u8_array!(
/// kbd_rgb_mode can only be set, not read back
"kbd_rgb_mode"
path
);
has_attr!("kbd_rgb_state" path);
set_attr_u8_array!(
/// kbd_rgb_state can only be set, not read back
"kbd_rgb_state"
path
);
}

View File

@@ -118,13 +118,13 @@ mod tests {
// .parent_with_subsystem_devtype("usb", "usb_device")
// .map_err(|err| {
// warn!("{}", err);
// PlatformError::Udev("parent_with_subsystem_devtype failed".into(), err)
// })?
// PlatformError::Udev("parent_with_subsystem_devtype
// failed".into(), err) })?
// {
// if parent
// .attribute_value("idProduct")
// .ok_or_else(|| PlatformError::NotFound("LED idProduct".into()))?
// == id_product
// .ok_or_else(|| PlatformError::NotFound("LED
// idProduct".into()))? == id_product
// {
// if let Some(dev_node) = device.devnode() {
// info!("Using device at: {:?} for LED control", dev_node);

View File

@@ -1,14 +1,13 @@
use std::{fmt::Display, path::PathBuf, str::FromStr};
use std::fmt::Display;
use std::path::PathBuf;
use std::str::FromStr;
use log::{info, warn};
use serde::{Deserialize, Serialize};
use zbus::zvariant::Type;
use crate::{
attr_bool, attr_u8,
error::{PlatformError, Result},
to_device,
};
use crate::error::{PlatformError, Result};
use crate::{attr_bool, attr_u8, to_device};
/// The "platform" device provides access to things like:
/// - `dgpu_disable`
@@ -24,6 +23,21 @@ pub struct AsusPlatform {
}
impl AsusPlatform {
attr_bool!("dgpu_disable", path);
attr_bool!("egpu_enable", path);
attr_bool!("panel_od", path);
attr_bool!("gpu_mux_mode", path);
// This is technically the same as `platform_profile` since both are tied
// in-kernel
attr_u8!("throttle_thermal_policy", path);
// The acpi platform_profile support
attr_u8!("platform_profile", pp_path);
pub fn new() -> Result<Self> {
let mut enumerator = udev::Enumerator::new().map_err(|err| {
warn!("{}", err);
@@ -54,15 +68,6 @@ impl AsusPlatform {
"asus-nb-wmi not found".into(),
))
}
attr_bool!("dgpu_disable", path);
attr_bool!("egpu_enable", path);
attr_bool!("panel_od", path);
attr_bool!("gpu_mux_mode", path);
// This is technically the same as `platform_profile` since both are tied in-kernel
attr_u8!("throttle_thermal_policy", path);
// The acpi platform_profile support
attr_u8!("platform_profile", pp_path);
}
#[derive(Serialize, Deserialize, Default, Type, Debug, PartialEq, Eq, Clone, Copy)]

View File

@@ -2,11 +2,8 @@ use std::path::PathBuf;
use log::{info, warn};
use crate::{
attr_u8,
error::{PlatformError, Result},
to_device,
};
use crate::error::{PlatformError, Result};
use crate::{attr_u8, to_device};
/// The "platform" device provides access to things like:
/// - `dgpu_disable`
@@ -23,9 +20,14 @@ pub struct AsusPower {
}
impl AsusPower {
attr_u8!("charge_control_end_threshold", battery);
attr_u8!("online", mains);
/// When checking for battery this will look in order:
/// - if attr `manufacturer` contains `asus`
/// - if attr `charge_control_end_threshold` exists and `energy_full_design` >= 50 watt
/// - if attr `charge_control_end_threshold` exists and `energy_full_design`
/// >= 50 watt
/// - if syspath end conatins `BAT`
/// - if attr `type` is `battery` (last resort)
pub fn new() -> Result<Self> {
@@ -62,7 +64,11 @@ impl AsusPower {
.attribute_value("charge_control_end_threshold")
.is_some()
{
info!("Found battery power at {:?}, matched charge_control_end_threshold", device.sysname());
info!(
"Found battery power at {:?}, matched \
charge_control_end_threshold",
device.sysname()
);
battery = Some(device.syspath().to_path_buf());
} else if device.sysname().to_string_lossy().starts_with("BAT") {
info!(
@@ -100,7 +106,4 @@ impl AsusPower {
"Did not find a battery".to_owned(),
))
}
attr_u8!("charge_control_end_threshold", battery);
attr_u8!("online", mains);
}

View File

@@ -1,6 +1,8 @@
use rog_aura::{usb::AuraDevice, AuraModeNum, AuraZone};
use serde_derive::{Deserialize, Serialize};
use std::fmt;
use rog_aura::usb::AuraDevice;
use rog_aura::{AdvancedAuraType, AuraModeNum, AuraZone};
use serde_derive::{Deserialize, Serialize};
use zbus::zvariant::Type;
#[derive(Serialize, Deserialize, Type, Debug, Default, Clone)]
@@ -26,13 +28,31 @@ pub struct PlatformProfileFunctions {
pub fan_curves: bool,
}
#[derive(Serialize, Deserialize, Default, Type, Debug, Clone)]
pub enum AdvancedAura {
#[default]
None,
Zoned,
PerKey,
}
impl From<AdvancedAuraType> for AdvancedAura {
fn from(a: AdvancedAuraType) -> Self {
match a {
AdvancedAuraType::None => Self::None,
AdvancedAuraType::Zoned(_) => Self::Zoned,
AdvancedAuraType::PerKey => Self::PerKey,
}
}
}
#[derive(Serialize, Deserialize, Type, Debug, Default, Clone)]
pub struct LedSupportedFunctions {
pub prod_id: AuraDevice,
pub brightness_set: bool,
pub stock_led_modes: Vec<AuraModeNum>,
pub multizone_led_mode: Vec<AuraZone>,
pub per_key_led_mode: bool,
pub dev_id: AuraDevice,
pub brightness: bool,
pub basic_modes: Vec<AuraModeNum>,
pub basic_zones: Vec<AuraZone>,
pub advanced_type: AdvancedAura,
}
#[derive(Serialize, Deserialize, Type, Debug, Default, Clone)]
@@ -46,7 +66,7 @@ pub struct RogBiosSupportedFunctions {
impl fmt::Display for SupportedFunctions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "{}", self.anime_ctrl)?;
writeln!(f, "\n{}", self.anime_ctrl)?;
writeln!(f, "{}", self.charge_ctrl)?;
writeln!(f, "{}", self.platform_profile)?;
writeln!(f, "{}", self.keyboard_led)?;
@@ -80,10 +100,11 @@ impl fmt::Display for PlatformProfileFunctions {
impl fmt::Display for LedSupportedFunctions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "LED:")?;
writeln!(f, "\tBrightness control: {}", self.brightness_set)?;
writeln!(f, "\tStock LED modes: {:?}", self.stock_led_modes)?;
writeln!(f, "\tMultizone LED mode: {:?}", self.multizone_led_mode)?;
writeln!(f, "\tPer key LED mode: {}", self.per_key_led_mode)
writeln!(f, "\tDevice ID: {:?}", self.dev_id)?;
writeln!(f, "\tBrightness control: {}", self.brightness)?;
writeln!(f, "\tBasic modes: {:?}", self.basic_modes)?;
writeln!(f, "\tBasic zones: {:?}", self.basic_zones)?;
writeln!(f, "\tAdvanced modes: {:?}", self.advanced_type)
}
}
impl fmt::Display for RogBiosSupportedFunctions {

View File

@@ -1,6 +1,7 @@
use rusb::{Device, DeviceHandle};
use std::time::Duration;
use rusb::{Device, DeviceHandle};
use crate::error::{PlatformError, Result};
#[derive(Debug, PartialEq, Eq)]