Add Ally 1 and X as "old" style devices for power

These have a slightly different power settings data which needs to be verified.
We can use the old style for now.

Closes #542
This commit is contained in:
Luke D. Jones
2024-08-27 11:46:09 +12:00
parent c3880d055d
commit 8f35220c5f
16 changed files with 1006 additions and 785 deletions

1673
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -36,7 +36,7 @@ default-members = [
] ]
[workspace.dependencies] [workspace.dependencies]
tokio = { version = "^1.36.0", default-features = false, features = [ tokio = { version = "^1.39.0", default-features = false, features = [
"macros", "macros",
"sync", "sync",
"time", "time",
@@ -47,7 +47,7 @@ dirs = "^4.0"
smol = "^1.3" smol = "^1.3"
mio = "0.8.11" mio = "0.8.11"
zbus = "4.2" zbus = "4.4"
logind-zbus = { version = "4.0.3" } #, default-features = false, features = ["non_blocking"] } logind-zbus = { version = "4.0.3" } #, default-features = false, features = ["non_blocking"] }
serde = { version = "^1.0", features = ["serde_derive"] } serde = { version = "^1.0", features = ["serde_derive"] }

View File

@@ -41,6 +41,8 @@ pub enum SetAuraZoneEnabled {
Lid(AuraPowerStates), Lid(AuraPowerStates),
#[options(help = "")] #[options(help = "")]
RearGlow(AuraPowerStates), RearGlow(AuraPowerStates),
#[options(help = "")]
Ally(AuraPowerStates),
} }
#[derive(Debug, Clone, Options)] #[derive(Debug, Clone, Options)]

View File

@@ -751,6 +751,7 @@ fn handle_led_power2(
aura_cli::SetAuraZoneEnabled::Lightbar(l) => set(PowerZones::Lightbar, l), aura_cli::SetAuraZoneEnabled::Lightbar(l) => set(PowerZones::Lightbar, l),
aura_cli::SetAuraZoneEnabled::Lid(l) => set(PowerZones::Lid, l), aura_cli::SetAuraZoneEnabled::Lid(l) => set(PowerZones::Lid, l),
aura_cli::SetAuraZoneEnabled::RearGlow(r) => set(PowerZones::RearGlow, r), aura_cli::SetAuraZoneEnabled::RearGlow(r) => set(PowerZones::RearGlow, r),
aura_cli::SetAuraZoneEnabled::Ally(r) => set(PowerZones::Ally, r),
} }
} }

View File

@@ -15,6 +15,8 @@ use crate::error::RogError;
// #[serde(default)] // #[serde(default)]
pub struct AuraConfig { pub struct AuraConfig {
pub config_name: String, pub config_name: String,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub ally_fix: Option<bool>,
pub brightness: LedBrightness, pub brightness: LedBrightness,
pub current_mode: AuraModeNum, pub current_mode: AuraModeNum,
pub builtins: BTreeMap<AuraModeNum, AuraEffect>, pub builtins: BTreeMap<AuraModeNum, AuraEffect>,
@@ -57,6 +59,7 @@ impl AuraConfig {
let enabled = LaptopAuraPower::new(device_type, &support_data); let enabled = LaptopAuraPower::new(device_type, &support_data);
let mut config = AuraConfig { let mut config = AuraConfig {
config_name: format!("aura_{prod_id}.ron"), config_name: format!("aura_{prod_id}.ron"),
ally_fix: None,
brightness: LedBrightness::Med, brightness: LedBrightness::Med,
current_mode: AuraModeNum::Static, current_mode: AuraModeNum::Static,
builtins: BTreeMap::new(), builtins: BTreeMap::new(),

View File

@@ -7,7 +7,7 @@ use log::{debug, info, warn};
use rog_aura::aura_detection::LedSupportData; use rog_aura::aura_detection::LedSupportData;
use rog_aura::keyboard::{LedUsbPackets, UsbPackets}; use rog_aura::keyboard::{LedUsbPackets, UsbPackets};
use rog_aura::usb::{LED_APPLY, LED_SET}; use rog_aura::usb::{LED_APPLY, LED_SET};
use rog_aura::{AuraDeviceType, AuraEffect, LedBrightness, LED_MSG_LEN}; use rog_aura::{AuraDeviceType, AuraEffect, LedBrightness, PowerZones, LED_MSG_LEN};
use rog_platform::hid_raw::HidRaw; use rog_platform::hid_raw::HidRaw;
use rog_platform::keyboard_led::KeyboardBacklight; use rog_platform::keyboard_led::KeyboardBacklight;
use udev::Device; use udev::Device;
@@ -317,6 +317,23 @@ impl CtrlKbdLed {
config_loaded config_loaded
} }
pub(super) fn fix_ally_power(&mut self) -> Result<(), RogError> {
if self.led_type == AuraDeviceType::Ally {
if let LEDNode::Rog(_, hid_raw) = &self.led_node {
if let Some(fix) = self.config.ally_fix.as_mut() {
if !*fix {
let msg = [0x5d, 0xbd, 0x01, 0xff, 0xff, 0xff, 0xff];
hid_raw.write_bytes(&msg)?;
info!("Reset Ally power settings to base");
}
*fix = true;
}
self.config.write();
}
}
Ok(())
}
/// Set combination state for boot animation/sleep animation/all leds/keys /// Set combination state for boot animation/sleep animation/all leds/keys
/// leds/side leds LED active /// leds/side leds LED active
pub(super) fn set_power_states(&mut self) -> Result<(), RogError> { pub(super) fn set_power_states(&mut self) -> Result<(), RogError> {
@@ -325,13 +342,17 @@ impl CtrlKbdLed {
let buf = self.config.enabled.to_bytes(self.led_type); let buf = self.config.enabled.to_bytes(self.led_type);
platform.set_kbd_rgb_state(&buf)?; platform.set_kbd_rgb_state(&buf)?;
} else if let LEDNode::Rog(_, hid_raw) = &self.led_node { } else if let LEDNode::Rog(_, hid_raw) = &self.led_node {
let bytes = self.config.enabled.to_bytes(self.led_type); if let Some(p) = self.config.enabled.states.first() {
let message = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2], bytes[3]]; if p.zone == PowerZones::Ally {
let msg = [0x5d, 0xd1, 0x09, 0x01, p.new_to_byte() as u8, 0x0, 0x0];
hid_raw.write_bytes(&msg)?;
return Ok(());
}
}
hid_raw.write_bytes(&message)?; let bytes = self.config.enabled.to_bytes(self.led_type);
hid_raw.write_bytes(&LED_SET)?; let msg = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2], bytes[3]];
// Changes won't persist unless apply is set hid_raw.write_bytes(&msg)?;
hid_raw.write_bytes(&LED_APPLY)?;
} }
Ok(()) Ok(())
} }

View File

@@ -296,6 +296,7 @@ impl CtrlTask for CtrlAuraZbus {
impl crate::Reloadable for CtrlAuraZbus { impl crate::Reloadable for CtrlAuraZbus {
async fn reload(&mut self) -> Result<(), RogError> { async fn reload(&mut self) -> Result<(), RogError> {
let mut ctrl = self.0.lock().await; let mut ctrl = self.0.lock().await;
ctrl.fix_ally_power()?;
debug!("reloading keyboard mode"); debug!("reloading keyboard mode");
ctrl.write_current_config_mode()?; ctrl.write_current_config_mode()?;
debug!("reloading power states"); debug!("reloading power states");

View File

@@ -903,18 +903,18 @@
device_name: "RC71L", device_name: "RC71L",
product_id: "", product_id: "",
layout_name: "ga401q", layout_name: "ga401q",
basic_modes: [Static, Breathe, Pulse, RainbowCycle], basic_modes: [Static, Breathe, Pulse, RainbowCycle, RainbowWave],
basic_zones: [], basic_zones: [],
advanced_type: None, advanced_type: None,
power_zones: [Keyboard], power_zones: [Ally],
), ),
( (
device_name: "RC72L", device_name: "RC72L",
product_id: "", product_id: "",
layout_name: "ga401q", layout_name: "ga401q",
basic_modes: [Static, Breathe, Pulse, RainbowCycle], basic_modes: [Static, Breathe, Pulse, RainbowCycle, RainbowWave],
basic_zones: [], basic_zones: [],
advanced_type: None, advanced_type: None,
power_zones: [Keyboard], power_zones: [Ally],
), ),
]) ])

View File

@@ -102,7 +102,7 @@ impl AuraPowerState {
] ]
} }
fn new_to_byte(&self) -> u32 { pub fn new_to_byte(&self) -> u32 {
match self.zone { match self.zone {
PowerZones::Logo => { PowerZones::Logo => {
self.boot as u32 self.boot as u32
@@ -110,6 +110,12 @@ impl AuraPowerState {
| (self.sleep as u32) << 4 | (self.sleep as u32) << 4
| (self.shutdown as u32) << 6 | (self.shutdown as u32) << 6
} }
PowerZones::Ally => {
(self.boot as u32)
| (self.awake as u32) << 1
| (self.sleep as u32) << 2
| (self.shutdown as u32) << 3
}
PowerZones::Keyboard => { PowerZones::Keyboard => {
(self.boot as u32) << 1 (self.boot as u32) << 1
| (self.awake as u32) << 3 | (self.awake as u32) << 3
@@ -187,7 +193,7 @@ impl LaptopAuraPower {
// TODO: use support data to setup correct zones // TODO: use support data to setup correct zones
pub fn new(aura_type: AuraDeviceType, support_data: &LedSupportData) -> Self { pub fn new(aura_type: AuraDeviceType, support_data: &LedSupportData) -> Self {
match aura_type { match aura_type {
AuraDeviceType::Unknown | AuraDeviceType::LaptopPost2021 => { AuraDeviceType::Unknown | AuraDeviceType::Ally | AuraDeviceType::LaptopPost2021 => {
let mut states = Vec::new(); let mut states = Vec::new();
for zone in support_data.power_zones.iter() { for zone in support_data.power_zones.iter() {
states.push(AuraPowerState::default_for(*zone)) states.push(AuraPowerState::default_for(*zone))
@@ -217,8 +223,13 @@ impl LaptopAuraPower {
} }
pub fn to_bytes(&self, aura_type: AuraDeviceType) -> Vec<u8> { pub fn to_bytes(&self, aura_type: AuraDeviceType) -> Vec<u8> {
if let Some(stuff) = self.states.first() {
if stuff.zone == PowerZones::Ally {
return vec![0x5d, 0xd1, 0x09, 0x01, stuff.new_to_byte() as u8];
}
}
match aura_type { match aura_type {
AuraDeviceType::LaptopPost2021 => self.new_to_bytes(), AuraDeviceType::LaptopPost2021 | AuraDeviceType::Ally => self.new_to_bytes(),
AuraDeviceType::LaptopPre2021 => { AuraDeviceType::LaptopPre2021 => {
if self.states.len() == 1 { if self.states.len() == 1 {
self.states self.states

View File

@@ -74,6 +74,7 @@ pub enum AuraDeviceType {
LaptopPre2021 = 1, LaptopPre2021 = 1,
LaptopTuf = 2, LaptopTuf = 2,
ScsiExtDisk = 3, ScsiExtDisk = 3,
Ally = 4,
Unknown = 255, Unknown = 255,
} }
@@ -90,6 +91,10 @@ impl AuraDeviceType {
*self == Self::LaptopPost2021 *self == Self::LaptopPost2021
} }
pub fn is_ally(&self) -> bool {
*self == Self::Ally
}
pub fn is_scsi(&self) -> bool { pub fn is_scsi(&self) -> bool {
*self == Self::ScsiExtDisk *self == Self::ScsiExtDisk
} }
@@ -101,6 +106,7 @@ impl From<&str> for AuraDeviceType {
"tuf" => AuraDeviceType::LaptopTuf, "tuf" => AuraDeviceType::LaptopTuf,
"1932" => AuraDeviceType::ScsiExtDisk, "1932" => AuraDeviceType::ScsiExtDisk,
"1866" | "18c6" | "1869" | "1854" => Self::LaptopPre2021, "1866" | "18c6" | "1869" | "1854" => Self::LaptopPre2021,
"1abe" | "1b4c" => Self::Ally,
_ => Self::LaptopPost2021, _ => Self::LaptopPost2021,
} }
} }
@@ -128,5 +134,7 @@ pub enum PowerZones {
RearGlow = 4, RearGlow = 4,
/// Exists for the older 0x1866 models /// Exists for the older 0x1866 models
KeyboardAndLightbar = 5, KeyboardAndLightbar = 5,
/// Ally specific for creating correct packet
Ally = 6,
None = 255, None = 255,
} }

View File

@@ -16,9 +16,9 @@ x11 = ["slint/backend-winit-x11"]
tokio-debug = ["console-subscriber"] tokio-debug = ["console-subscriber"]
[dependencies] [dependencies]
console-subscriber = { version = "0.2.0", optional = true } console-subscriber = { version = "^0.4", optional = true }
nix = { version = "^0.28.0", features = ["fs"] } nix = { version = "^0.29.0", features = ["fs"] }
tempfile = "3.3.0" tempfile = "3.3.0"
betrayer = { version = "0.2.0" } betrayer = { version = "0.2.0" }

View File

@@ -65,6 +65,7 @@ impl From<PowerZones> for SlintPowerZones {
PowerZones::Lid => SlintPowerZones::Lid, PowerZones::Lid => SlintPowerZones::Lid,
PowerZones::RearGlow => SlintPowerZones::RearGlow, PowerZones::RearGlow => SlintPowerZones::RearGlow,
PowerZones::KeyboardAndLightbar => SlintPowerZones::KeyboardAndLightbar, PowerZones::KeyboardAndLightbar => SlintPowerZones::KeyboardAndLightbar,
PowerZones::Ally => SlintPowerZones::Ally,
PowerZones::None => SlintPowerZones::Keyboard, PowerZones::None => SlintPowerZones::Keyboard,
} }
} }
@@ -79,6 +80,7 @@ impl From<SlintPowerZones> for PowerZones {
SlintPowerZones::Lid => PowerZones::Lid, SlintPowerZones::Lid => PowerZones::Lid,
SlintPowerZones::RearGlow => PowerZones::RearGlow, SlintPowerZones::RearGlow => PowerZones::RearGlow,
SlintPowerZones::KeyboardAndLightbar => PowerZones::KeyboardAndLightbar, SlintPowerZones::KeyboardAndLightbar => PowerZones::KeyboardAndLightbar,
SlintPowerZones::Ally => PowerZones::Ally,
} }
} }
} }
@@ -151,6 +153,7 @@ impl From<SlintDeviceType> for AuraDeviceType {
SlintDeviceType::Tuf => Self::LaptopTuf, SlintDeviceType::Tuf => Self::LaptopTuf,
SlintDeviceType::ScsiExtDisk => Self::ScsiExtDisk, SlintDeviceType::ScsiExtDisk => Self::ScsiExtDisk,
SlintDeviceType::Unknown => Self::Unknown, SlintDeviceType::Unknown => Self::Unknown,
SlintDeviceType::Ally => Self::Ally,
} }
} }
} }
@@ -163,6 +166,7 @@ impl From<AuraDeviceType> for SlintDeviceType {
AuraDeviceType::LaptopTuf => SlintDeviceType::Tuf, AuraDeviceType::LaptopTuf => SlintDeviceType::Tuf,
AuraDeviceType::ScsiExtDisk => SlintDeviceType::ScsiExtDisk, AuraDeviceType::ScsiExtDisk => SlintDeviceType::ScsiExtDisk,
AuraDeviceType::Unknown => SlintDeviceType::Unknown, AuraDeviceType::Unknown => SlintDeviceType::Unknown,
AuraDeviceType::Ally => SlintDeviceType::Ally,
} }
} }
} }

View File

@@ -2,7 +2,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-08-26 05:52+0000\n" "POT-Creation-Date: 2024-08-26 07:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"

View File

@@ -4,6 +4,7 @@ export enum AuraDevType {
Tuf, Tuf,
ScsiExtDisk, ScsiExtDisk,
Unknown, Unknown,
Ally,
} }
export struct AuraEffect { export struct AuraEffect {
@@ -28,6 +29,7 @@ export enum PowerZones {
Lid, Lid,
RearGlow, RearGlow,
KeyboardAndLightbar, KeyboardAndLightbar,
Ally,
} }
export struct AuraPowerState { export struct AuraPowerState {
@@ -52,6 +54,7 @@ export global AuraPageData {
@tr("Aura power zone" => "Lid"), @tr("Aura power zone" => "Lid"),
@tr("Aura power zone" => "Rear Glow"), @tr("Aura power zone" => "Rear Glow"),
@tr("Aura power zone" => "Keyboard and Lightbar"), @tr("Aura power zone" => "Keyboard and Lightbar"),
@tr("Aura power zone" => "Ally"),
]; ];
// Exists only for the older 0x1866 keybaords. On page setup it must // Exists only for the older 0x1866 keybaords. On page setup it must
// be set to match the supported_power_zones // be set to match the supported_power_zones

View File

@@ -43,23 +43,17 @@ impl KeyboardBacklight {
PlatformError::Udev("match_subsystem failed".into(), err) PlatformError::Udev("match_subsystem failed".into(), err)
})?; })?;
enumerator for device in enumerator.scan_devices().map_err(|err| {
.match_sysname("asus::kbd_backlight")
.map_err(|err| {
warn!("{}", err);
PlatformError::Udev("match_subsystem failed".into(), err)
})?;
if let Some(device) = (enumerator.scan_devices().map_err(|err| {
warn!("{}", err); warn!("{}", err);
PlatformError::Udev("scan_devices failed".into(), err) PlatformError::Udev("scan_devices failed".into(), err)
})?) })? {
.next() let sys = device.sysname().to_string_lossy();
{ if sys.contains("kbd_backlight") || sys.contains("ally:rgb:gamepad") {
info!("Found keyboard LED controls at {:?}", device.sysname()); info!("Found keyboard LED controls at {:?}", device.sysname());
return Ok(Self { return Ok(Self {
path: device.syspath().to_owned(), path: device.syspath().to_owned(),
}); });
}
} }
Err(PlatformError::MissingFunction( Err(PlatformError::MissingFunction(
"KeyboardLed:new(), asus::kbd_backlight not found".into(), "KeyboardLed:new(), asus::kbd_backlight not found".into(),

View File

@@ -19,6 +19,6 @@ uhid-virt = "^0.0.7"
rog_anime = { path = "../rog-anime", features = ["dbus"] } rog_anime = { path = "../rog-anime", features = ["dbus"] }
[dependencies.sdl2] [dependencies.sdl2]
version = "0.36" version = "0.37"
default-features = false default-features = false
# features = ["gfx"] # features = ["gfx"]