Compare commits

...

21 Commits
4.2.0 ... 4.3.0

Author SHA1 Message Date
Luke D. Jones
cd7e748c88 Prep new release 2022-07-21 19:36:17 +12:00
Luke Jones
f222eef6b7 Update CHANGELOG.md 2022-07-21 03:40:04 +00:00
Luke Jones
e6f3aeb851 Merge branch 'fluke/multi-led-power' into 'main'
Make LED power more universal

Closes #219

See merge request asus-linux/asusctl!122
2022-07-21 03:39:11 +00:00
Luke D. Jones
22605e57cc Properly set full defaults for LED power 2022-07-21 14:56:30 +12:00
Luke D. Jones
02fb7addf4 Make LED power more universal
Closes #219
2022-07-21 14:48:16 +12:00
Luke Jones
bdbb403a0e Merge branch 'fluke/errors' into 'main'
Improve error handling in some cases

See merge request asus-linux/asusctl!121
2022-07-20 09:01:55 +00:00
Luke D. Jones
7a8bede92f Return error if a pixel-gif is larger than the anime-display dimensions 2022-07-20 20:52:03 +12:00
Luke D. Jones
a71a40b509 Make rog-anime more tolerent of faults 2022-07-20 20:17:43 +12:00
Luke D. Jones
42fc5a5392 Minor doc comment change 2022-07-18 15:43:09 +12:00
Luke D. Jones
5017a0ea9b Add extra multizone test 2022-07-18 14:11:54 +12:00
Luke D. Jones
05f7b0060f Prep new release 2022-07-18 14:01:32 +12:00
Luke Jones
1043da5328 Merge branch 'fluke/multizone-defaults' into 'main'
Create defaults on missing zones

See merge request asus-linux/asusctl!120
2022-07-18 01:50:35 +00:00
Luke D. Jones
959ad35afa Create defaults on missing zones 2022-07-18 13:40:42 +12:00
Luke Jones
1e10255d01 Merge branch 'fluke/multizone-fixes' into 'main'
Fluke/multizone fixes

See merge request asus-linux/asusctl!119
2022-07-17 10:02:32 +00:00
Luke D. Jones
c72693bc53 Fix test for CI 2022-07-17 22:02:01 +12:00
Luke D. Jones
2297aad5e5 Fix test 2022-07-17 21:49:15 +12:00
Luke D. Jones
f39c0db680 Add more support detection for bios/system level components 2022-07-17 21:02:39 +12:00
Luke D. Jones
23353c77f3 Add panel_od support 2022-07-17 20:31:47 +12:00
Luke D. Jones
fee1486db6 Correctly save multizone config 2022-07-17 19:23:08 +12:00
Luke D. Jones
39c4253b24 Add GA401I Anime support 2022-07-17 15:08:18 +12:00
Luke D. Jones
84e924f46a Add doc comments for bytes of 0x1866 power control 2022-07-16 22:52:36 +12:00
37 changed files with 1288 additions and 499 deletions

View File

@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased ]
## [4.3.0] - 2022-07-21
### Added
- Clear command for anime `asusctl anime --clear` will clear the display
- Re-added support for LED power states on `0x1866` type keyboards
### Changed
- Make rog-anime more error tolerent. Remove various asserts and return errors instead
- Return error if a pixel-gif is larger than the anime-display dimensions
- Both Anime and Aura dbus interfaces are changed a little
- Aura power has changed, all power related settings are now in one method
- Anime methods will now return an error (if errored)
- /org/asuslinux/Led renamed to /org/asuslinux/Aura
## [4.2.1] - 2022-07-18
### Added
- Add panel overdrive support (autodetects if supported)
- Add detection of dgpu_disable and egpu_enable for diagnostic
### Changed
- Fixed save and restore of multizone LED settings
- Create defaults for multizone
## [4.2.0] - 2022-07-16
### Added
- Support for GA402 Anime Matrix display (Author: I-Al-Istannen & Luke Jones)

11
Cargo.lock generated
View File

@@ -33,7 +33,7 @@ dependencies = [
[[package]]
name = "asusctl"
version = "4.0.7"
version = "4.3.0"
dependencies = [
"daemon",
"gif",
@@ -278,7 +278,7 @@ dependencies = [
[[package]]
name = "daemon"
version = "4.2.0"
version = "4.3.0"
dependencies = [
"async-trait",
"env_logger",
@@ -1018,7 +1018,7 @@ dependencies = [
[[package]]
name = "rog_anime"
version = "1.3.4"
version = "1.3.5"
dependencies = [
"gif",
"glam",
@@ -1029,12 +1029,13 @@ dependencies = [
"serde_derive",
"sysfs-class",
"udev",
"zbus",
"zvariant",
]
[[package]]
name = "rog_aura"
version = "1.1.1"
version = "1.2.0"
dependencies = [
"serde",
"serde_derive",
@@ -1067,7 +1068,7 @@ dependencies = [
[[package]]
name = "rog_supported"
version = "4.0.0"
version = "4.2.1"
dependencies = [
"rog_aura",
"serde",

View File

@@ -1,6 +1,6 @@
[package]
name = "asusctl"
version = "4.0.7"
version = "4.3.0"
authors = ["Luke D Jones <luke@ljones.dev>"]
edition = "2018"

View File

@@ -25,7 +25,7 @@ fn main() -> Result<(), Box<dyn Error>> {
client
.proxies()
.anime()
.write(matrix.into_data_buffer(anime_type))
.write(matrix.into_data_buffer(anime_type)?)
.unwrap();
Ok(())

View File

@@ -29,7 +29,7 @@ fn main() {
client
.proxies()
.anime()
.write(matrix.into_data_buffer(anime_type))
.write(matrix.into_data_buffer(anime_type).unwrap())
.unwrap();
sleep(Duration::from_millis(300));
}

View File

@@ -1,5 +1,6 @@
use rog_anime::{usb::get_anime_type, AnimeDataBuffer, AnimeGrid};
use rog_dbus::RogDbusClientBlocking;
use std::convert::TryFrom;
// In usable data:
// Top row start at 1, ends at 32
@@ -39,7 +40,7 @@ fn main() {
}
}
let matrix = <AnimeDataBuffer>::from(matrix);
let matrix = <AnimeDataBuffer>::try_from(matrix).unwrap();
client.proxies().anime().write(matrix).unwrap();
}

View File

@@ -1,3 +1,4 @@
use std::convert::TryFrom;
use std::{env, error::Error, path::Path, process::exit};
use rog_anime::{
@@ -32,7 +33,7 @@ fn main() -> Result<(), Box<dyn Error>> {
client
.proxies()
.anime()
.write(<AnimeDataBuffer>::from(&matrix))
.write(<AnimeDataBuffer>::try_from(&matrix)?)
.unwrap();
Ok(())

View File

@@ -1,3 +1,4 @@
use std::convert::TryFrom;
use std::{
env, error::Error, f32::consts::PI, path::Path, process::exit, thread::sleep, time::Duration,
};
@@ -41,7 +42,7 @@ fn main() -> Result<(), Box<dyn Error>> {
client
.proxies()
.anime()
.write(<AnimeDataBuffer>::from(&matrix))
.write(<AnimeDataBuffer>::try_from(&matrix)?)
.unwrap();
sleep(Duration::from_micros(500));
}

View File

@@ -16,6 +16,8 @@ pub struct AnimeCommand {
pub boot_enable: Option<bool>,
#[options(meta = "", help = "set global AniMe brightness value")]
pub brightness: Option<f32>,
#[options(help = "clear the display")]
pub clear: bool,
#[options(command)]
pub command: Option<AnimeActions>,
}

View File

@@ -3,7 +3,23 @@ use rog_aura::{error::Error, AuraEffect, AuraModeNum, AuraZone, Colour, Directio
use std::str::FromStr;
#[derive(Options)]
pub struct LedPowerCommand {
pub struct LedPowerCommand1 {
#[options(help = "print help message")]
pub help: bool,
#[options(meta = "", help = "Control if LEDs enabled while awake <true/false>")]
pub awake: Option<bool>,
#[options(meta = "", help = "Use with awake option <true/false>")]
pub keyboard: Option<bool>,
#[options(meta = "", help = "Use with awake option <true/false>")]
pub lightbar: Option<bool>,
#[options(meta = "", help = "Control boot animations <true/false>")]
pub boot: Option<bool>,
#[options(meta = "", help = "Control suspend animations <true/false>")]
pub sleep: Option<bool>,
}
#[derive(Options)]
pub struct LedPowerCommand2 {
#[options(help = "print help message")]
pub help: bool,
#[options(command)]
@@ -12,12 +28,13 @@ pub struct LedPowerCommand {
#[derive(Options)]
pub enum SetAuraEnabled {
/// Applies to both old and new models
#[options(help = "set <keyboard, logo, lightbar> to enabled while device is awake")]
Awake(AuraEnabled),
#[options(help = "set <keyboard, logo, lightbar> to enabled while the device is booting")]
Boot(AuraEnabled),
#[options(help = "set <keyboard, logo, lightbar> to animate while the device is suspended")]
Sleep(AuraEnabled),
#[options(help = "set <keyboard, logo, lightbar> to enabled while device is awake")]
Awake(AuraEnabled),
#[options(help = "set <keyboard, logo, lightbar> to animate while the device is shutdown")]
Shutdown(AuraEnabled),
}

View File

@@ -1,6 +1,6 @@
use crate::{
anime_cli::AnimeCommand,
aura_cli::{LedBrightness, LedPowerCommand, SetAuraBuiltin},
aura_cli::{LedBrightness, LedPowerCommand1, LedPowerCommand2, SetAuraBuiltin},
profiles_cli::{FanCurveCommand, ProfileCommand},
};
use gumdrop::Options;
@@ -29,8 +29,10 @@ pub struct CliStart {
pub enum CliCommand {
#[options(help = "Set the keyboard lighting from built-in modes")]
LedMode(LedModeCommand),
#[options(help = "Set the keyboard lighting from built-in modes")]
LedPower(LedPowerCommand),
#[options(help = "Set the LED power states")]
LedPow1(LedPowerCommand1),
#[options(help = "Set the LED power states")]
LedPow2(LedPowerCommand2),
#[options(help = "Set or select platform_profile")]
Profile(ProfileCommand),
#[options(help = "Set, select, or modify fan curves if supported")]
@@ -67,18 +69,29 @@ pub struct BiosCommand {
pub help: bool,
#[options(
meta = "",
short = "S",
no_long,
help = "set bios POST sound: asusctl -p <true/false>"
)]
pub post_sound_set: Option<bool>,
#[options(no_long, help = "read bios POST sound")]
#[options(no_long, short = "s", help = "read bios POST sound")]
pub post_sound_get: bool,
#[options(
meta = "",
short = "D",
no_long,
help = "activate dGPU dedicated/G-Sync: asusctl -d <true/false>, reboot required"
)]
pub dedicated_gfx_set: Option<bool>,
#[options(no_long, help = "get GPU mode")]
#[options(no_long, short = "d", help = "get GPU mode")]
pub dedicated_gfx_get: bool,
#[options(
meta = "",
short = "O",
no_long,
help = "Set device panel overdrive <true/false>"
)]
pub panel_overdrive_set: Option<bool>,
#[options(no_long, short = "o", help = "get panel overdrive")]
pub panel_overdrive_get: bool,
}

View File

@@ -1,15 +1,16 @@
use std::convert::TryFrom;
use std::process::Command;
use std::thread::sleep;
use std::{env::args, path::Path};
use aura_cli::LedPowerCommand;
use aura_cli::{LedPowerCommand1, LedPowerCommand2};
use gumdrop::{Opt, Options};
use anime_cli::{AnimeActions, AnimeCommand};
use profiles_cli::{FanCurveCommand, ProfileCommand};
use rog_anime::usb::get_anime_type;
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, Vec2};
use rog_aura::usb::AuraControl;
use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraPowerDev};
use rog_aura::{self, AuraEffect};
use rog_dbus::RogDbusClientBlocking;
use rog_profiles::error::ProfileError;
@@ -27,8 +28,6 @@ mod aura_cli;
mod cli_opts;
mod profiles_cli;
const CONFIG_ADVICE: &str = "A config file need to be removed so a new one can be generated";
fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = args().skip(1).collect();
@@ -82,15 +81,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
fn print_error_help(err: Box<dyn std::error::Error>, supported: Option<&SupportedFunctions>) {
if do_diagnose("asusd") {
println!("\nError: {}\n", err);
print_versions();
check_service("asusd");
println!("\nError: {}\n", err);
print_versions();
println!();
print_laptop_info();
if let Some(supported) = supported {
println!();
print_laptop_info();
if let Some(supported) = supported {
println!();
println!("Supported laptop functions:\n\n{}", supported);
}
println!("Supported laptop functions:\n\n{}", supported);
}
}
@@ -115,7 +113,7 @@ fn print_laptop_info() {
println!("Board name: {}", board_name.trim());
}
fn do_diagnose(name: &str) -> bool {
fn check_service(name: &str) -> bool {
if name != "asusd" && !check_systemd_unit_enabled(name) {
println!(
"\n\x1b[0;31m{} is not enabled, enable it with `systemctl enable {}\x1b[0m",
@@ -128,13 +126,6 @@ fn do_diagnose(name: &str) -> bool {
name, name
);
return true;
} else {
println!("\nSome error happened (sorry)");
println!(
"Please use `systemctl status {}` and `journalctl -b -u {}` for more information",
name, name
);
println!("{}", CONFIG_ADVICE);
}
false
}
@@ -146,7 +137,8 @@ fn do_parsed(
) -> Result<(), Box<dyn std::error::Error>> {
match &parsed.command {
Some(CliCommand::LedMode(mode)) => handle_led_mode(dbus, &supported.keyboard_led, mode)?,
Some(CliCommand::LedPower(pow)) => handle_led_power(dbus, &supported.keyboard_led, pow)?,
Some(CliCommand::LedPow1(pow)) => handle_led_power1(dbus, &supported.keyboard_led, pow)?,
Some(CliCommand::LedPow2(pow)) => handle_led_power2(dbus, &supported.keyboard_led, pow)?,
Some(CliCommand::Profile(cmd)) => handle_profile(dbus, &supported.platform_profile, cmd)?,
Some(CliCommand::FanCurve(cmd)) => {
handle_fan_curve(dbus, &supported.platform_profile, cmd)?
@@ -165,8 +157,27 @@ fn do_parsed(
println!("{}", CliStart::usage());
println!();
if let Some(cmdlist) = CliStart::command_list() {
println!("{}", cmdlist);
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_string()).collect();
for command in commands.iter().filter(|command| {
if supported.keyboard_led.prod_id != "1866"
&& command.trim().starts_with("led-pow-1")
{
return false;
}
if supported.keyboard_led.prod_id != "19b6"
&& command.trim().starts_with("led-pow-2")
{
return false;
}
true
}) {
println!("{}", command);
}
}
println!("\nExtra help can be requested on any command or subcommand:");
println!(" asusctl led-mode --help");
println!(" asusctl led-mode static --help");
}
}
}
@@ -235,6 +246,13 @@ fn handle_anime(
verify_brightness(bright);
dbus.proxies().anime().set_brightness(bright)?
}
if cmd.clear {
let anime_type = get_anime_type()?;
let data = vec![0u8; anime_type.data_length()];
let tmp = AnimeDataBuffer::from_vec(anime_type, data)?;
dbus.proxies().anime().write(tmp)?;
}
if let Some(action) = cmd.command.as_ref() {
let anime_type = get_anime_type()?;
match action {
@@ -259,7 +277,7 @@ fn handle_anime(
dbus.proxies()
.anime()
.write(<AnimeDataBuffer>::from(&matrix))?;
.write(<AnimeDataBuffer>::try_from(&matrix)?)?;
}
AnimeActions::PixelImage(image) => {
if image.help_requested() || image.path.is_empty() {
@@ -280,7 +298,7 @@ fn handle_anime(
dbus.proxies()
.anime()
.write(matrix.into_data_buffer(anime_type))?;
.write(matrix.into_data_buffer(anime_type)?)?;
}
AnimeActions::Gif(gif) => {
if gif.help_requested() || gif.path.is_empty() {
@@ -419,10 +437,67 @@ fn handle_led_mode(
Ok(())
}
fn handle_led_power(
fn handle_led_power1(
dbus: &RogDbusClientBlocking,
_supported: &LedSupportedFunctions,
power: &LedPowerCommand,
supported: &LedSupportedFunctions,
power: &LedPowerCommand1,
) -> Result<(), Box<dyn std::error::Error>> {
if power.awake.is_none()
&& power.sleep.is_none()
&& power.boot.is_none()
&& power.keyboard.is_none()
&& power.lightbar.is_none()
{
if !power.help {
println!("Missing arg or command\n");
}
println!("{}\n", power.self_usage());
return Ok(());
}
if supported.prod_id != "1866" {
println!("These options are for keyboards of product ID 0x1866 only");
return Ok(());
}
let mut enabled: Vec<AuraDev1866> = Vec::new();
let mut disabled: Vec<AuraDev1866> = Vec::new();
let mut check = |e: Option<bool>, a: AuraDev1866| {
if let Some(arg) = e {
if arg {
enabled.push(a);
} else {
disabled.push(a);
}
}
};
check(power.awake, AuraDev1866::Awake);
check(power.boot, AuraDev1866::Boot);
check(power.sleep, AuraDev1866::Sleep);
check(power.keyboard, AuraDev1866::Keyboard);
check(power.lightbar, AuraDev1866::Lightbar);
let data = AuraPowerDev {
x1866: enabled,
x19b6: vec![],
};
dbus.proxies().led().set_leds_power(data, true)?;
let data = AuraPowerDev {
x1866: disabled,
x19b6: vec![],
};
dbus.proxies().led().set_leds_power(data, false)?;
Ok(())
}
fn handle_led_power2(
dbus: &RogDbusClientBlocking,
supported: &LedSupportedFunctions,
power: &LedPowerCommand2,
) -> Result<(), Box<dyn std::error::Error>> {
if power.command().is_none() {
if !power.help {
@@ -431,7 +506,7 @@ fn handle_led_power(
println!("{}\n", power.self_usage());
println!("Commands available");
if let Some(cmdlist) = LedPowerCommand::command_list() {
if let Some(cmdlist) = LedPowerCommand2::command_list() {
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_string()).collect();
for command in commands.iter() {
println!("{}", command);
@@ -448,133 +523,60 @@ fn handle_led_power(
return Ok(());
}
if supported.prod_id == "1866" {
println!("This option does not apply to keyboards with product ID 0x1866")
}
let mut enabled: Vec<AuraDev19b6> = Vec::new();
let mut disabled: Vec<AuraDev19b6> = Vec::new();
let mut check = |e: Option<bool>, a: AuraDev19b6| {
if let Some(arg) = e {
if arg {
enabled.push(a);
} else {
disabled.push(a);
}
}
};
match pow {
// TODO: make this a macro or something
aura_cli::SetAuraEnabled::Boot(arg) => {
let mut enabled: Vec<AuraControl> = Vec::new();
let mut disabled: Vec<AuraControl> = Vec::new();
arg.keyboard.map(|v| {
if v {
enabled.push(AuraControl::BootKeyb)
} else {
disabled.push(AuraControl::BootKeyb)
}
});
arg.logo.map(|v| {
if v {
enabled.push(AuraControl::BootLogo)
} else {
disabled.push(AuraControl::BootLogo)
}
});
arg.lightbar.map(|v| {
if v {
enabled.push(AuraControl::BootBar)
} else {
disabled.push(AuraControl::BootBar)
}
});
if !enabled.is_empty() {
dbus.proxies().led().set_leds_enabled(enabled)?;
}
if !disabled.is_empty() {
dbus.proxies().led().set_leds_disabled(disabled)?;
}
check(arg.keyboard, AuraDev19b6::BootKeyb);
check(arg.logo, AuraDev19b6::BootLogo);
check(arg.lightbar, AuraDev19b6::BootBar);
}
aura_cli::SetAuraEnabled::Sleep(arg) => {
let mut enabled: Vec<AuraControl> = Vec::new();
let mut disabled: Vec<AuraControl> = Vec::new();
arg.keyboard.map(|v| {
if v {
enabled.push(AuraControl::SleepKeyb)
} else {
disabled.push(AuraControl::SleepKeyb)
}
});
arg.logo.map(|v| {
if v {
enabled.push(AuraControl::SleepLogo)
} else {
disabled.push(AuraControl::SleepLogo)
}
});
arg.lightbar.map(|v| {
if v {
enabled.push(AuraControl::SleepBar)
} else {
disabled.push(AuraControl::SleepBar)
}
});
if !enabled.is_empty() {
dbus.proxies().led().set_leds_enabled(enabled)?;
}
if !disabled.is_empty() {
dbus.proxies().led().set_leds_disabled(disabled)?;
}
check(arg.keyboard, AuraDev19b6::SleepKeyb);
check(arg.logo, AuraDev19b6::SleepLogo);
check(arg.lightbar, AuraDev19b6::SleepBar);
}
aura_cli::SetAuraEnabled::Awake(arg) => {
let mut enabled: Vec<AuraControl> = Vec::new();
let mut disabled: Vec<AuraControl> = Vec::new();
arg.keyboard.map(|v| {
if v {
enabled.push(AuraControl::AwakeKeyb)
} else {
disabled.push(AuraControl::AwakeKeyb)
}
});
arg.logo.map(|v| {
if v {
enabled.push(AuraControl::AwakeLogo)
} else {
disabled.push(AuraControl::AwakeLogo)
}
});
arg.lightbar.map(|v| {
if v {
enabled.push(AuraControl::AwakeBar)
} else {
disabled.push(AuraControl::AwakeBar)
}
});
if !enabled.is_empty() {
dbus.proxies().led().set_leds_enabled(enabled)?;
}
if !disabled.is_empty() {
dbus.proxies().led().set_leds_disabled(disabled)?;
}
check(arg.keyboard, AuraDev19b6::AwakeKeyb);
check(arg.logo, AuraDev19b6::AwakeLogo);
check(arg.lightbar, AuraDev19b6::AwakeBar);
}
aura_cli::SetAuraEnabled::Shutdown(arg) => {
let mut enabled: Vec<AuraControl> = Vec::new();
let mut disabled: Vec<AuraControl> = Vec::new();
arg.keyboard.map(|v| {
if v {
enabled.push(AuraControl::ShutdownKeyb)
} else {
disabled.push(AuraControl::ShutdownKeyb)
}
});
arg.logo.map(|v| {
if v {
enabled.push(AuraControl::ShutdownLogo)
} else {
disabled.push(AuraControl::ShutdownLogo)
}
});
arg.lightbar.map(|v| {
if v {
enabled.push(AuraControl::ShutdownBar)
} else {
disabled.push(AuraControl::ShutdownBar)
}
});
if !enabled.is_empty() {
dbus.proxies().led().set_leds_enabled(enabled)?;
}
if !disabled.is_empty() {
dbus.proxies().led().set_leds_disabled(disabled)?;
}
check(arg.keyboard, AuraDev19b6::ShutdownKeyb);
check(arg.logo, AuraDev19b6::ShutdownLogo);
check(arg.lightbar, AuraDev19b6::ShutdownBar);
}
}
if !enabled.is_empty() {
let data = AuraPowerDev {
x1866: vec![],
x19b6: enabled,
};
dbus.proxies().led().set_leds_power(data, true)?;
}
if !disabled.is_empty() {
let data = AuraPowerDev {
x1866: vec![],
x19b6: disabled,
};
dbus.proxies().led().set_leds_power(data, false)?;
}
}
Ok(())
@@ -692,7 +694,9 @@ fn handle_bios_option(
if (cmd.dedicated_gfx_set.is_none()
&& !cmd.dedicated_gfx_get
&& cmd.post_sound_set.is_none()
&& !cmd.post_sound_get)
&& !cmd.post_sound_get
&& cmd.panel_overdrive_set.is_none()
&& !cmd.panel_overdrive_get)
|| cmd.help
{
println!("Missing arg or command\n");
@@ -703,8 +707,9 @@ fn handle_bios_option(
.collect();
for line in usage.iter().filter(|line| {
line.contains("sound") && supported.post_sound_toggle
|| line.contains("GPU") && supported.dedicated_gfx_toggle
line.contains("sound") && supported.post_sound
|| line.contains("GPU") && supported.dedicated_gfx
|| line.contains("panel") && supported.panel_overdrive
}) {
println!("{}", line);
}
@@ -717,6 +722,7 @@ fn handle_bios_option(
let res = dbus.proxies().rog_bios().post_boot_sound()? == 1;
println!("Bios POST sound on: {}", res);
}
if let Some(opt) = cmd.dedicated_gfx_set {
println!("Rebuilding initrd to include drivers");
dbus.proxies().rog_bios().set_dedicated_graphic_mode(opt)?;
@@ -733,6 +739,14 @@ fn handle_bios_option(
let res = dbus.proxies().rog_bios().dedicated_graphic_mode()? == 1;
println!("Bios dedicated GPU on: {}", res);
}
if let Some(opt) = cmd.panel_overdrive_set {
dbus.proxies().rog_bios().set_panel_overdrive(opt)?;
}
if cmd.panel_overdrive_get {
let res = dbus.proxies().rog_bios().panel_overdrive()? == 1;
println!("Panel overdrive on: {}", res);
}
}
Ok(())
}

View File

@@ -1,6 +1,6 @@
[package]
name = "daemon"
version = "4.2.0"
version = "4.3.0"
license = "MPL-2.0"
readme = "README.md"
authors = ["Luke <luke@ljones.dev>"]

View File

@@ -6,7 +6,7 @@ use std::path::PathBuf;
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, Default)]
pub struct Config {
/// Save charge limit for restoring on boot
pub bat_charge_limit: u8,

View File

@@ -18,6 +18,7 @@ use rusb::{Device, DeviceHandle};
use smol::{stream::StreamExt, Executor};
use std::{
cell::RefCell,
convert::TryFrom,
error::Error,
sync::{Arc, Mutex, MutexGuard},
thread::sleep,
@@ -167,7 +168,14 @@ impl CtrlAnime {
inner
.try_lock()
.map(|lock| {
lock.write_data_buffer(frame);
lock.write_data_buffer(frame)
.map_err(|err| {
warn!(
"rog_anime::run_animation:callback {}",
err
);
})
.ok();
false // Don't exit yet
})
.map_err(|err| {
@@ -183,6 +191,8 @@ impl CtrlAnime {
once = false;
if let Ok(lock) = inner.try_lock() {
lock.write_data_buffer(image.as_ref().clone())
.map_err(|e| error!("{}", e))
.ok();
}
}
ActionData::Pause(duration) => sleep(*duration),
@@ -201,9 +211,16 @@ impl CtrlAnime {
}
// Clear the display on exit
if let Ok(lock) = inner.try_lock() {
let data =
AnimeDataBuffer::from_vec(anime_type, vec![0u8; anime_type.data_length()]);
lock.write_data_buffer(data);
if let Ok(data) =
AnimeDataBuffer::from_vec(anime_type, vec![0u8; anime_type.data_length()])
.map_err(|e| error!("{}", e))
{
lock.write_data_buffer(data)
.map_err(|err| {
warn!("rog_anime::run_animation:callback {}", err);
})
.ok();
}
}
// Loop ended, set the atmonics
thread_running.store(false, Ordering::SeqCst);
@@ -254,7 +271,7 @@ impl CtrlAnime {
/// Write only a data packet. This will modify the leds brightness using the
/// global brightness set in config.
fn write_data_buffer(&self, mut buffer: AnimeDataBuffer) {
fn write_data_buffer(&self, mut buffer: AnimeDataBuffer) -> Result<(), RogError> {
for led in buffer.data_mut()[7..].iter_mut() {
let mut bright = *led as f32 * self.config.brightness;
if bright > 254.0 {
@@ -262,11 +279,12 @@ impl CtrlAnime {
}
*led = bright as u8;
}
let data = AnimePacketType::from(buffer);
let data = AnimePacketType::try_from(buffer)?;
for row in data.iter() {
self.write_bytes(row);
}
self.write_bytes(&pkt_for_flush());
Ok(())
}
fn do_initialization(&self) {

View File

@@ -1,6 +1,7 @@
use std::sync::{Arc, Mutex};
use async_trait::async_trait;
use log::warn;
use rog_anime::{
usb::{pkt_for_apply, pkt_for_set_boot, pkt_for_set_on},
AnimeDataBuffer, AnimePowerStates,
@@ -27,14 +28,18 @@ impl crate::ZbusAdd for CtrlAnimeZbus {
#[dbus_interface(name = "org.asuslinux.Daemon")]
impl CtrlAnimeZbus {
/// Writes a data stream of length. Will force system thread to exit until it is restarted
fn write(&self, input: AnimeDataBuffer) {
fn write(&self, input: AnimeDataBuffer) -> zbus::fdo::Result<()> {
'outer: loop {
if let Ok(lock) = self.0.try_lock() {
lock.thread_exit.store(true, Ordering::SeqCst);
lock.write_data_buffer(input);
lock.write_data_buffer(input).map_err(|err| {
warn!("rog_anime::run_animation:callback {}", err);
err
})?;
break 'outer;
}
}
Ok(())
}
/// Set the global AniMe brightness

View File

@@ -1,14 +1,75 @@
use crate::laptops::LaptopLedData;
use crate::laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES};
use log::{error, warn};
use rog_aura::usb::AuraControl;
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, LedBrightness};
use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraPowerDev};
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT};
use serde_derive::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashSet};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use super::controller::CtrlKbdLed;
pub static AURA_CONFIG_PATH: &str = "/etc/asusd/aura.conf";
/// Enable/disable LED control in various states such as
/// when the device is awake, suspended, shutting down or
/// booting.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum AuraPowerConfig {
AuraDev1866(HashSet<AuraDev1866>),
AuraDev19b6(HashSet<AuraDev19b6>),
}
impl AuraPowerConfig {
pub fn to_bytes(control: &Self) -> [u8; 3] {
match control {
AuraPowerConfig::AuraDev1866(c) => {
let c: Vec<AuraDev1866> = c.iter().map(|v| *v).collect();
AuraDev1866::to_bytes(&c)
}
AuraPowerConfig::AuraDev19b6(c) => {
let c: Vec<AuraDev19b6> = c.iter().map(|v| *v).collect();
AuraDev19b6::to_bytes(&c)
}
}
}
pub fn set_0x1866(&mut self, power: AuraDev1866, on: bool) {
if let Self::AuraDev1866(p) = self {
if on {
p.insert(power);
} else {
p.remove(&power);
}
}
}
pub fn set_0x19b6(&mut self, power: AuraDev19b6, on: bool) {
if let Self::AuraDev19b6(p) = self {
if on {
p.insert(power);
} else {
p.remove(&power);
}
}
}
}
impl From<&AuraPowerConfig> for AuraPowerDev {
fn from(config: &AuraPowerConfig) -> Self {
match config {
AuraPowerConfig::AuraDev1866(d) => AuraPowerDev {
x1866: d.iter().map(|o| *o).collect(),
x19b6: vec![],
},
AuraPowerConfig::AuraDev19b6(d) => AuraPowerDev {
x1866: vec![],
x19b6: d.iter().map(|o| *o).collect(),
},
}
}
}
#[derive(Deserialize, Serialize)]
#[serde(default)]
pub struct AuraConfig {
@@ -16,30 +77,52 @@ pub struct AuraConfig {
pub current_mode: AuraModeNum,
pub builtins: BTreeMap<AuraModeNum, AuraEffect>,
pub multizone: Option<BTreeMap<AuraModeNum, Vec<AuraEffect>>>,
pub enabled: HashSet<AuraControl>,
pub multizone_on: bool,
pub enabled: AuraPowerConfig,
}
impl Default for AuraConfig {
fn default() -> Self {
let mut prod_id = String::new();
for prod in ASUS_KEYBOARD_DEVICES.iter() {
if let Ok(_) = CtrlKbdLed::find_led_node(prod) {
prod_id = prod.to_string();
break;
}
}
let enabled = if prod_id == "19b6" {
AuraPowerConfig::AuraDev19b6(HashSet::from([
AuraDev19b6::BootLogo,
AuraDev19b6::BootKeyb,
AuraDev19b6::SleepLogo,
AuraDev19b6::SleepKeyb,
AuraDev19b6::AwakeLogo,
AuraDev19b6::AwakeKeyb,
AuraDev19b6::ShutdownLogo,
AuraDev19b6::ShutdownKeyb,
AuraDev19b6::AwakeBar,
AuraDev19b6::BootBar,
AuraDev19b6::SleepBar,
AuraDev19b6::ShutdownBar,
]))
} else {
AuraPowerConfig::AuraDev1866(HashSet::from([
AuraDev1866::Awake,
AuraDev1866::Boot,
AuraDev1866::Sleep,
AuraDev1866::Keyboard,
AuraDev1866::Lightbar,
]))
};
AuraConfig {
brightness: LedBrightness::Med,
current_mode: AuraModeNum::Static,
builtins: BTreeMap::new(),
multizone: None,
enabled: HashSet::from([
AuraControl::BootLogo,
AuraControl::BootKeyb,
AuraControl::SleepLogo,
AuraControl::SleepKeyb,
AuraControl::AwakeLogo,
AuraControl::AwakeKeyb,
AuraControl::ShutdownLogo,
AuraControl::ShutdownKeyb,
AuraControl::AwakeBar,
AuraControl::BootBar,
AuraControl::SleepBar,
AuraControl::ShutdownBar,
]),
multizone_on: false,
enabled,
}
}
}
@@ -90,6 +173,27 @@ impl AuraConfig {
config
.builtins
.insert(*n, AuraEffect::default_with_mode(*n));
if !support_data.multizone.is_empty() {
let mut default = vec![];
for (i, tmp) in support_data.multizone.iter().enumerate() {
default.push(AuraEffect {
mode: *n,
zone: *tmp,
colour1: *GRADIENT.get(i).unwrap_or(&GRADIENT[0]),
colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]),
speed: Speed::Med,
direction: Direction::Left,
})
}
if let Some(m) = config.multizone.as_mut() {
m.insert(*n, default);
} else {
let mut tmp = BTreeMap::new();
tmp.insert(*n, default);
config.multizone = Some(tmp);
}
}
}
// Should be okay to unwrap this as is since it is a Default
@@ -123,27 +227,35 @@ impl AuraConfig {
.unwrap_or_else(|err| error!("Could not write config: {}", err));
}
/// Multipurpose, will accept AuraEffect with zones and put in the correct store
/// Set the mode data, current mode, and if multizone enabled.
///
/// Multipurpose, will accept AuraEffect with zones and put in the correct store.
pub fn set_builtin(&mut self, effect: AuraEffect) {
self.current_mode = effect.mode;
match effect.zone() {
AuraZone::None => {
self.builtins.insert(*effect.mode(), effect);
self.multizone_on = false;
}
_ => {
if let Some(multi) = self.multizone.as_mut() {
if let Some(fx) = multi.get_mut(effect.mode()) {
for fx in fx.iter_mut() {
if fx.mode == effect.mode {
if fx.zone == effect.zone {
*fx = effect;
break;
return;
}
}
fx.push(effect);
} else {
let mut tmp = BTreeMap::new();
tmp.insert(*effect.mode(), vec![effect]);
self.multizone = Some(tmp);
multi.insert(*effect.mode(), vec![effect]);
}
} else {
let mut tmp = BTreeMap::new();
tmp.insert(*effect.mode(), vec![effect]);
self.multizone = Some(tmp);
}
self.multizone_on = true;
}
}
}
@@ -155,3 +267,86 @@ impl AuraConfig {
None
}
}
#[cfg(test)]
mod tests {
use super::AuraConfig;
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour};
#[test]
fn set_multizone_4key_config() {
let mut config = AuraConfig::default();
let mut effect = AuraEffect::default();
effect.colour1 = Colour(0xff, 0x00, 0xff);
effect.zone = AuraZone::Key1;
config.set_builtin(effect);
assert!(config.multizone.is_some());
let mut effect = AuraEffect::default();
effect.colour1 = Colour(0x00, 0xff, 0xff);
effect.zone = AuraZone::Key2;
config.set_builtin(effect);
let mut effect = AuraEffect::default();
effect.colour1 = Colour(0xff, 0xff, 0x00);
effect.zone = AuraZone::Key3;
config.set_builtin(effect);
let mut effect = AuraEffect::default();
effect.colour1 = Colour(0x00, 0xff, 0x00);
effect.zone = AuraZone::Key4;
let effect_clone = effect.clone();
config.set_builtin(effect);
// This should replace existing
config.set_builtin(effect_clone);
let res = config.multizone.unwrap();
let sta = res.get(&AuraModeNum::Static).unwrap();
assert_eq!(sta.len(), 4);
assert_eq!(sta[0].colour1, Colour(0xff, 0x00, 0xff));
assert_eq!(sta[1].colour1, Colour(0x00, 0xff, 0xff));
assert_eq!(sta[2].colour1, Colour(0xff, 0xff, 0x00));
assert_eq!(sta[3].colour1, Colour(0x00, 0xff, 0x00));
}
#[test]
fn set_multizone_multimode_config() {
let mut config = AuraConfig::default();
let mut effect = AuraEffect::default();
effect.zone = AuraZone::Key1;
config.set_builtin(effect);
assert!(config.multizone.is_some());
let mut effect = AuraEffect::default();
effect.zone = AuraZone::Key2;
effect.mode = AuraModeNum::Breathe;
config.set_builtin(effect);
let mut effect = AuraEffect::default();
effect.zone = AuraZone::Key3;
effect.mode = AuraModeNum::Comet;
config.set_builtin(effect);
let mut effect = AuraEffect::default();
effect.zone = AuraZone::Key4;
effect.mode = AuraModeNum::Pulse;
config.set_builtin(effect);
let res = config.multizone.unwrap();
let sta = res.get(&AuraModeNum::Static).unwrap();
assert_eq!(sta.len(), 1);
let sta = res.get(&AuraModeNum::Breathe).unwrap();
assert_eq!(sta.len(), 1);
let sta = res.get(&AuraModeNum::Comet).unwrap();
assert_eq!(sta.len(), 1);
let sta = res.get(&AuraModeNum::Pulse).unwrap();
assert_eq!(sta.len(), 1);
}
}

View File

@@ -9,23 +9,26 @@ use crate::{
use async_trait::async_trait;
use log::{error, info, warn};
use logind_zbus::manager::ManagerProxy;
use rog_aura::usb::AuraControl;
use rog_aura::{
usb::{LED_APPLY, LED_SET},
AuraEffect, LedBrightness, LED_MSG_LEN,
};
use rog_aura::{AuraZone, Direction, Speed, GRADIENT};
use rog_supported::LedSupportedFunctions;
use smol::{stream::StreamExt, Executor};
use std::io::{Read, Write};
use std::path::Path;
use std::sync::Arc;
use std::sync::Mutex;
use std::{
collections::BTreeMap,
io::{Read, Write},
};
use std::{fs::OpenOptions, sync::MutexGuard};
use zbus::Connection;
use crate::GetSupported;
use super::config::AuraConfig;
use super::config::{AuraConfig, AuraPowerConfig};
impl GetSupported for CtrlKbdLed {
type A = LedSupportedFunctions;
@@ -37,7 +40,16 @@ impl GetSupported for CtrlKbdLed {
let multizone_led_mode = laptop.multizone;
let per_key_led_mode = laptop.per_key;
let mut prod_id = String::new();
for prod in ASUS_KEYBOARD_DEVICES.iter() {
if let Ok(_) = Self::find_led_node(prod) {
prod_id = prod.to_string();
break;
}
}
LedSupportedFunctions {
prod_id,
brightness_set: CtrlKbdLed::get_kbd_bright_path().is_some(),
stock_led_modes,
multizone_led_mode,
@@ -47,6 +59,8 @@ impl GetSupported for CtrlKbdLed {
}
pub struct CtrlKbdLed {
// TODO: config stores the keyboard type as an AuraPower, use or update this
pub led_prod: Option<String>,
pub led_node: Option<String>,
pub bright_node: String,
pub supported_modes: LaptopLedData,
@@ -106,11 +120,9 @@ impl CtrlTask for CtrlKbdLedTask {
lock.set_brightness(lock.config.brightness)
.map_err(|e| error!("CtrlKbdLedTask: {e}"))
.ok();
if let Some(mode) = lock.config.builtins.get(&lock.config.current_mode) {
lock.write_mode(mode)
.map_err(|e| error!("CtrlKbdLedTask: {e}"))
.ok();
}
lock.write_current_config_mode()
.map_err(|e| error!("CtrlKbdLedTask: {e}"))
.ok();
} else if start {
info!("CtrlKbdLedTask saving last brightness");
Self::update_config(&mut lock)
@@ -154,15 +166,6 @@ impl CtrlTask for CtrlKbdLedTask {
}
})
.detach();
// let inner = self.inner.clone();
// self.repeating_task(500, executor, move || loop {
// if let Ok(ref mut lock) = inner.try_lock() {
// Self::update_config(lock).unwrap();
// break;
// }
// })
// .await;
Ok(())
}
}
@@ -172,11 +175,7 @@ pub struct CtrlKbdLedReloader(pub Arc<Mutex<CtrlKbdLed>>);
impl crate::Reloadable for CtrlKbdLedReloader {
fn reload(&mut self) -> Result<(), RogError> {
if let Ok(mut ctrl) = self.0.try_lock() {
let current = ctrl.config.current_mode;
if let Some(mode) = ctrl.config.builtins.get(&current).cloned() {
ctrl.do_command(mode).ok();
}
ctrl.write_current_config_mode()?;
ctrl.set_power_states(&ctrl.config)
.map_err(|err| warn!("{err}"))
.ok();
@@ -194,13 +193,14 @@ impl CtrlKbdLedZbus {
}
impl CtrlKbdLed {
#[inline]
pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result<Self, RogError> {
// TODO: return error if *all* nodes are None
let mut led_prod = None;
let mut led_node = None;
for prod in ASUS_KEYBOARD_DEVICES.iter() {
match Self::find_led_node(prod) {
Ok(node) => {
led_prod = Some(prod.to_string());
led_node = Some(node);
info!("Looked for keyboard controller 0x{prod}: Found");
break;
@@ -211,11 +211,8 @@ impl CtrlKbdLed {
let bright_node = Self::get_kbd_bright_path();
if led_node.is_none() && bright_node.is_none() {
return Err(RogError::MissingFunction(
"All keyboard features missing, you may require a v5.11 series kernel or newer"
.into(),
));
if led_node.is_none() {
return Err(RogError::NoAuraKeyboard);
}
if bright_node.is_none() {
@@ -225,6 +222,7 @@ impl CtrlKbdLed {
}
let ctrl = CtrlKbdLed {
led_prod,
led_node,
bright_node: bright_node.unwrap(), // If was none then we already returned above
supported_modes,
@@ -298,13 +296,8 @@ impl CtrlKbdLed {
/// Set combination state for boot animation/sleep animation/all leds/keys leds/side leds LED active
pub(super) fn set_power_states(&self, config: &AuraConfig) -> Result<(), RogError> {
let set: Vec<AuraControl> = config.enabled.iter().map(|v| *v).collect();
let bytes = AuraControl::to_bytes(&set);
// Quite ugly, must be a more idiomatic way to do
let message = [
0x5d, 0xbd, 0x01, bytes[0], bytes[1], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
let bytes = AuraPowerConfig::to_bytes(&config.enabled);
let message = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2]];
self.write_bytes(&message)?;
self.write_bytes(&LED_SET)?;
@@ -313,7 +306,7 @@ impl CtrlKbdLed {
Ok(())
}
fn find_led_node(id_product: &str) -> Result<String, RogError> {
pub(crate) fn find_led_node(id_product: &str) -> Result<String, RogError> {
let mut enumerator = udev::Enumerator::new().map_err(|err| {
warn!("{}", err);
RogError::Udev("enumerator failed".into(), err)
@@ -351,12 +344,27 @@ impl CtrlKbdLed {
))
}
pub(crate) fn do_command(&mut self, mode: AuraEffect) -> Result<(), RogError> {
self.set_and_save(mode)
/// Set an Aura effect if the effect mode or zone is supported.
///
/// On success the aura config file is read to refresh cached values, then the effect is
/// stored and config written to disk.
pub(crate) fn set_effect(&mut self, effect: AuraEffect) -> Result<(), RogError> {
if !self.supported_modes.standard.contains(&effect.mode) {
return Err(RogError::AuraEffectNotSupported);
} else if effect.zone != AuraZone::None
&& !self.supported_modes.multizone.contains(&effect.zone)
{
return Err(RogError::AuraEffectNotSupported);
}
self.write_mode(&effect)?;
self.config.read(); // refresh config if successful
self.config.set_builtin(effect);
self.config.write();
Ok(())
}
/// Should only be used if the bytes you are writing are verified correct
#[inline]
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
if let Some(led_node) = &self.led_node {
if let Ok(mut file) = OpenOptions::new().write(true).open(led_node) {
@@ -366,11 +374,10 @@ impl CtrlKbdLed {
.map_err(|err| RogError::Write("write_bytes".into(), err));
}
}
Err(RogError::NotSupported)
Err(RogError::NoAuraNode)
}
/// Write an effect block
#[inline]
/// Write an effect block. This is for per-key
fn _write_effect(&mut self, effect: &[Vec<u8>]) -> Result<(), RogError> {
if self.flip_effect_write {
for row in effect.iter().rev() {
@@ -385,20 +392,6 @@ impl CtrlKbdLed {
Ok(())
}
/// Used to set a builtin mode and save the settings for it
///
/// This needs to be universal so that settings applied by dbus stick
#[inline]
fn set_and_save(&mut self, mode: AuraEffect) -> Result<(), RogError> {
self.config.read();
self.write_mode(&mode)?;
self.config.current_mode = *mode.mode();
self.config.set_builtin(mode);
self.config.write();
Ok(())
}
#[inline]
pub(super) fn toggle_mode(&mut self, reverse: bool) -> Result<(), RogError> {
let current = self.config.current_mode;
if let Some(idx) = self
@@ -424,9 +417,9 @@ impl CtrlKbdLed {
let next = self.supported_modes.standard[idx];
self.config.read();
if let Some(data) = self.config.builtins.get(&next) {
self.write_mode(data)?;
if self.config.builtins.contains_key(&next) {
self.config.current_mode = next;
self.write_current_config_mode()?;
}
self.config.write();
}
@@ -434,11 +427,7 @@ impl CtrlKbdLed {
Ok(())
}
#[inline]
fn write_mode(&self, mode: &AuraEffect) -> Result<(), RogError> {
if !self.supported_modes.standard.contains(mode.mode()) {
return Err(RogError::NotSupported);
}
let bytes: [u8; LED_MSG_LEN] = mode.into();
self.write_bytes(&bytes)?;
self.write_bytes(&LED_SET)?;
@@ -446,4 +435,217 @@ impl CtrlKbdLed {
self.write_bytes(&LED_APPLY)?;
Ok(())
}
fn write_current_config_mode(&mut self) -> Result<(), RogError> {
if self.config.multizone_on {
let mode = self.config.current_mode;
let mut create = false;
// There is no multizone config for this mode so create one here
// using the colours of rainbow if it exists, or first available
// mode, or random
if self.config.multizone.is_none() {
create = true;
} else if let Some(multizones) = self.config.multizone.as_ref() {
if !multizones.contains_key(&mode) {
create = true;
}
}
if create {
info!("No user-set config for zone founding, attempting a default");
self.create_multizone_default()?;
}
if let Some(multizones) = self.config.multizone.as_ref() {
if let Some(set) = multizones.get(&mode) {
for mode in set {
self.write_mode(mode)?;
}
}
}
} else {
let mode = self.config.current_mode;
if let Some(effect) = self.config.builtins.get(&mode) {
self.write_mode(effect)?;
}
}
Ok(())
}
/// Create a default for the `current_mode` if multizone and no config exists.
fn create_multizone_default(&mut self) -> Result<(), RogError> {
let mut default = vec![];
for (i, tmp) in self.supported_modes.multizone.iter().enumerate() {
default.push(AuraEffect {
mode: self.config.current_mode,
zone: *tmp,
colour1: *GRADIENT.get(i).unwrap_or(&GRADIENT[0]),
colour2: *GRADIENT.get(GRADIENT.len() - i).unwrap_or(&GRADIENT[6]),
speed: Speed::Med,
direction: Direction::Left,
})
}
if default.is_empty() {
return Err(RogError::AuraEffectNotSupported);
}
if let Some(multizones) = self.config.multizone.as_mut() {
multizones.insert(self.config.current_mode, default);
} else {
let mut tmp = BTreeMap::new();
tmp.insert(self.config.current_mode, default);
self.config.multizone = Some(tmp);
}
Ok(())
}
}
#[cfg(test)]
mod tests {
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Colour};
use crate::{ctrl_aura::config::AuraConfig, laptops::LaptopLedData};
use super::CtrlKbdLed;
#[test]
// #[ignore = "Must be manually run due to detection stage"]
fn check_set_mode_errors() {
// Checking to ensure set_mode errors when unsupported modes are tried
let config = AuraConfig::default();
let supported_modes = LaptopLedData {
prod_family: "".into(),
board_names: vec![],
standard: vec![AuraModeNum::Static],
multizone: vec![],
per_key: false,
};
let mut controller = CtrlKbdLed {
led_prod: None,
led_node: None,
bright_node: String::new(),
supported_modes,
flip_effect_write: false,
config,
};
let mut effect = AuraEffect::default();
effect.colour1 = Colour(0xff, 0x00, 0xff);
effect.zone = AuraZone::None;
// This error comes from write_bytes because we don't have a keyboard node stored
assert_eq!(
controller
.set_effect(effect.clone())
.unwrap_err()
.to_string(),
"No Aura keyboard node found"
);
effect.mode = AuraModeNum::Laser;
assert_eq!(
controller
.set_effect(effect.clone())
.unwrap_err()
.to_string(),
"Aura effect not supported"
);
effect.mode = AuraModeNum::Static;
effect.zone = AuraZone::Key2;
assert_eq!(
controller
.set_effect(effect.clone())
.unwrap_err()
.to_string(),
"Aura effect not supported"
);
controller.supported_modes.multizone.push(AuraZone::Key2);
assert_eq!(
controller
.set_effect(effect.clone())
.unwrap_err()
.to_string(),
"No Aura keyboard node found"
);
}
#[test]
fn create_multizone_if_no_config() {
// Checking to ensure set_mode errors when unsupported modes are tried
let config = AuraConfig::default();
let supported_modes = LaptopLedData {
prod_family: "".into(),
board_names: vec![],
standard: vec![AuraModeNum::Static],
multizone: vec![],
per_key: false,
};
let mut controller = CtrlKbdLed {
led_prod: None,
led_node: None,
bright_node: String::new(),
supported_modes,
flip_effect_write: false,
config,
};
assert!(controller.config.multizone.is_none());
assert!(controller.create_multizone_default().is_err());
assert!(controller.config.multizone.is_none());
controller.supported_modes.multizone.push(AuraZone::Key1);
controller.supported_modes.multizone.push(AuraZone::Key2);
assert!(controller.create_multizone_default().is_ok());
assert!(controller.config.multizone.is_some());
let m = controller.config.multizone.unwrap();
assert!(m.contains_key(&AuraModeNum::Static));
let e = m.get(&AuraModeNum::Static).unwrap();
assert_eq!(e.len(), 2);
assert_eq!(e[0].zone, AuraZone::Key1);
assert_eq!(e[1].zone, AuraZone::Key2);
}
#[test]
fn next_mode_create_multizone_if_no_config() {
// Checking to ensure set_mode errors when unsupported modes are tried
let config = AuraConfig::default();
let supported_modes = LaptopLedData {
prod_family: "".into(),
board_names: vec![],
standard: vec![AuraModeNum::Static],
multizone: vec![AuraZone::Key1, AuraZone::Key2],
per_key: false,
};
let mut controller = CtrlKbdLed {
led_prod: None,
led_node: None,
bright_node: String::new(),
supported_modes,
flip_effect_write: false,
config,
};
assert!(controller.config.multizone.is_none());
controller.config.multizone_on = true;
// This is called in toggle_mode. It will error here because we have no
// keyboard node in tests.
assert_eq!(
controller
.write_current_config_mode()
.unwrap_err()
.to_string(),
"No Aura keyboard node found"
);
assert!(controller.config.multizone.is_some());
let m = controller.config.multizone.unwrap();
assert!(m.contains_key(&AuraModeNum::Static));
let e = m.get(&AuraModeNum::Static).unwrap();
assert_eq!(e.len(), 2);
assert_eq!(e[0].zone, AuraZone::Key1);
assert_eq!(e[1].zone, AuraZone::Key2);
}
}

View File

@@ -1,6 +1,6 @@
use async_trait::async_trait;
use log::warn;
use rog_aura::{usb::AuraControl, AuraEffect, LedBrightness};
use rog_aura::{usb::AuraPowerDev, AuraEffect, LedBrightness};
use zbus::{dbus_interface, Connection, SignalContext};
use super::controller::CtrlKbdLedZbus;
@@ -8,7 +8,7 @@ use super::controller::CtrlKbdLedZbus;
#[async_trait]
impl crate::ZbusAdd for CtrlKbdLedZbus {
async fn add_to_server(self, server: &mut Connection) {
Self::add_to_server_helper(self, "/org/asuslinux/Led", server).await;
Self::add_to_server_helper(self, "/org/asuslinux/Aura", server).await;
}
}
@@ -42,51 +42,29 @@ impl CtrlKbdLedZbus {
/// SleepBar,
/// ShutdownBar,
/// }
async fn set_leds_enabled(
async fn set_leds_power(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
enabled: Vec<AuraControl>,
) {
options: AuraPowerDev,
enabled: bool,
) -> zbus::fdo::Result<()> {
let mut states = None;
if let Ok(mut ctrl) = self.0.try_lock() {
for s in enabled {
ctrl.config.enabled.insert(s);
for p in options.x1866 {
ctrl.config.enabled.set_0x1866(p, enabled);
}
for p in options.x19b6 {
ctrl.config.enabled.set_0x19b6(p, enabled);
}
ctrl.config.write();
ctrl.set_power_states(&ctrl.config)
.map_err(|err| warn!("{}", err))
.ok();
ctrl.set_power_states(&ctrl.config).map_err(|e| {
warn!("{}", e);
e
})?;
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
states = Some(set);
}
// Need to pull state out like this due to MutexGuard
if let Some(states) = states {
Self::notify_power_states(&ctxt, &states)
.await
.unwrap_or_else(|err| warn!("{}", err));
}
}
async fn set_leds_disabled(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
disabled: Vec<AuraControl>,
) {
let mut states = None;
if let Ok(mut ctrl) = self.0.try_lock() {
for s in disabled {
ctrl.config.enabled.remove(&s);
}
ctrl.config.write();
ctrl.set_power_states(&ctrl.config)
.map_err(|err| warn!("{}", err))
.ok();
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
states = Some(set);
states = Some(AuraPowerDev::from(&ctrl.config.enabled));
}
// Need to pull state out like this due to MutexGuard
if let Some(states) = states {
@@ -94,24 +72,22 @@ impl CtrlKbdLedZbus {
.await
.unwrap_or_else(|err| warn!("{}", err));
}
Ok(())
}
async fn set_led_mode(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
effect: AuraEffect,
) {
) -> zbus::fdo::Result<()> {
let mut led = None;
if let Ok(mut ctrl) = self.0.try_lock() {
match ctrl.do_command(effect) {
Ok(_) => {
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
led = Some(mode.clone());
}
}
Err(err) => {
warn!("{}", err);
}
ctrl.set_effect(effect).map_err(|e| {
warn!("{}", e);
e
})?;
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
led = Some(mode.clone());
}
}
if let Some(led) = led {
@@ -119,13 +95,19 @@ impl CtrlKbdLedZbus {
.await
.unwrap_or_else(|err| warn!("{}", err));
}
Ok(())
}
async fn next_led_mode(&self, #[zbus(signal_context)] ctxt: SignalContext<'_>) {
async fn next_led_mode(
&self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
) -> zbus::fdo::Result<()> {
let mut led = None;
if let Ok(mut ctrl) = self.0.lock() {
ctrl.toggle_mode(false)
.unwrap_or_else(|err| warn!("{}", err));
ctrl.toggle_mode(false).map_err(|e| {
warn!("{}", e);
e
})?;
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
led = Some(mode.clone());
@@ -136,13 +118,19 @@ impl CtrlKbdLedZbus {
.await
.unwrap_or_else(|err| warn!("{}", err));
}
Ok(())
}
async fn prev_led_mode(&self, #[zbus(signal_context)] ctxt: SignalContext<'_>) {
async fn prev_led_mode(
&self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
) -> zbus::fdo::Result<()> {
let mut led = None;
if let Ok(mut ctrl) = self.0.lock() {
ctrl.toggle_mode(true)
.unwrap_or_else(|err| warn!("{}", err));
ctrl.toggle_mode(true).map_err(|e| {
warn!("{}", e);
e
})?;
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
led = Some(mode.clone());
@@ -153,29 +141,37 @@ impl CtrlKbdLedZbus {
.await
.unwrap_or_else(|err| warn!("{}", err));
}
Ok(())
}
async fn next_led_brightness(&self) {
async fn next_led_brightness(&self) -> zbus::fdo::Result<()> {
if let Ok(mut ctrl) = self.0.try_lock() {
ctrl.next_brightness()
.unwrap_or_else(|err| warn!("{}", err));
ctrl.next_brightness().map_err(|e| {
warn!("{}", e);
e
})?;
}
Ok(())
}
async fn prev_led_brightness(&self) {
async fn prev_led_brightness(&self) -> zbus::fdo::Result<()> {
if let Ok(mut ctrl) = self.0.try_lock() {
ctrl.prev_brightness()
.unwrap_or_else(|err| warn!("{}", err));
ctrl.prev_brightness().map_err(|e| {
warn!("{}", e);
e
})?;
}
Ok(())
}
#[dbus_interface(property)]
async fn leds_enabled(&self) -> Vec<u8> {
if let Ok(ctrl) = self.0.try_lock() {
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
return AuraControl::to_bytes(&set).to_vec();
// As property doesn't work for AuraPowerDev (complexity of serialization?)
// #[dbus_interface(property)]
async fn leds_power(&self) -> AuraPowerDev {
loop {
if let Ok(ctrl) = self.0.try_lock() {
return AuraPowerDev::from(&ctrl.config.enabled);
}
}
vec![0, 0]
}
/// Return the current mode data
@@ -220,6 +216,6 @@ impl CtrlKbdLedZbus {
#[dbus_interface(signal)]
async fn notify_power_states(
signal_ctxt: &SignalContext<'_>,
data: &[AuraControl],
data: &AuraPowerDev,
) -> zbus::Result<()>;
}

View File

@@ -19,6 +19,9 @@ static ASUS_SWITCH_GRAPHIC_MODE: &str =
"/sys/firmware/efi/efivars/AsusSwitchGraphicMode-607005d5-3f75-4b2e-98f0-85ba66797a3e";
static ASUS_POST_LOGO_SOUND: &str =
"/sys/firmware/efi/efivars/AsusPostLogoSound-607005d5-3f75-4b2e-98f0-85ba66797a3e";
static ASUS_PANEL_OD_PATH: &str = "/sys/devices/platform/asus-nb-wmi/panel_od";
static ASUS_DGPU_DISABLE_PATH: &str = "/sys/devices/platform/asus-nb-wmi/dgpu_disable";
static ASUS_EGPU_ENABLE_PATH: &str = "/sys/devices/platform/asus-nb-wmi/egpu_enable";
pub struct CtrlRogBios {
_config: Arc<Mutex<Config>>,
@@ -29,8 +32,11 @@ impl GetSupported for CtrlRogBios {
fn get_supported() -> Self::A {
RogBiosSupportedFunctions {
post_sound_toggle: Path::new(ASUS_POST_LOGO_SOUND).exists(),
dedicated_gfx_toggle: Path::new(ASUS_SWITCH_GRAPHIC_MODE).exists(),
post_sound: Path::new(ASUS_POST_LOGO_SOUND).exists(),
dedicated_gfx: Path::new(ASUS_SWITCH_GRAPHIC_MODE).exists(),
panel_overdrive: Path::new(ASUS_PANEL_OD_PATH).exists(),
dgpu_disable: Path::new(ASUS_DGPU_DISABLE_PATH).exists(),
egpu_enable: Path::new(ASUS_EGPU_ENABLE_PATH).exists(),
}
}
}
@@ -94,6 +100,52 @@ impl CtrlRogBios {
#[dbus_interface(signal)]
async fn notify_post_boot_sound(ctxt: &SignalContext<'_>, on: bool) -> zbus::Result<()> {}
async fn set_panel_overdrive(
&mut self,
#[zbus(signal_context)] ctxt: SignalContext<'_>,
overdrive: bool,
) {
if self
.set_panel_od(overdrive)
.map_err(|err| {
warn!("CtrlRogBios: set_panel_overdrive {}", err);
err
})
.is_ok()
{
Self::notify_panel_overdrive(&ctxt, overdrive).await.ok();
}
}
fn panel_overdrive(&self) -> i8 {
let path = ASUS_PANEL_OD_PATH;
if let Ok(mut file) = OpenOptions::new().read(true).open(path).map_err(|err| {
warn!("CtrlRogBios: panel_overdrive {}", err);
err
}) {
let mut buf = Vec::new();
file.read_to_end(&mut buf)
.map_err(|err| {
warn!("CtrlRogBios: set_panel_overdrive {}", err);
err
})
.ok();
if buf.len() >= 1 {
let tmp = String::from_utf8_lossy(&buf[0..1]);
return tmp.parse::<i8>().unwrap_or(-1);
}
}
-1
}
#[dbus_interface(signal)]
async fn notify_panel_overdrive(
signal_ctxt: &SignalContext<'_>,
overdrive: bool,
) -> zbus::Result<()> {
}
}
#[async_trait]
@@ -305,4 +357,43 @@ impl CtrlRogBios {
}
Ok(())
}
fn set_panel_od(&mut self, overdrive: bool) -> Result<(), RogError> {
let path = ASUS_PANEL_OD_PATH;
let mut file = OpenOptions::new().write(true).open(path).map_err(|err| {
warn!("CtrlRogBios: set_panel_overdrive {}", err);
err
})?;
let s = if overdrive { '1' } else { '0' };
file.write(&[s as u8]).map_err(|err| {
warn!("CtrlRogBios: set_panel_overdrive {}", err);
err
})?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::CtrlRogBios;
use crate::config::Config;
use std::sync::{Arc, Mutex};
#[test]
#[ignore = "Must be manually tested"]
fn set_multizone_4key_config() {
let config = Config::default();
let controller = CtrlRogBios {
_config: Arc::new(Mutex::new(config)),
};
let res = controller.panel_overdrive();
assert_eq!(res, 1);
// controller.set_panel_od(false).unwrap();
// let res = controller.panel_overdrive();
// assert_eq!(res, 0);
}
}

View File

@@ -1,3 +1,4 @@
use rog_anime::error::AnimeError;
use rog_profiles::error::ProfileError;
use std::convert::From;
use std::fmt;
@@ -23,6 +24,10 @@ pub enum RogError {
Io(std::io::Error),
Zbus(zbus::Error),
ChargeLimit(u8),
AuraEffectNotSupported,
NoAuraKeyboard,
NoAuraNode,
Anime(AnimeError),
}
impl fmt::Display for RogError {
@@ -48,6 +53,10 @@ impl fmt::Display for RogError {
RogError::Io(detail) => write!(f, "std::io error: {}", detail),
RogError::Zbus(detail) => write!(f, "Zbus error: {}", detail),
RogError::ChargeLimit(value) => write!(f, "Invalid charging limit, not in range 20-100%: {}", value),
RogError::AuraEffectNotSupported => write!(f, "Aura effect not supported"),
RogError::NoAuraKeyboard => write!(f, "No supported Aura keyboard"),
RogError::NoAuraNode => write!(f, "No Aura keyboard node found"),
RogError::Anime(deets) => write!(f, "AniMe Matrix error: {}", deets),
}
}
}
@@ -60,6 +69,12 @@ impl From<ProfileError> for RogError {
}
}
impl From<AnimeError> for RogError {
fn from(err: AnimeError) -> Self {
RogError::Anime(err)
}
}
impl From<zbus::Error> for RogError {
fn from(err: zbus::Error) -> Self {
RogError::Zbus(err)

View File

@@ -1,6 +1,6 @@
[package]
name = "rog_anime"
version = "1.3.4"
version = "1.3.5"
license = "MPL-2.0"
readme = "README.md"
authors = ["Luke <luke@ljones.dev>"]
@@ -14,7 +14,7 @@ exclude = ["data"]
[features]
default = ["dbus", "detect"]
dbus = ["zvariant"]
dbus = ["zvariant", "zbus"]
detect = ["udev", "sysfs-class"]
[dependencies]
@@ -29,6 +29,7 @@ serde_derive = "^1.0"
glam = { version = "0.20.5", features = ["serde"] }
zvariant = { version = "^3.0", optional = true }
zbus = { version = "^2.2", optional = true }
udev = { version = "^0.6", optional = true }
sysfs-class = { version = "^0.1", optional = true }

View File

@@ -1,4 +1,5 @@
use std::{
convert::TryFrom,
thread::sleep,
time::{Duration, Instant},
};
@@ -8,7 +9,10 @@ use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "dbus")]
use zvariant::Type;
use crate::{error::AnimeError, AnimTime, AnimeGif};
use crate::{
error::{AnimeError, Result},
AnimTime, AnimeGif,
};
/// The first 7 bytes of a USB packet are accounted for by `USB_PREFIX1` and `USB_PREFIX2`
const BLOCK_START: usize = 7;
@@ -102,20 +106,25 @@ impl AnimeDataBuffer {
/// # Panics
/// Will panic if the vector length is not `ANIME_DATA_LEN`
#[inline]
pub fn from_vec(anime: AnimeType, data: Vec<u8>) -> Self {
assert_eq!(data.len(), anime.data_length());
pub fn from_vec(anime: AnimeType, data: Vec<u8>) -> Result<Self> {
if data.len() != anime.data_length() {
return Err(AnimeError::DataBufferLength);
}
Self { data, anime }
Ok(Self { data, anime })
}
}
/// The two packets to be written to USB
pub type AnimePacketType = Vec<[u8; 640]>;
impl From<AnimeDataBuffer> for AnimePacketType {
#[inline]
fn from(anime: AnimeDataBuffer) -> Self {
assert_eq!(anime.data.len(), anime.anime.data_length());
impl TryFrom<AnimeDataBuffer> for AnimePacketType {
type Error = AnimeError;
fn try_from(anime: AnimeDataBuffer) -> std::result::Result<Self, Self::Error> {
if anime.data.len() != anime.anime.data_length() {
return Err(AnimeError::DataBufferLength);
}
let mut buffers = match anime.anime {
AnimeType::GA401 => vec![[0; 640]; 2],
@@ -131,7 +140,7 @@ impl From<AnimeDataBuffer> for AnimePacketType {
if matches!(anime.anime, AnimeType::GA402) {
buffers[2][..7].copy_from_slice(&USB_PREFIX3);
}
buffers
Ok(buffers)
}
}
@@ -140,8 +149,8 @@ impl From<AnimeDataBuffer> for AnimePacketType {
/// If `callback` is `Ok(true)` then `run_animation` will exit the animation loop early.
pub fn run_animation(
frames: &AnimeGif,
callback: &dyn Fn(AnimeDataBuffer) -> Result<bool, AnimeError>,
) -> Result<(), AnimeError> {
callback: &dyn Fn(AnimeDataBuffer) -> Result<bool>,
) -> Result<()> {
let mut count = 0;
let start = Instant::now();

View File

@@ -1,6 +1,10 @@
use std::{path::Path, time::Duration};
use crate::{data::AnimeDataBuffer, error::AnimeError, AnimeType};
use crate::{
data::AnimeDataBuffer,
error::{AnimeError, Result},
AnimeType,
};
/// Mostly intended to be used with ASUS gifs, but can be used for other purposes (like images)
#[derive(Debug, Clone)]
@@ -40,7 +44,7 @@ impl AnimeDiagonal {
duration: Option<Duration>,
bright: f32,
anime_type: AnimeType,
) -> Result<Self, AnimeError> {
) -> Result<Self> {
let data = std::fs::read(path)?;
let data = std::io::Cursor::new(data);
let decoder = png_pong::Decoder::new(data)?.into_steps();
@@ -125,7 +129,7 @@ impl AnimeDiagonal {
/// Convert to a data buffer that can be sent over dbus
#[inline]
pub fn into_data_buffer(&self, anime_type: AnimeType) -> AnimeDataBuffer {
pub fn into_data_buffer(&self, anime_type: AnimeType) -> Result<AnimeDataBuffer> {
match anime_type {
AnimeType::GA401 => self.into_ga401_packets(),
AnimeType::GA402 => self.into_ga402_packets(),
@@ -134,7 +138,7 @@ impl AnimeDiagonal {
/// Do conversion from the nested Vec in AnimeMatrix to the two required
/// packets suitable for sending over USB
fn into_ga401_packets(&self) -> AnimeDataBuffer {
fn into_ga401_packets(&self) -> Result<AnimeDataBuffer> {
let mut buf = vec![0u8; AnimeType::GA401.data_length()];
buf[1..=32].copy_from_slice(&self.get_row(0, 3, 32));
@@ -196,7 +200,7 @@ impl AnimeDiagonal {
AnimeDataBuffer::from_vec(crate::AnimeType::GA401, buf)
}
fn into_ga402_packets(&self) -> AnimeDataBuffer {
fn into_ga402_packets(&self) -> Result<AnimeDataBuffer> {
let mut buf = vec![0u8; AnimeType::GA402.data_length()];
let mut start_index: usize = 0;
@@ -282,7 +286,7 @@ impl AnimeDiagonal {
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use std::{convert::TryFrom, path::PathBuf};
use crate::{AnimeDiagonal, AnimePacketType, AnimeType};
@@ -374,8 +378,8 @@ mod tests {
path.push("test/ga401-diagonal.png");
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA401).unwrap();
let data = matrix.into_data_buffer(crate::AnimeType::GA401);
let pkt = AnimePacketType::from(data);
let data = matrix.into_data_buffer(crate::AnimeType::GA401).unwrap();
let pkt = AnimePacketType::try_from(data).unwrap();
assert_eq!(pkt[0], pkt0_check);
assert_eq!(pkt[1], pkt1_check);
@@ -509,8 +513,8 @@ mod tests {
path.push("test/ga402-diagonal.png");
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA402).unwrap();
let data = matrix.into_data_buffer(crate::AnimeType::GA402);
let pkt = AnimePacketType::from(data);
let data = matrix.into_data_buffer(crate::AnimeType::GA402).unwrap();
let pkt = AnimePacketType::try_from(data).unwrap();
assert_eq!(pkt[0], pkt0_check);
assert_eq!(pkt[1], pkt1_check);
@@ -654,8 +658,8 @@ mod tests {
path.push("test/ga402-diagonal-fullbright.png");
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA402).unwrap();
let data = matrix.into_data_buffer(crate::AnimeType::GA402);
let pkt = AnimePacketType::from(data);
let data = matrix.into_data_buffer(crate::AnimeType::GA402).unwrap();
let pkt = AnimePacketType::try_from(data).unwrap();
assert_eq!(pkt[0], pkt0_check);
assert_eq!(pkt[1], pkt1_check);

View File

@@ -3,6 +3,8 @@ use png_pong::decode::Error as PngError;
use std::error::Error;
use std::fmt;
pub type Result<T> = std::result::Result<T, AnimeError>;
#[derive(Debug)]
pub enum AnimeError {
NoFrames,
@@ -17,6 +19,9 @@ pub enum AnimeError {
NoDevice,
UnsupportedDevice,
InvalidBrightness(f32),
DataBufferLength,
PixelGifWidth(usize),
PixelGifHeight(usize),
}
impl fmt::Display for AnimeError {
@@ -36,12 +41,23 @@ impl fmt::Display for AnimeError {
AnimeError::Dbus(detail) => write!(f, "{}", detail),
AnimeError::Udev(deets, error) => write!(f, "udev {}: {}", deets, error),
AnimeError::NoDevice => write!(f, "No AniMe Matrix device found"),
AnimeError::DataBufferLength => write!(
f,
"The data buffer was incorrect length for generating USB packets"
),
AnimeError::UnsupportedDevice => write!(f, "Unsupported AniMe Matrix device found"),
AnimeError::InvalidBrightness(bright) => write!(
f,
"Image brightness must be between 0.0 and 1.0 (inclusive), was {}",
bright
),
AnimeError::PixelGifWidth(n) => {
write!(f, "The gif used for pixel-perfect gif is is wider than {n}")
}
AnimeError::PixelGifHeight(n) => write!(
f,
"The gif used for pixel-perfect gif is is taller than {n}"
),
}
}
}
@@ -68,3 +84,10 @@ impl From<DecodingError> for AnimeError {
AnimeError::Gif(err)
}
}
impl From<AnimeError> for zbus::fdo::Error {
#[inline]
fn from(err: AnimeError) -> Self {
zbus::fdo::Error::Failed(format!("{}", err))
}
}

View File

@@ -1,8 +1,10 @@
use glam::Vec2;
use serde_derive::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::{fs::File, path::Path, time::Duration};
use crate::{error::AnimeError, AnimeDataBuffer, AnimeDiagonal, AnimeImage, AnimeType, Pixel};
use crate::error::AnimeError;
use crate::{error::Result, AnimeDataBuffer, AnimeDiagonal, AnimeImage, AnimeType, Pixel};
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct AnimeFrame {
@@ -93,7 +95,7 @@ impl AnimeGif {
duration: AnimTime,
brightness: f32,
anime_type: AnimeType,
) -> Result<Self, AnimeError> {
) -> Result<Self> {
let mut matrix = AnimeDiagonal::new(anime_type, None);
let mut decoder = gif::DecodeOptions::new();
@@ -116,13 +118,22 @@ impl AnimeGif {
// should be t but not in some gifs? What, ASUS, what?
continue;
}
matrix.get_mut()[y + frame.top as usize][x + frame.left as usize] =
(px[0] as f32 * brightness) as u8;
let tmp = matrix.get_mut();
let y = y + frame.top as usize;
if y >= tmp.len() {
return Err(AnimeError::PixelGifHeight(tmp.len()));
}
let x = x + frame.left as usize;
if x >= tmp[y].len() {
return Err(AnimeError::PixelGifWidth(tmp[y].len()));
}
matrix.get_mut()[y][x] = (px[0] as f32 * brightness) as u8;
}
}
frames.push(AnimeFrame {
data: matrix.into_data_buffer(anime_type),
data: matrix.into_data_buffer(anime_type)?,
delay: Duration::from_millis(wait as u64),
});
}
@@ -136,7 +147,7 @@ impl AnimeGif {
anime_type: AnimeType,
duration: AnimTime,
brightness: f32,
) -> Result<Self, AnimeError> {
) -> Result<Self> {
let image = AnimeDiagonal::from_png(file_name, None, brightness, anime_type)?;
let mut total = Duration::from_millis(1000);
@@ -150,7 +161,7 @@ impl AnimeGif {
let frame_count = total.as_millis() / 30;
let single = AnimeFrame {
data: image.into_data_buffer(anime_type),
data: image.into_data_buffer(anime_type)?,
delay: Duration::from_millis(30),
};
let frames = vec![single; frame_count as usize];
@@ -169,7 +180,7 @@ impl AnimeGif {
duration: AnimTime,
brightness: f32,
anime_type: AnimeType,
) -> Result<Self, AnimeError> {
) -> Result<Self> {
let mut frames = Vec::new();
let mut decoder = gif::DecodeOptions::new();
@@ -225,7 +236,7 @@ impl AnimeGif {
image.update();
frames.push(AnimeFrame {
data: <AnimeDataBuffer>::from(&image),
data: <AnimeDataBuffer>::try_from(&image)?,
delay: Duration::from_millis(wait as u64),
});
}
@@ -244,7 +255,7 @@ impl AnimeGif {
duration: AnimTime,
brightness: f32,
anime_type: AnimeType,
) -> Result<Self, AnimeError> {
) -> Result<Self> {
let image =
AnimeImage::from_png(file_name, scale, angle, translation, brightness, anime_type)?;
@@ -259,7 +270,7 @@ impl AnimeGif {
let frame_count = total.as_millis() / 30;
let single = AnimeFrame {
data: <AnimeDataBuffer>::from(&image),
data: <AnimeDataBuffer>::try_from(&image)?,
delay: Duration::from_millis(30),
};
let frames = vec![single; frame_count as usize];

View File

@@ -1,4 +1,7 @@
use std::convert::TryFrom;
use crate::data::AnimeDataBuffer;
use crate::error::{AnimeError, Result};
use crate::{AnimeImage, AnimeType};
// TODO: Adjust these sizes as WIDTH_GA401 WIDTH_GA402
@@ -87,11 +90,12 @@ impl AnimeGrid {
// }
}
impl From<AnimeGrid> for AnimeDataBuffer {
impl TryFrom<AnimeGrid> for AnimeDataBuffer {
type Error = AnimeError;
/// Do conversion from the nested Vec in AniMeMatrix to the two required
/// packets suitable for sending over USB
#[inline]
fn from(anime: AnimeGrid) -> Self {
fn try_from(anime: AnimeGrid) -> Result<Self> {
let mut buf = vec![0u8; anime.anime_type.data_length()];
for (idx, pos) in AnimeImage::generate_image_positioning(anime.anime_type)
@@ -123,7 +127,7 @@ mod tests {
}
}
let matrix = <AnimeDataBuffer>::from(matrix);
let matrix = <AnimeDataBuffer>::try_from(matrix).unwrap();
let data_cmp = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

View File

@@ -1,9 +1,13 @@
use std::path::Path;
use std::{convert::TryFrom, path::Path};
pub use glam::Vec2;
use glam::{Mat3, Vec3};
use crate::{data::AnimeDataBuffer, error::AnimeError, AnimeType};
use crate::{
data::AnimeDataBuffer,
error::{AnimeError, Result},
AnimeType,
};
/// A single greyscale + alpha pixel in the image
#[derive(Copy, Clone, Debug)]
@@ -83,7 +87,7 @@ impl AnimeImage {
pixels: Vec<Pixel>,
width: u32,
anime_type: AnimeType,
) -> Result<Self, AnimeError> {
) -> Result<Self> {
if bright < 0.0 || bright > 1.0 {
return Err(AnimeError::InvalidBrightness(bright));
}
@@ -388,7 +392,7 @@ impl AnimeImage {
translation: Vec2,
bright: f32,
anime_type: AnimeType,
) -> Result<Self, AnimeError> {
) -> Result<Self> {
let data = std::fs::read(path)?;
let data = std::io::Cursor::new(data);
let decoder = png_pong::Decoder::new(data)?.into_steps();
@@ -484,11 +488,12 @@ impl AnimeImage {
}
}
impl From<&AnimeImage> for AnimeDataBuffer {
impl TryFrom<&AnimeImage> for AnimeDataBuffer {
type Error = AnimeError;
/// Do conversion from the nested Vec in AnimeDataBuffer to the two required
/// packets suitable for sending over USB
#[inline]
fn from(leds: &AnimeImage) -> Self {
fn try_from(leds: &AnimeImage) -> Result<Self> {
let mut l: Vec<u8> = leds
.led_pos
.iter()
@@ -506,7 +511,7 @@ impl From<&AnimeImage> for AnimeDataBuffer {
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use std::{convert::TryFrom, path::PathBuf};
use crate::{image::*, AnimTime, AnimeGif, AnimePacketType};
@@ -731,10 +736,11 @@ mod tests {
vec![Pixel::default(); 1000],
100,
AnimeType::GA402,
);
)
.unwrap();
matrix._edge_outline();
let data = AnimeDataBuffer::from(&matrix);
let pkt = AnimePacketType::from(data);
let data = AnimeDataBuffer::try_from(&matrix).unwrap();
let pkt = AnimePacketType::try_from(data).unwrap();
assert_eq!(pkt[0], pkt0_check);
assert_eq!(pkt[1], pkt1_check);
@@ -758,6 +764,6 @@ mod tests {
)
.unwrap();
matrix.frames()[0].frame();
let _pkt = AnimePacketType::from(matrix.frames()[0].frame().clone());
let _pkt = AnimePacketType::try_from(matrix.frames()[0].frame().clone()).unwrap();
}
}

View File

@@ -1,10 +1,10 @@
use std::{path::PathBuf, time::Duration};
use glam::Vec2;
use serde_derive::{Deserialize, Serialize};
use std::convert::TryFrom;
use std::{path::PathBuf, time::Duration};
use crate::{
error::AnimeError, AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType,
error::Result, AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType,
};
/// All the possible AniMe actions that can be used. This enum is intended to be
@@ -65,10 +65,7 @@ pub enum ActionData {
}
impl ActionData {
pub fn from_anime_action(
anime_type: AnimeType,
action: &ActionLoader,
) -> Result<ActionData, AnimeError> {
pub fn from_anime_action(anime_type: AnimeType, action: &ActionLoader) -> Result<ActionData> {
let a = match action {
ActionLoader::AsusAnimation {
file,
@@ -87,7 +84,7 @@ impl ActionData {
} => match time {
AnimTime::Infinite => {
let image = AnimeDiagonal::from_png(file, None, *brightness, anime_type)?;
let data = image.into_data_buffer(anime_type);
let data = image.into_data_buffer(anime_type)?;
ActionData::Image(Box::new(data))
}
_ => ActionData::Animation(AnimeGif::from_diagonal_png(
@@ -147,7 +144,7 @@ impl ActionData {
*brightness,
anime_type,
)?;
let data = <AnimeDataBuffer>::from(&image);
let data = <AnimeDataBuffer>::try_from(&image)?;
ActionData::Image(Box::new(data))
}
_ => ActionData::Animation(AnimeGif::from_png(
@@ -180,7 +177,7 @@ impl Sequences {
/// Use a base `AnimeAction` to generate the precomputed data and insert in to
/// the run buffer
#[inline]
pub fn insert(&mut self, index: usize, action: &ActionLoader) -> Result<(), AnimeError> {
pub fn insert(&mut self, index: usize, action: &ActionLoader) -> Result<()> {
self.0
.insert(index, ActionData::from_anime_action(self.1, action)?);
Ok(())

View File

@@ -26,7 +26,9 @@ pub fn get_anime_type() -> Result<AnimeType, AnimeError> {
let dmi = sysfs_class::DmiId::default();
let board_name = dmi.board_name()?;
if board_name.contains("GA401Q") {
if board_name.contains("GA401I") {
return Ok(AnimeType::GA401);
} else if board_name.contains("GA401Q") {
return Ok(AnimeType::GA401);
} else if board_name.contains("GA402R") {
return Ok(AnimeType::GA402);

View File

@@ -1,6 +1,6 @@
[package]
name = "rog_aura"
version = "1.1.1"
version = "1.2.0"
license = "MPL-2.0"
readme = "README.md"
authors = ["Luke <luke@ljones.dev>"]

View File

@@ -16,3 +16,12 @@ pub mod error;
pub const LED_MSG_LEN: usize = 17;
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
pub const RED: Colour = Colour(0xff, 0x00, 0x00);
pub const GREEN: Colour = Colour(0x00, 0xff, 0x00);
pub const BLUE: Colour = Colour(0x00, 0x00, 0xff);
pub const VIOLET: Colour = Colour(0x9B, 0x26, 0xB6);
pub const TEAL: Colour = Colour(0x00, 0x7C, 0x80);
pub const YELLOW: Colour = Colour(0xff, 0xef, 0x00);
pub const ORANGE: Colour = Colour(0xff, 0xa4, 0x00);
pub const GRADIENT: [Colour; 7] = [RED, VIOLET, BLUE, TEAL, GREEN, YELLOW, ORANGE];

View File

@@ -20,37 +20,110 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
]
}
/// Enable/disable LED control in various states such as
/// when the device is awake, suspended, shutting down or
/// booting.
///
/// ```text
// byte 4 in the USB packet is for keyboard + logo power states
// default is on, `ff`
// Keyboard and logo use the full range of bits (almost)
// | n1 | n2 | hex | action | bit |
// |------|------|-----|-----------------------|-------|
// | 0000 | 0000 | 00 | all off | |
// | 0000 | 0001 | 01 | logo boot | bit 1 |
// | 0000 | 0010 | 02 | keyboard boot | bit 2 |
// | 0000 | 0100 | 04 | logo awake | bit 3 |
// | 0000 | 1000 | 08 | keyboard awake | bit 4 |
// | 0001 | 0000 | 10 | logo sleep off | bit 5 |
// | 0010 | 0000 | 20 | keyboard sleep | bit 6 |
// | 0100 | 0000 | 40 | logo shutdown off | bit 7 |
// | 1000 | 0000 | 80 | keyboard shutdown off | bit 8 |
/// This struct is intended as a helper to pass args to generic dbus interface
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AuraPowerDev {
pub x1866: Vec<AuraDev1866>,
pub x19b6: Vec<AuraDev19b6>,
}
// byte 5 = lightbar
// | 1 | 2 | hex | action | bit |
// |------|------|-----|----------------------|-------|
// | 0000 | 0010 | 02 | lightbar off boot | bit 2 |
// | 0000 | 0100 | 04 | lightbar on | bit 3 |
// | 0000 | 1000 | 08 | lightbar off sleep | bit 4 |
// | 0001 | 0000 | 10 | lightbar shtdn off | bit 5 |
/// # Bits for older 0x1866 keyboard model
///
/// Keybord and Lightbar require Awake, Boot and Sleep apply to both
/// Keybord and Lightbar regardless of if either are enabled (or Awake is enabled)
///
/// | Byte 1 | Byte 2 | Byte 3 | function | hex |
/// |------------|------------|------------|----------|----------|
/// | 0000, 0000 | 0000, 0000 | 0000, 0010 | Awake | 00,00,02 |
/// | 0000, 1000 | 0000, 0000 | 0000, 0000 | Keyboard | 08,00,00 |
/// | 0000, 0100 | 0000, 0101 | 0000, 0000 | Lightbar | 04,05,00 |
/// | 1100, 0011 | 0001, 0010 | 0000, 1001 | Boot/Sht | c3,12,09 |
/// | 0011, 0000 | 0000, 1000 | 0000, 0100 | Sleep | 30,08,04 |
/// | 1111, 1111 | 0001, 1111 | 0000, 1111 | all on | |
///
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
#[repr(u32)]
pub enum AuraDev1866 {
Awake = 0x000002,
Keyboard = 0x080000,
Lightbar = 0x040500,
Boot = 0xc31209,
Sleep = 0x300804,
}
impl From<AuraDev1866> for u32 {
fn from(a: AuraDev1866) -> Self {
a as u32
}
}
impl AuraDev1866 {
pub fn to_bytes(control: &[Self]) -> [u8; 3] {
let mut a: u32 = 0;
control.iter().for_each(|n| {
a |= *n as u32;
});
[
((a & 0xff0000) >> 16) as u8,
((a & 0xff00) >> 8) as u8,
(a & 0xff) as u8,
]
}
pub const fn dev_id() -> &'static str {
"0x1866"
}
}
impl BitOr<AuraDev1866> for AuraDev1866 {
type Output = u32;
fn bitor(self, rhs: AuraDev1866) -> Self::Output {
return self as u32 | rhs as u32;
}
}
impl BitAnd<AuraDev1866> for AuraDev1866 {
type Output = u32;
fn bitand(self, rhs: AuraDev1866) -> Self::Output {
return self as u32 & rhs as u32;
}
}
/// # Bits for 0x19b6 keyboard model
///
/// byte 4 in the USB packet is for keyboard + logo power states
/// default is on, `ff`
/// Keyboard and logo use the full range of bits (almost)
///
/// | n1 | n2 | hex | action | bit |
/// |------|------|-----|-----------------------|-------|
/// | 0000 | 0000 | 00 | all off | |
/// | 0000 | 0001 | 01 | logo boot | bit 1 |
/// | 0000 | 0010 | 02 | keyboard boot | bit 2 |
/// | 0000 | 0100 | 04 | logo awake | bit 3 |
/// | 0000 | 1000 | 08 | keyboard awake | bit 4 |
/// | 0001 | 0000 | 10 | logo sleep off | bit 5 |
/// | 0010 | 0000 | 20 | keyboard sleep | bit 6 |
/// | 0100 | 0000 | 40 | logo shutdown off | bit 7 |
/// | 1000 | 0000 | 80 | keyboard shutdown off | bit 8 |
///
/// byte 5 = lightbar
///
/// | 1 | 2 | hex | action | bit |
/// |------|------|-----|----------------------|-------|
/// | 0000 | 0010 | 02 | lightbar off boot | bit 2 |
/// | 0000 | 0100 | 04 | lightbar on | bit 3 |
/// | 0000 | 1000 | 08 | lightbar off sleep | bit 4 |
/// | 0001 | 0000 | 10 | lightbar shtdn off | bit 5 |
///
#[cfg_attr(feature = "dbus", derive(Type))]
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
#[repr(u16)]
pub enum AuraControl {
pub enum AuraDev19b6 {
BootLogo = 1,
BootKeyb = 1 << 1,
AwakeLogo = 1 << 2,
@@ -65,133 +138,174 @@ pub enum AuraControl {
ShutdownBar = 1 << 7 + 5,
}
impl From<AuraControl> for u16 {
fn from(a: AuraControl) -> Self {
impl From<AuraDev19b6> for u16 {
fn from(a: AuraDev19b6) -> Self {
a as u16
}
}
impl AuraControl {
pub fn to_bytes(control: &[Self]) -> [u8; 2] {
impl AuraDev19b6 {
pub fn to_bytes(control: &[Self]) -> [u8; 3] {
let mut a: u16 = 0;
control.iter().for_each(|n| {
a |= *n as u16;
});
[(a & 0xff) as u8, ((a & 0xff00) >> 8) as u8]
[(a & 0xff) as u8, ((a & 0xff00) >> 8) as u8, 0x00]
}
pub const fn dev_id() -> &'static str {
"0x196b"
}
}
impl BitOr<AuraControl> for AuraControl {
impl BitOr<AuraDev19b6> for AuraDev19b6 {
type Output = u16;
fn bitor(self, rhs: AuraControl) -> Self::Output {
fn bitor(self, rhs: AuraDev19b6) -> Self::Output {
return self as u16 | rhs as u16;
}
}
impl BitAnd<AuraControl> for AuraControl {
impl BitAnd<AuraDev19b6> for AuraDev19b6 {
type Output = u16;
fn bitand(self, rhs: AuraControl) -> Self::Output {
fn bitand(self, rhs: AuraDev19b6) -> Self::Output {
return self as u16 & rhs as u16;
}
}
#[cfg(test)]
mod tests {
use crate::usb::AuraControl;
use crate::usb::AuraDev19b6;
use super::AuraDev1866;
#[test]
fn check_led_control_bytes() {
fn check_0x1866_control_bytes() {
let bytes = [AuraDev1866::Keyboard, AuraDev1866::Awake];
let bytes = AuraDev1866::to_bytes(&bytes);
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
assert_eq!(bytes, [0x08, 0x00, 0x02]);
let bytes = [AuraDev1866::Lightbar, AuraDev1866::Awake];
let bytes = AuraDev1866::to_bytes(&bytes);
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
assert_eq!(bytes, [0x04, 0x05, 0x02]);
let bytes = [AuraDev1866::Sleep];
let bytes = AuraDev1866::to_bytes(&bytes);
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
assert_eq!(bytes, [0x30, 0x08, 0x04]);
let bytes = [AuraDev1866::Boot];
let bytes = AuraDev1866::to_bytes(&bytes);
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
assert_eq!(bytes, [0xc3, 0x12, 0x09]);
let bytes = [
AuraDev1866::Keyboard,
AuraDev1866::Lightbar,
AuraDev1866::Awake,
AuraDev1866::Sleep,
AuraDev1866::Boot,
];
let bytes = AuraDev1866::to_bytes(&bytes);
println!("{:08b}, {:08b}, {:08b}", bytes[0], bytes[1], bytes[2]);
assert_eq!(bytes, [0xff, 0x1f, 0x000f]);
}
#[test]
fn check_0x19b6_control_bytes() {
// All on
let byte1 = [
AuraControl::BootLogo,
AuraControl::BootKeyb,
AuraControl::SleepLogo,
AuraControl::SleepKeyb,
AuraControl::AwakeLogo,
AuraControl::AwakeKeyb,
AuraControl::ShutdownLogo,
AuraControl::ShutdownKeyb,
AuraDev19b6::BootLogo,
AuraDev19b6::BootKeyb,
AuraDev19b6::SleepLogo,
AuraDev19b6::SleepKeyb,
AuraDev19b6::AwakeLogo,
AuraDev19b6::AwakeKeyb,
AuraDev19b6::ShutdownLogo,
AuraDev19b6::ShutdownKeyb,
];
let bytes = AuraControl::to_bytes(&byte1);
let bytes = AuraDev19b6::to_bytes(&byte1);
println!("{:08b}", bytes[0]);
assert_eq!(bytes[0], 0xff);
//
let byte1 = [
// AuraControl::BootLogo,
AuraControl::BootKeyb,
AuraControl::SleepLogo,
AuraControl::SleepKeyb,
AuraControl::AwakeLogo,
AuraControl::AwakeKeyb,
AuraControl::ShutdownLogo,
AuraControl::ShutdownKeyb,
AuraDev19b6::BootKeyb,
AuraDev19b6::SleepLogo,
AuraDev19b6::SleepKeyb,
AuraDev19b6::AwakeLogo,
AuraDev19b6::AwakeKeyb,
AuraDev19b6::ShutdownLogo,
AuraDev19b6::ShutdownKeyb,
];
let bytes = AuraControl::to_bytes(&byte1);
let bytes = AuraDev19b6::to_bytes(&byte1);
println!("{:08b}", bytes[0]);
assert_eq!(bytes[0], 0xfe);
let byte1 = [
AuraControl::BootLogo,
AuraDev19b6::BootLogo,
// AuraControl::BootKeyb,
AuraControl::SleepLogo,
AuraControl::SleepKeyb,
AuraControl::AwakeLogo,
AuraControl::AwakeKeyb,
AuraControl::ShutdownLogo,
AuraControl::ShutdownKeyb,
AuraDev19b6::SleepLogo,
AuraDev19b6::SleepKeyb,
AuraDev19b6::AwakeLogo,
AuraDev19b6::AwakeKeyb,
AuraDev19b6::ShutdownLogo,
AuraDev19b6::ShutdownKeyb,
];
let bytes = AuraControl::to_bytes(&byte1);
let bytes = AuraDev19b6::to_bytes(&byte1);
println!("{:08b}", bytes[0]);
assert_eq!(bytes[0], 0xfd);
let byte1 = [
AuraControl::BootLogo,
AuraControl::BootKeyb,
AuraDev19b6::BootLogo,
AuraDev19b6::BootKeyb,
// AuraControl::SleepLogo,
AuraControl::SleepKeyb,
AuraControl::AwakeLogo,
AuraControl::AwakeKeyb,
AuraControl::ShutdownLogo,
AuraControl::ShutdownKeyb,
AuraDev19b6::SleepKeyb,
AuraDev19b6::AwakeLogo,
AuraDev19b6::AwakeKeyb,
AuraDev19b6::ShutdownLogo,
AuraDev19b6::ShutdownKeyb,
];
let bytes = AuraControl::to_bytes(&byte1);
let bytes = AuraDev19b6::to_bytes(&byte1);
println!("{:08b}", bytes[0]);
assert_eq!(bytes[0], 0xef);
let byte1 = [
AuraControl::BootLogo,
AuraControl::BootKeyb,
AuraControl::SleepLogo,
AuraDev19b6::BootLogo,
AuraDev19b6::BootKeyb,
AuraDev19b6::SleepLogo,
// AuraControl::SleepKeyb,
AuraControl::AwakeLogo,
AuraControl::AwakeKeyb,
AuraControl::ShutdownLogo,
AuraControl::ShutdownKeyb,
AuraDev19b6::AwakeLogo,
AuraDev19b6::AwakeKeyb,
AuraDev19b6::ShutdownLogo,
AuraDev19b6::ShutdownKeyb,
];
let bytes = AuraControl::to_bytes(&byte1);
let bytes = AuraDev19b6::to_bytes(&byte1);
println!("{:08b}", bytes[0]);
assert_eq!(bytes[0], 0xdf);
let byte2 = [
AuraControl::AwakeBar,
AuraControl::BootBar,
AuraControl::SleepBar,
AuraControl::ShutdownBar,
AuraDev19b6::AwakeBar,
AuraDev19b6::BootBar,
AuraDev19b6::SleepBar,
AuraDev19b6::ShutdownBar,
];
let bytes = AuraControl::to_bytes(&byte2);
let bytes = AuraDev19b6::to_bytes(&byte2);
println!("{:08b}", bytes[1]);
assert_eq!(bytes[1], 0x1e);
let byte2 = [
AuraControl::AwakeBar,
AuraControl::BootBar,
AuraDev19b6::AwakeBar,
AuraDev19b6::BootBar,
// AuraControl::SleepBar,
AuraControl::ShutdownBar,
AuraDev19b6::ShutdownBar,
];
let bytes = AuraControl::to_bytes(&byte2);
let bytes = AuraDev19b6::to_bytes(&byte2);
println!("{:08b}", bytes[1]);
assert_eq!(bytes[1], 0x16);
}

View File

@@ -1,7 +1,7 @@
//! # DBus interface proxy for: `org.asuslinux.Daemon`
//!
//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data.
//! Source: `Interface '/org/asuslinux/Led' from service 'org.asuslinux.Daemon' on system bus`.
//! Source: `Interface '/org/asuslinux/Aura' from service 'org.asuslinux.Daemon' on system bus`.
//!
//! You may prefer to adapt it, instead of using it verbatim.
//!
@@ -22,13 +22,13 @@
use zbus::{blocking::Connection, Result};
use zbus_macros::dbus_proxy;
use rog_aura::{usb::AuraControl, AuraEffect, KeyColourArray, LedBrightness};
use rog_aura::{usb::AuraPowerDev, AuraEffect, KeyColourArray, LedBrightness};
const BLOCKING_TIME: u64 = 40; // 100ms = 10 FPS, max 50ms = 20 FPS, 40ms = 25 FPS
#[dbus_proxy(
interface = "org.asuslinux.Daemon",
default_path = "/org/asuslinux/Led"
default_path = "/org/asuslinux/Aura"
)]
trait Led {
/// NextLedMode method
@@ -49,16 +49,14 @@ trait Led {
/// SetLedMode method
fn set_led_mode(&self, effect: &AuraEffect) -> zbus::Result<()>;
fn set_leds_enabled(&self, enabled: Vec<AuraControl>) -> zbus::Result<()>;
fn set_leds_disabled(&self, disabled: Vec<AuraControl>) -> zbus::Result<()>;
fn set_leds_power(&self, options: AuraPowerDev, enabled: bool) -> zbus::Result<()>;
/// NotifyLed signal
#[dbus_proxy(signal)]
fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>;
#[dbus_proxy(signal)]
fn notify_power_states(&self, data: Vec<AuraControl>) -> zbus::Result<()>;
fn notify_power_states(&self, data: AuraPowerDev) -> zbus::Result<()>;
/// LedBrightness property
#[dbus_proxy(property)]
@@ -72,8 +70,9 @@ trait Led {
#[dbus_proxy(property)]
fn led_modes(&self) -> zbus::Result<String>;
#[dbus_proxy(property)]
fn leds_enabled(&self) -> zbus::Result<Vec<u8>>;
// As property doesn't work for AuraPowerDev (complexity of serialization?)
// #[dbus_proxy(property)]
fn leds_enabled(&self) -> zbus::Result<AuraPowerDev>;
}
pub struct LedProxyPerkey<'a>(LedProxyBlocking<'a>);

View File

@@ -38,6 +38,12 @@ trait RogBios {
/// SetPostBootSound method
fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>;
/// PanelOverdrive method
fn panel_overdrive(&self) -> zbus::Result<i8>;
/// SetPanelOverdrive method
fn set_panel_overdrive(&self, overdrive: bool) -> zbus::Result<()>;
/// NotifyDedicatedGraphicMode signal
#[dbus_proxy(signal)]
fn notify_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>;
@@ -45,4 +51,8 @@ trait RogBios {
/// NotifyPostBootSound signal
#[dbus_proxy(signal)]
fn notify_post_boot_sound(&self, sound: bool) -> zbus::Result<()>;
/// NotifyPanelOverdrive signal
#[dbus_proxy(signal)]
fn notify_panel_overdrive(&self, overdrive: bool) -> zbus::Result<()>;
}

View File

@@ -1,6 +1,6 @@
[package]
name = "rog_supported"
version = "4.0.0"
version = "4.2.1"
license = "MPL-2.0"
readme = "README.md"
authors = ["Luke <luke@ljones.dev>"]

View File

@@ -30,6 +30,7 @@ pub struct PlatformProfileFunctions {
#[derive(Serialize, Deserialize, Type, Debug)]
pub struct LedSupportedFunctions {
pub prod_id: String,
pub brightness_set: bool,
pub stock_led_modes: Vec<AuraModeNum>,
pub multizone_led_mode: Vec<AuraZone>,
@@ -38,8 +39,11 @@ pub struct LedSupportedFunctions {
#[derive(Serialize, Deserialize, Type, Debug)]
pub struct RogBiosSupportedFunctions {
pub post_sound_toggle: bool,
pub dedicated_gfx_toggle: bool,
pub post_sound: bool,
pub dedicated_gfx: bool,
pub panel_overdrive: bool,
pub dgpu_disable: bool,
pub egpu_enable: bool,
}
impl fmt::Display for SupportedFunctions {
@@ -87,7 +91,11 @@ impl fmt::Display for LedSupportedFunctions {
impl fmt::Display for RogBiosSupportedFunctions {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "ROG BIOS:")?;
writeln!(f, "\tPOST sound toggle: {}", self.post_sound_toggle)?;
writeln!(f, "\tDedicated GFX toggle: {}", self.dedicated_gfx_toggle)
writeln!(f, "\tPOST sound switch: {}", self.post_sound)?;
writeln!(f, "\tPanel Overdrive: {}", self.panel_overdrive)?;
writeln!(f, "\tdGPU disable switch: {}", self.dgpu_disable)?;
writeln!(f, "\teGPU enable switch: {}", self.egpu_enable)?;
writeln!(f, "\tDedicated GFX switch: {}", self.dedicated_gfx)?;
Ok(())
}
}