mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-02-06 00:15:04 +01:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cd7e748c88 | |||
| f222eef6b7 | |||
| e6f3aeb851 | |||
| 22605e57cc | |||
| 02fb7addf4 | |||
| bdbb403a0e | |||
| 7a8bede92f | |||
| a71a40b509 | |||
| 42fc5a5392 | |||
| 5017a0ea9b | |||
| 05f7b0060f | |||
| 1043da5328 | |||
| 959ad35afa | |||
| 1e10255d01 | |||
| c72693bc53 | |||
| 2297aad5e5 | |||
| f39c0db680 | |||
| 23353c77f3 | |||
| fee1486db6 | |||
| 39c4253b24 | |||
| 84e924f46a |
@@ -6,6 +6,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased ]
|
## [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
|
## [4.2.0] - 2022-07-16
|
||||||
### Added
|
### Added
|
||||||
- Support for GA402 Anime Matrix display (Author: I-Al-Istannen & Luke Jones)
|
- Support for GA402 Anime Matrix display (Author: I-Al-Istannen & Luke Jones)
|
||||||
|
|||||||
Generated
+6
-5
@@ -33,7 +33,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "asusctl"
|
name = "asusctl"
|
||||||
version = "4.0.7"
|
version = "4.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"daemon",
|
"daemon",
|
||||||
"gif",
|
"gif",
|
||||||
@@ -278,7 +278,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "daemon"
|
name = "daemon"
|
||||||
version = "4.2.0"
|
version = "4.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
@@ -1018,7 +1018,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_anime"
|
name = "rog_anime"
|
||||||
version = "1.3.4"
|
version = "1.3.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"gif",
|
"gif",
|
||||||
"glam",
|
"glam",
|
||||||
@@ -1029,12 +1029,13 @@ dependencies = [
|
|||||||
"serde_derive",
|
"serde_derive",
|
||||||
"sysfs-class",
|
"sysfs-class",
|
||||||
"udev",
|
"udev",
|
||||||
|
"zbus",
|
||||||
"zvariant",
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_aura"
|
name = "rog_aura"
|
||||||
version = "1.1.1"
|
version = "1.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
@@ -1067,7 +1068,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rog_supported"
|
name = "rog_supported"
|
||||||
version = "4.0.0"
|
version = "4.2.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rog_aura",
|
"rog_aura",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "asusctl"
|
name = "asusctl"
|
||||||
version = "4.0.7"
|
version = "4.3.0"
|
||||||
authors = ["Luke D Jones <luke@ljones.dev>"]
|
authors = ["Luke D Jones <luke@ljones.dev>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
client
|
client
|
||||||
.proxies()
|
.proxies()
|
||||||
.anime()
|
.anime()
|
||||||
.write(matrix.into_data_buffer(anime_type))
|
.write(matrix.into_data_buffer(anime_type)?)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn main() {
|
|||||||
client
|
client
|
||||||
.proxies()
|
.proxies()
|
||||||
.anime()
|
.anime()
|
||||||
.write(matrix.into_data_buffer(anime_type))
|
.write(matrix.into_data_buffer(anime_type).unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
sleep(Duration::from_millis(300));
|
sleep(Duration::from_millis(300));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use rog_anime::{usb::get_anime_type, AnimeDataBuffer, AnimeGrid};
|
use rog_anime::{usb::get_anime_type, AnimeDataBuffer, AnimeGrid};
|
||||||
use rog_dbus::RogDbusClientBlocking;
|
use rog_dbus::RogDbusClientBlocking;
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
// In usable data:
|
// In usable data:
|
||||||
// Top row start at 1, ends at 32
|
// 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();
|
client.proxies().anime().write(matrix).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::convert::TryFrom;
|
||||||
use std::{env, error::Error, path::Path, process::exit};
|
use std::{env, error::Error, path::Path, process::exit};
|
||||||
|
|
||||||
use rog_anime::{
|
use rog_anime::{
|
||||||
@@ -32,7 +33,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
client
|
client
|
||||||
.proxies()
|
.proxies()
|
||||||
.anime()
|
.anime()
|
||||||
.write(<AnimeDataBuffer>::from(&matrix))
|
.write(<AnimeDataBuffer>::try_from(&matrix)?)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use std::convert::TryFrom;
|
||||||
use std::{
|
use std::{
|
||||||
env, error::Error, f32::consts::PI, path::Path, process::exit, thread::sleep, time::Duration,
|
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
|
client
|
||||||
.proxies()
|
.proxies()
|
||||||
.anime()
|
.anime()
|
||||||
.write(<AnimeDataBuffer>::from(&matrix))
|
.write(<AnimeDataBuffer>::try_from(&matrix)?)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
sleep(Duration::from_micros(500));
|
sleep(Duration::from_micros(500));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ pub struct AnimeCommand {
|
|||||||
pub boot_enable: Option<bool>,
|
pub boot_enable: Option<bool>,
|
||||||
#[options(meta = "", help = "set global AniMe brightness value")]
|
#[options(meta = "", help = "set global AniMe brightness value")]
|
||||||
pub brightness: Option<f32>,
|
pub brightness: Option<f32>,
|
||||||
|
#[options(help = "clear the display")]
|
||||||
|
pub clear: bool,
|
||||||
#[options(command)]
|
#[options(command)]
|
||||||
pub command: Option<AnimeActions>,
|
pub command: Option<AnimeActions>,
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-3
@@ -3,7 +3,23 @@ use rog_aura::{error::Error, AuraEffect, AuraModeNum, AuraZone, Colour, Directio
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Options)]
|
#[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")]
|
#[options(help = "print help message")]
|
||||||
pub help: bool,
|
pub help: bool,
|
||||||
#[options(command)]
|
#[options(command)]
|
||||||
@@ -12,12 +28,13 @@ pub struct LedPowerCommand {
|
|||||||
|
|
||||||
#[derive(Options)]
|
#[derive(Options)]
|
||||||
pub enum SetAuraEnabled {
|
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")]
|
#[options(help = "set <keyboard, logo, lightbar> to enabled while the device is booting")]
|
||||||
Boot(AuraEnabled),
|
Boot(AuraEnabled),
|
||||||
#[options(help = "set <keyboard, logo, lightbar> to animate while the device is suspended")]
|
#[options(help = "set <keyboard, logo, lightbar> to animate while the device is suspended")]
|
||||||
Sleep(AuraEnabled),
|
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")]
|
#[options(help = "set <keyboard, logo, lightbar> to animate while the device is shutdown")]
|
||||||
Shutdown(AuraEnabled),
|
Shutdown(AuraEnabled),
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-5
@@ -1,6 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
anime_cli::AnimeCommand,
|
anime_cli::AnimeCommand,
|
||||||
aura_cli::{LedBrightness, LedPowerCommand, SetAuraBuiltin},
|
aura_cli::{LedBrightness, LedPowerCommand1, LedPowerCommand2, SetAuraBuiltin},
|
||||||
profiles_cli::{FanCurveCommand, ProfileCommand},
|
profiles_cli::{FanCurveCommand, ProfileCommand},
|
||||||
};
|
};
|
||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
@@ -29,8 +29,10 @@ pub struct CliStart {
|
|||||||
pub enum CliCommand {
|
pub enum CliCommand {
|
||||||
#[options(help = "Set the keyboard lighting from built-in modes")]
|
#[options(help = "Set the keyboard lighting from built-in modes")]
|
||||||
LedMode(LedModeCommand),
|
LedMode(LedModeCommand),
|
||||||
#[options(help = "Set the keyboard lighting from built-in modes")]
|
#[options(help = "Set the LED power states")]
|
||||||
LedPower(LedPowerCommand),
|
LedPow1(LedPowerCommand1),
|
||||||
|
#[options(help = "Set the LED power states")]
|
||||||
|
LedPow2(LedPowerCommand2),
|
||||||
#[options(help = "Set or select platform_profile")]
|
#[options(help = "Set or select platform_profile")]
|
||||||
Profile(ProfileCommand),
|
Profile(ProfileCommand),
|
||||||
#[options(help = "Set, select, or modify fan curves if supported")]
|
#[options(help = "Set, select, or modify fan curves if supported")]
|
||||||
@@ -67,18 +69,29 @@ pub struct BiosCommand {
|
|||||||
pub help: bool,
|
pub help: bool,
|
||||||
#[options(
|
#[options(
|
||||||
meta = "",
|
meta = "",
|
||||||
|
short = "S",
|
||||||
no_long,
|
no_long,
|
||||||
help = "set bios POST sound: asusctl -p <true/false>"
|
help = "set bios POST sound: asusctl -p <true/false>"
|
||||||
)]
|
)]
|
||||||
pub post_sound_set: Option<bool>,
|
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,
|
pub post_sound_get: bool,
|
||||||
#[options(
|
#[options(
|
||||||
meta = "",
|
meta = "",
|
||||||
|
short = "D",
|
||||||
no_long,
|
no_long,
|
||||||
help = "activate dGPU dedicated/G-Sync: asusctl -d <true/false>, reboot required"
|
help = "activate dGPU dedicated/G-Sync: asusctl -d <true/false>, reboot required"
|
||||||
)]
|
)]
|
||||||
pub dedicated_gfx_set: Option<bool>,
|
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,
|
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,
|
||||||
}
|
}
|
||||||
|
|||||||
+162
-148
@@ -1,15 +1,16 @@
|
|||||||
|
use std::convert::TryFrom;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::{env::args, path::Path};
|
use std::{env::args, path::Path};
|
||||||
|
|
||||||
use aura_cli::LedPowerCommand;
|
use aura_cli::{LedPowerCommand1, LedPowerCommand2};
|
||||||
use gumdrop::{Opt, Options};
|
use gumdrop::{Opt, Options};
|
||||||
|
|
||||||
use anime_cli::{AnimeActions, AnimeCommand};
|
use anime_cli::{AnimeActions, AnimeCommand};
|
||||||
use profiles_cli::{FanCurveCommand, ProfileCommand};
|
use profiles_cli::{FanCurveCommand, ProfileCommand};
|
||||||
use rog_anime::usb::get_anime_type;
|
use rog_anime::usb::get_anime_type;
|
||||||
use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, Vec2};
|
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_aura::{self, AuraEffect};
|
||||||
use rog_dbus::RogDbusClientBlocking;
|
use rog_dbus::RogDbusClientBlocking;
|
||||||
use rog_profiles::error::ProfileError;
|
use rog_profiles::error::ProfileError;
|
||||||
@@ -27,8 +28,6 @@ mod aura_cli;
|
|||||||
mod cli_opts;
|
mod cli_opts;
|
||||||
mod profiles_cli;
|
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>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args: Vec<String> = args().skip(1).collect();
|
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>) {
|
fn print_error_help(err: Box<dyn std::error::Error>, supported: Option<&SupportedFunctions>) {
|
||||||
if do_diagnose("asusd") {
|
check_service("asusd");
|
||||||
println!("\nError: {}\n", err);
|
println!("\nError: {}\n", err);
|
||||||
print_versions();
|
print_versions();
|
||||||
|
println!();
|
||||||
|
print_laptop_info();
|
||||||
|
if let Some(supported) = supported {
|
||||||
println!();
|
println!();
|
||||||
print_laptop_info();
|
println!("Supported laptop functions:\n\n{}", supported);
|
||||||
if let Some(supported) = supported {
|
|
||||||
println!();
|
|
||||||
println!("Supported laptop functions:\n\n{}", supported);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +113,7 @@ fn print_laptop_info() {
|
|||||||
println!("Board name: {}", board_name.trim());
|
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) {
|
if name != "asusd" && !check_systemd_unit_enabled(name) {
|
||||||
println!(
|
println!(
|
||||||
"\n\x1b[0;31m{} is not enabled, enable it with `systemctl enable {}\x1b[0m",
|
"\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
|
name, name
|
||||||
);
|
);
|
||||||
return true;
|
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
|
false
|
||||||
}
|
}
|
||||||
@@ -146,7 +137,8 @@ fn do_parsed(
|
|||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
match &parsed.command {
|
match &parsed.command {
|
||||||
Some(CliCommand::LedMode(mode)) => handle_led_mode(dbus, &supported.keyboard_led, mode)?,
|
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::Profile(cmd)) => handle_profile(dbus, &supported.platform_profile, cmd)?,
|
||||||
Some(CliCommand::FanCurve(cmd)) => {
|
Some(CliCommand::FanCurve(cmd)) => {
|
||||||
handle_fan_curve(dbus, &supported.platform_profile, cmd)?
|
handle_fan_curve(dbus, &supported.platform_profile, cmd)?
|
||||||
@@ -165,8 +157,27 @@ fn do_parsed(
|
|||||||
println!("{}", CliStart::usage());
|
println!("{}", CliStart::usage());
|
||||||
println!();
|
println!();
|
||||||
if let Some(cmdlist) = CliStart::command_list() {
|
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);
|
verify_brightness(bright);
|
||||||
dbus.proxies().anime().set_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() {
|
if let Some(action) = cmd.command.as_ref() {
|
||||||
let anime_type = get_anime_type()?;
|
let anime_type = get_anime_type()?;
|
||||||
match action {
|
match action {
|
||||||
@@ -259,7 +277,7 @@ fn handle_anime(
|
|||||||
|
|
||||||
dbus.proxies()
|
dbus.proxies()
|
||||||
.anime()
|
.anime()
|
||||||
.write(<AnimeDataBuffer>::from(&matrix))?;
|
.write(<AnimeDataBuffer>::try_from(&matrix)?)?;
|
||||||
}
|
}
|
||||||
AnimeActions::PixelImage(image) => {
|
AnimeActions::PixelImage(image) => {
|
||||||
if image.help_requested() || image.path.is_empty() {
|
if image.help_requested() || image.path.is_empty() {
|
||||||
@@ -280,7 +298,7 @@ fn handle_anime(
|
|||||||
|
|
||||||
dbus.proxies()
|
dbus.proxies()
|
||||||
.anime()
|
.anime()
|
||||||
.write(matrix.into_data_buffer(anime_type))?;
|
.write(matrix.into_data_buffer(anime_type)?)?;
|
||||||
}
|
}
|
||||||
AnimeActions::Gif(gif) => {
|
AnimeActions::Gif(gif) => {
|
||||||
if gif.help_requested() || gif.path.is_empty() {
|
if gif.help_requested() || gif.path.is_empty() {
|
||||||
@@ -419,10 +437,67 @@ fn handle_led_mode(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_led_power(
|
fn handle_led_power1(
|
||||||
dbus: &RogDbusClientBlocking,
|
dbus: &RogDbusClientBlocking,
|
||||||
_supported: &LedSupportedFunctions,
|
supported: &LedSupportedFunctions,
|
||||||
power: &LedPowerCommand,
|
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>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if power.command().is_none() {
|
if power.command().is_none() {
|
||||||
if !power.help {
|
if !power.help {
|
||||||
@@ -431,7 +506,7 @@ fn handle_led_power(
|
|||||||
println!("{}\n", power.self_usage());
|
println!("{}\n", power.self_usage());
|
||||||
println!("Commands available");
|
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();
|
let commands: Vec<String> = cmdlist.lines().map(|s| s.to_string()).collect();
|
||||||
for command in commands.iter() {
|
for command in commands.iter() {
|
||||||
println!("{}", command);
|
println!("{}", command);
|
||||||
@@ -448,133 +523,60 @@ fn handle_led_power(
|
|||||||
return Ok(());
|
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 {
|
match pow {
|
||||||
// TODO: make this a macro or something
|
|
||||||
aura_cli::SetAuraEnabled::Boot(arg) => {
|
aura_cli::SetAuraEnabled::Boot(arg) => {
|
||||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
check(arg.keyboard, AuraDev19b6::BootKeyb);
|
||||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
check(arg.logo, AuraDev19b6::BootLogo);
|
||||||
arg.keyboard.map(|v| {
|
check(arg.lightbar, AuraDev19b6::BootBar);
|
||||||
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)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
aura_cli::SetAuraEnabled::Sleep(arg) => {
|
aura_cli::SetAuraEnabled::Sleep(arg) => {
|
||||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
check(arg.keyboard, AuraDev19b6::SleepKeyb);
|
||||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
check(arg.logo, AuraDev19b6::SleepLogo);
|
||||||
arg.keyboard.map(|v| {
|
check(arg.lightbar, AuraDev19b6::SleepBar);
|
||||||
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)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
aura_cli::SetAuraEnabled::Awake(arg) => {
|
aura_cli::SetAuraEnabled::Awake(arg) => {
|
||||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
check(arg.keyboard, AuraDev19b6::AwakeKeyb);
|
||||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
check(arg.logo, AuraDev19b6::AwakeLogo);
|
||||||
arg.keyboard.map(|v| {
|
check(arg.lightbar, AuraDev19b6::AwakeBar);
|
||||||
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)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
aura_cli::SetAuraEnabled::Shutdown(arg) => {
|
aura_cli::SetAuraEnabled::Shutdown(arg) => {
|
||||||
let mut enabled: Vec<AuraControl> = Vec::new();
|
check(arg.keyboard, AuraDev19b6::ShutdownKeyb);
|
||||||
let mut disabled: Vec<AuraControl> = Vec::new();
|
check(arg.logo, AuraDev19b6::ShutdownLogo);
|
||||||
arg.keyboard.map(|v| {
|
check(arg.lightbar, AuraDev19b6::ShutdownBar);
|
||||||
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)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(())
|
Ok(())
|
||||||
@@ -692,7 +694,9 @@ fn handle_bios_option(
|
|||||||
if (cmd.dedicated_gfx_set.is_none()
|
if (cmd.dedicated_gfx_set.is_none()
|
||||||
&& !cmd.dedicated_gfx_get
|
&& !cmd.dedicated_gfx_get
|
||||||
&& cmd.post_sound_set.is_none()
|
&& 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
|
|| cmd.help
|
||||||
{
|
{
|
||||||
println!("Missing arg or command\n");
|
println!("Missing arg or command\n");
|
||||||
@@ -703,8 +707,9 @@ fn handle_bios_option(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for line in usage.iter().filter(|line| {
|
for line in usage.iter().filter(|line| {
|
||||||
line.contains("sound") && supported.post_sound_toggle
|
line.contains("sound") && supported.post_sound
|
||||||
|| line.contains("GPU") && supported.dedicated_gfx_toggle
|
|| line.contains("GPU") && supported.dedicated_gfx
|
||||||
|
|| line.contains("panel") && supported.panel_overdrive
|
||||||
}) {
|
}) {
|
||||||
println!("{}", line);
|
println!("{}", line);
|
||||||
}
|
}
|
||||||
@@ -717,6 +722,7 @@ fn handle_bios_option(
|
|||||||
let res = dbus.proxies().rog_bios().post_boot_sound()? == 1;
|
let res = dbus.proxies().rog_bios().post_boot_sound()? == 1;
|
||||||
println!("Bios POST sound on: {}", res);
|
println!("Bios POST sound on: {}", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(opt) = cmd.dedicated_gfx_set {
|
if let Some(opt) = cmd.dedicated_gfx_set {
|
||||||
println!("Rebuilding initrd to include drivers");
|
println!("Rebuilding initrd to include drivers");
|
||||||
dbus.proxies().rog_bios().set_dedicated_graphic_mode(opt)?;
|
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;
|
let res = dbus.proxies().rog_bios().dedicated_graphic_mode()? == 1;
|
||||||
println!("Bios dedicated GPU on: {}", res);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "daemon"
|
name = "daemon"
|
||||||
version = "4.2.0"
|
version = "4.3.0"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Luke <luke@ljones.dev>"]
|
authors = ["Luke <luke@ljones.dev>"]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
|
pub static CONFIG_PATH: &str = "/etc/asusd/asusd.conf";
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// Save charge limit for restoring on boot
|
/// Save charge limit for restoring on boot
|
||||||
pub bat_charge_limit: u8,
|
pub bat_charge_limit: u8,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use rusb::{Device, DeviceHandle};
|
|||||||
use smol::{stream::StreamExt, Executor};
|
use smol::{stream::StreamExt, Executor};
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
convert::TryFrom,
|
||||||
error::Error,
|
error::Error,
|
||||||
sync::{Arc, Mutex, MutexGuard},
|
sync::{Arc, Mutex, MutexGuard},
|
||||||
thread::sleep,
|
thread::sleep,
|
||||||
@@ -167,7 +168,14 @@ impl CtrlAnime {
|
|||||||
inner
|
inner
|
||||||
.try_lock()
|
.try_lock()
|
||||||
.map(|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
|
false // Don't exit yet
|
||||||
})
|
})
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
@@ -183,6 +191,8 @@ impl CtrlAnime {
|
|||||||
once = false;
|
once = false;
|
||||||
if let Ok(lock) = inner.try_lock() {
|
if let Ok(lock) = inner.try_lock() {
|
||||||
lock.write_data_buffer(image.as_ref().clone())
|
lock.write_data_buffer(image.as_ref().clone())
|
||||||
|
.map_err(|e| error!("{}", e))
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ActionData::Pause(duration) => sleep(*duration),
|
ActionData::Pause(duration) => sleep(*duration),
|
||||||
@@ -201,9 +211,16 @@ impl CtrlAnime {
|
|||||||
}
|
}
|
||||||
// Clear the display on exit
|
// Clear the display on exit
|
||||||
if let Ok(lock) = inner.try_lock() {
|
if let Ok(lock) = inner.try_lock() {
|
||||||
let data =
|
if let Ok(data) =
|
||||||
AnimeDataBuffer::from_vec(anime_type, vec![0u8; anime_type.data_length()]);
|
AnimeDataBuffer::from_vec(anime_type, vec![0u8; anime_type.data_length()])
|
||||||
lock.write_data_buffer(data);
|
.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
|
// Loop ended, set the atmonics
|
||||||
thread_running.store(false, Ordering::SeqCst);
|
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
|
/// Write only a data packet. This will modify the leds brightness using the
|
||||||
/// global brightness set in config.
|
/// 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() {
|
for led in buffer.data_mut()[7..].iter_mut() {
|
||||||
let mut bright = *led as f32 * self.config.brightness;
|
let mut bright = *led as f32 * self.config.brightness;
|
||||||
if bright > 254.0 {
|
if bright > 254.0 {
|
||||||
@@ -262,11 +279,12 @@ impl CtrlAnime {
|
|||||||
}
|
}
|
||||||
*led = bright as u8;
|
*led = bright as u8;
|
||||||
}
|
}
|
||||||
let data = AnimePacketType::from(buffer);
|
let data = AnimePacketType::try_from(buffer)?;
|
||||||
for row in data.iter() {
|
for row in data.iter() {
|
||||||
self.write_bytes(row);
|
self.write_bytes(row);
|
||||||
}
|
}
|
||||||
self.write_bytes(&pkt_for_flush());
|
self.write_bytes(&pkt_for_flush());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn do_initialization(&self) {
|
fn do_initialization(&self) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use log::warn;
|
||||||
use rog_anime::{
|
use rog_anime::{
|
||||||
usb::{pkt_for_apply, pkt_for_set_boot, pkt_for_set_on},
|
usb::{pkt_for_apply, pkt_for_set_boot, pkt_for_set_on},
|
||||||
AnimeDataBuffer, AnimePowerStates,
|
AnimeDataBuffer, AnimePowerStates,
|
||||||
@@ -27,14 +28,18 @@ impl crate::ZbusAdd for CtrlAnimeZbus {
|
|||||||
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
#[dbus_interface(name = "org.asuslinux.Daemon")]
|
||||||
impl CtrlAnimeZbus {
|
impl CtrlAnimeZbus {
|
||||||
/// Writes a data stream of length. Will force system thread to exit until it is restarted
|
/// 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 {
|
'outer: loop {
|
||||||
if let Ok(lock) = self.0.try_lock() {
|
if let Ok(lock) = self.0.try_lock() {
|
||||||
lock.thread_exit.store(true, Ordering::SeqCst);
|
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;
|
break 'outer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the global AniMe brightness
|
/// Set the global AniMe brightness
|
||||||
|
|||||||
+219
-24
@@ -1,14 +1,75 @@
|
|||||||
use crate::laptops::LaptopLedData;
|
use crate::laptops::{LaptopLedData, ASUS_KEYBOARD_DEVICES};
|
||||||
use log::{error, warn};
|
use log::{error, warn};
|
||||||
use rog_aura::usb::AuraControl;
|
use rog_aura::usb::{AuraDev1866, AuraDev19b6, AuraPowerDev};
|
||||||
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, LedBrightness};
|
use rog_aura::{AuraEffect, AuraModeNum, AuraZone, Direction, LedBrightness, Speed, GRADIENT};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::collections::{BTreeMap, HashSet};
|
use std::collections::{BTreeMap, HashSet};
|
||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use super::controller::CtrlKbdLed;
|
||||||
|
|
||||||
pub static AURA_CONFIG_PATH: &str = "/etc/asusd/aura.conf";
|
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)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct AuraConfig {
|
pub struct AuraConfig {
|
||||||
@@ -16,30 +77,52 @@ pub struct AuraConfig {
|
|||||||
pub current_mode: AuraModeNum,
|
pub current_mode: AuraModeNum,
|
||||||
pub builtins: BTreeMap<AuraModeNum, AuraEffect>,
|
pub builtins: BTreeMap<AuraModeNum, AuraEffect>,
|
||||||
pub multizone: Option<BTreeMap<AuraModeNum, Vec<AuraEffect>>>,
|
pub multizone: Option<BTreeMap<AuraModeNum, Vec<AuraEffect>>>,
|
||||||
pub enabled: HashSet<AuraControl>,
|
pub multizone_on: bool,
|
||||||
|
pub enabled: AuraPowerConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AuraConfig {
|
impl Default for AuraConfig {
|
||||||
fn default() -> Self {
|
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 {
|
AuraConfig {
|
||||||
brightness: LedBrightness::Med,
|
brightness: LedBrightness::Med,
|
||||||
current_mode: AuraModeNum::Static,
|
current_mode: AuraModeNum::Static,
|
||||||
builtins: BTreeMap::new(),
|
builtins: BTreeMap::new(),
|
||||||
multizone: None,
|
multizone: None,
|
||||||
enabled: HashSet::from([
|
multizone_on: false,
|
||||||
AuraControl::BootLogo,
|
enabled,
|
||||||
AuraControl::BootKeyb,
|
|
||||||
AuraControl::SleepLogo,
|
|
||||||
AuraControl::SleepKeyb,
|
|
||||||
AuraControl::AwakeLogo,
|
|
||||||
AuraControl::AwakeKeyb,
|
|
||||||
AuraControl::ShutdownLogo,
|
|
||||||
AuraControl::ShutdownKeyb,
|
|
||||||
AuraControl::AwakeBar,
|
|
||||||
AuraControl::BootBar,
|
|
||||||
AuraControl::SleepBar,
|
|
||||||
AuraControl::ShutdownBar,
|
|
||||||
]),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,6 +173,27 @@ impl AuraConfig {
|
|||||||
config
|
config
|
||||||
.builtins
|
.builtins
|
||||||
.insert(*n, AuraEffect::default_with_mode(*n));
|
.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
|
// 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));
|
.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) {
|
pub fn set_builtin(&mut self, effect: AuraEffect) {
|
||||||
|
self.current_mode = effect.mode;
|
||||||
match effect.zone() {
|
match effect.zone() {
|
||||||
AuraZone::None => {
|
AuraZone::None => {
|
||||||
self.builtins.insert(*effect.mode(), effect);
|
self.builtins.insert(*effect.mode(), effect);
|
||||||
|
self.multizone_on = false;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(multi) = self.multizone.as_mut() {
|
if let Some(multi) = self.multizone.as_mut() {
|
||||||
if let Some(fx) = multi.get_mut(effect.mode()) {
|
if let Some(fx) = multi.get_mut(effect.mode()) {
|
||||||
for fx in fx.iter_mut() {
|
for fx in fx.iter_mut() {
|
||||||
if fx.mode == effect.mode {
|
if fx.zone == effect.zone {
|
||||||
*fx = effect;
|
*fx = effect;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fx.push(effect);
|
||||||
} else {
|
} else {
|
||||||
let mut tmp = BTreeMap::new();
|
multi.insert(*effect.mode(), vec![effect]);
|
||||||
tmp.insert(*effect.mode(), vec![effect]);
|
|
||||||
self.multizone = Some(tmp);
|
|
||||||
}
|
}
|
||||||
|
} 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
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,23 +9,26 @@ use crate::{
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use logind_zbus::manager::ManagerProxy;
|
use logind_zbus::manager::ManagerProxy;
|
||||||
use rog_aura::usb::AuraControl;
|
|
||||||
use rog_aura::{
|
use rog_aura::{
|
||||||
usb::{LED_APPLY, LED_SET},
|
usb::{LED_APPLY, LED_SET},
|
||||||
AuraEffect, LedBrightness, LED_MSG_LEN,
|
AuraEffect, LedBrightness, LED_MSG_LEN,
|
||||||
};
|
};
|
||||||
|
use rog_aura::{AuraZone, Direction, Speed, GRADIENT};
|
||||||
use rog_supported::LedSupportedFunctions;
|
use rog_supported::LedSupportedFunctions;
|
||||||
use smol::{stream::StreamExt, Executor};
|
use smol::{stream::StreamExt, Executor};
|
||||||
use std::io::{Read, Write};
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
|
io::{Read, Write},
|
||||||
|
};
|
||||||
use std::{fs::OpenOptions, sync::MutexGuard};
|
use std::{fs::OpenOptions, sync::MutexGuard};
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
use crate::GetSupported;
|
use crate::GetSupported;
|
||||||
|
|
||||||
use super::config::AuraConfig;
|
use super::config::{AuraConfig, AuraPowerConfig};
|
||||||
|
|
||||||
impl GetSupported for CtrlKbdLed {
|
impl GetSupported for CtrlKbdLed {
|
||||||
type A = LedSupportedFunctions;
|
type A = LedSupportedFunctions;
|
||||||
@@ -37,7 +40,16 @@ impl GetSupported for CtrlKbdLed {
|
|||||||
let multizone_led_mode = laptop.multizone;
|
let multizone_led_mode = laptop.multizone;
|
||||||
let per_key_led_mode = laptop.per_key;
|
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 {
|
LedSupportedFunctions {
|
||||||
|
prod_id,
|
||||||
brightness_set: CtrlKbdLed::get_kbd_bright_path().is_some(),
|
brightness_set: CtrlKbdLed::get_kbd_bright_path().is_some(),
|
||||||
stock_led_modes,
|
stock_led_modes,
|
||||||
multizone_led_mode,
|
multizone_led_mode,
|
||||||
@@ -47,6 +59,8 @@ impl GetSupported for CtrlKbdLed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct 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 led_node: Option<String>,
|
||||||
pub bright_node: String,
|
pub bright_node: String,
|
||||||
pub supported_modes: LaptopLedData,
|
pub supported_modes: LaptopLedData,
|
||||||
@@ -106,11 +120,9 @@ impl CtrlTask for CtrlKbdLedTask {
|
|||||||
lock.set_brightness(lock.config.brightness)
|
lock.set_brightness(lock.config.brightness)
|
||||||
.map_err(|e| error!("CtrlKbdLedTask: {e}"))
|
.map_err(|e| error!("CtrlKbdLedTask: {e}"))
|
||||||
.ok();
|
.ok();
|
||||||
if let Some(mode) = lock.config.builtins.get(&lock.config.current_mode) {
|
lock.write_current_config_mode()
|
||||||
lock.write_mode(mode)
|
.map_err(|e| error!("CtrlKbdLedTask: {e}"))
|
||||||
.map_err(|e| error!("CtrlKbdLedTask: {e}"))
|
.ok();
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
} else if start {
|
} else if start {
|
||||||
info!("CtrlKbdLedTask saving last brightness");
|
info!("CtrlKbdLedTask saving last brightness");
|
||||||
Self::update_config(&mut lock)
|
Self::update_config(&mut lock)
|
||||||
@@ -154,15 +166,6 @@ impl CtrlTask for CtrlKbdLedTask {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.detach();
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,11 +175,7 @@ pub struct CtrlKbdLedReloader(pub Arc<Mutex<CtrlKbdLed>>);
|
|||||||
impl crate::Reloadable for CtrlKbdLedReloader {
|
impl crate::Reloadable for CtrlKbdLedReloader {
|
||||||
fn reload(&mut self) -> Result<(), RogError> {
|
fn reload(&mut self) -> Result<(), RogError> {
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
let current = ctrl.config.current_mode;
|
ctrl.write_current_config_mode()?;
|
||||||
if let Some(mode) = ctrl.config.builtins.get(¤t).cloned() {
|
|
||||||
ctrl.do_command(mode).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
ctrl.set_power_states(&ctrl.config)
|
ctrl.set_power_states(&ctrl.config)
|
||||||
.map_err(|err| warn!("{err}"))
|
.map_err(|err| warn!("{err}"))
|
||||||
.ok();
|
.ok();
|
||||||
@@ -194,13 +193,14 @@ impl CtrlKbdLedZbus {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CtrlKbdLed {
|
impl CtrlKbdLed {
|
||||||
#[inline]
|
|
||||||
pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result<Self, RogError> {
|
pub fn new(supported_modes: LaptopLedData, config: AuraConfig) -> Result<Self, RogError> {
|
||||||
// TODO: return error if *all* nodes are None
|
// TODO: return error if *all* nodes are None
|
||||||
|
let mut led_prod = None;
|
||||||
let mut led_node = None;
|
let mut led_node = None;
|
||||||
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
for prod in ASUS_KEYBOARD_DEVICES.iter() {
|
||||||
match Self::find_led_node(prod) {
|
match Self::find_led_node(prod) {
|
||||||
Ok(node) => {
|
Ok(node) => {
|
||||||
|
led_prod = Some(prod.to_string());
|
||||||
led_node = Some(node);
|
led_node = Some(node);
|
||||||
info!("Looked for keyboard controller 0x{prod}: Found");
|
info!("Looked for keyboard controller 0x{prod}: Found");
|
||||||
break;
|
break;
|
||||||
@@ -211,11 +211,8 @@ impl CtrlKbdLed {
|
|||||||
|
|
||||||
let bright_node = Self::get_kbd_bright_path();
|
let bright_node = Self::get_kbd_bright_path();
|
||||||
|
|
||||||
if led_node.is_none() && bright_node.is_none() {
|
if led_node.is_none() {
|
||||||
return Err(RogError::MissingFunction(
|
return Err(RogError::NoAuraKeyboard);
|
||||||
"All keyboard features missing, you may require a v5.11 series kernel or newer"
|
|
||||||
.into(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if bright_node.is_none() {
|
if bright_node.is_none() {
|
||||||
@@ -225,6 +222,7 @@ impl CtrlKbdLed {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let ctrl = CtrlKbdLed {
|
let ctrl = CtrlKbdLed {
|
||||||
|
led_prod,
|
||||||
led_node,
|
led_node,
|
||||||
bright_node: bright_node.unwrap(), // If was none then we already returned above
|
bright_node: bright_node.unwrap(), // If was none then we already returned above
|
||||||
supported_modes,
|
supported_modes,
|
||||||
@@ -298,13 +296,8 @@ impl CtrlKbdLed {
|
|||||||
|
|
||||||
/// Set combination state for boot animation/sleep animation/all leds/keys leds/side leds LED active
|
/// 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> {
|
pub(super) fn set_power_states(&self, config: &AuraConfig) -> Result<(), RogError> {
|
||||||
let set: Vec<AuraControl> = config.enabled.iter().map(|v| *v).collect();
|
let bytes = AuraPowerConfig::to_bytes(&config.enabled);
|
||||||
let bytes = AuraControl::to_bytes(&set);
|
let message = [0x5d, 0xbd, 0x01, bytes[0], bytes[1], bytes[2]];
|
||||||
|
|
||||||
// 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,
|
|
||||||
];
|
|
||||||
|
|
||||||
self.write_bytes(&message)?;
|
self.write_bytes(&message)?;
|
||||||
self.write_bytes(&LED_SET)?;
|
self.write_bytes(&LED_SET)?;
|
||||||
@@ -313,7 +306,7 @@ impl CtrlKbdLed {
|
|||||||
Ok(())
|
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| {
|
let mut enumerator = udev::Enumerator::new().map_err(|err| {
|
||||||
warn!("{}", err);
|
warn!("{}", err);
|
||||||
RogError::Udev("enumerator failed".into(), err)
|
RogError::Udev("enumerator failed".into(), err)
|
||||||
@@ -351,12 +344,27 @@ impl CtrlKbdLed {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn do_command(&mut self, mode: AuraEffect) -> Result<(), RogError> {
|
/// Set an Aura effect if the effect mode or zone is supported.
|
||||||
self.set_and_save(mode)
|
///
|
||||||
|
/// 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
|
/// Should only be used if the bytes you are writing are verified correct
|
||||||
#[inline]
|
|
||||||
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
fn write_bytes(&self, message: &[u8]) -> Result<(), RogError> {
|
||||||
if let Some(led_node) = &self.led_node {
|
if let Some(led_node) = &self.led_node {
|
||||||
if let Ok(mut file) = OpenOptions::new().write(true).open(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));
|
.map_err(|err| RogError::Write("write_bytes".into(), err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(RogError::NotSupported)
|
Err(RogError::NoAuraNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write an effect block
|
/// Write an effect block. This is for per-key
|
||||||
#[inline]
|
|
||||||
fn _write_effect(&mut self, effect: &[Vec<u8>]) -> Result<(), RogError> {
|
fn _write_effect(&mut self, effect: &[Vec<u8>]) -> Result<(), RogError> {
|
||||||
if self.flip_effect_write {
|
if self.flip_effect_write {
|
||||||
for row in effect.iter().rev() {
|
for row in effect.iter().rev() {
|
||||||
@@ -385,20 +392,6 @@ impl CtrlKbdLed {
|
|||||||
Ok(())
|
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> {
|
pub(super) fn toggle_mode(&mut self, reverse: bool) -> Result<(), RogError> {
|
||||||
let current = self.config.current_mode;
|
let current = self.config.current_mode;
|
||||||
if let Some(idx) = self
|
if let Some(idx) = self
|
||||||
@@ -424,9 +417,9 @@ impl CtrlKbdLed {
|
|||||||
let next = self.supported_modes.standard[idx];
|
let next = self.supported_modes.standard[idx];
|
||||||
|
|
||||||
self.config.read();
|
self.config.read();
|
||||||
if let Some(data) = self.config.builtins.get(&next) {
|
if self.config.builtins.contains_key(&next) {
|
||||||
self.write_mode(data)?;
|
|
||||||
self.config.current_mode = next;
|
self.config.current_mode = next;
|
||||||
|
self.write_current_config_mode()?;
|
||||||
}
|
}
|
||||||
self.config.write();
|
self.config.write();
|
||||||
}
|
}
|
||||||
@@ -434,11 +427,7 @@ impl CtrlKbdLed {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn write_mode(&self, mode: &AuraEffect) -> Result<(), RogError> {
|
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();
|
let bytes: [u8; LED_MSG_LEN] = mode.into();
|
||||||
self.write_bytes(&bytes)?;
|
self.write_bytes(&bytes)?;
|
||||||
self.write_bytes(&LED_SET)?;
|
self.write_bytes(&LED_SET)?;
|
||||||
@@ -446,4 +435,217 @@ impl CtrlKbdLed {
|
|||||||
self.write_bytes(&LED_APPLY)?;
|
self.write_bytes(&LED_APPLY)?;
|
||||||
Ok(())
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use rog_aura::{usb::AuraControl, AuraEffect, LedBrightness};
|
use rog_aura::{usb::AuraPowerDev, AuraEffect, LedBrightness};
|
||||||
use zbus::{dbus_interface, Connection, SignalContext};
|
use zbus::{dbus_interface, Connection, SignalContext};
|
||||||
|
|
||||||
use super::controller::CtrlKbdLedZbus;
|
use super::controller::CtrlKbdLedZbus;
|
||||||
@@ -8,7 +8,7 @@ use super::controller::CtrlKbdLedZbus;
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl crate::ZbusAdd for CtrlKbdLedZbus {
|
impl crate::ZbusAdd for CtrlKbdLedZbus {
|
||||||
async fn add_to_server(self, server: &mut Connection) {
|
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,
|
/// SleepBar,
|
||||||
/// ShutdownBar,
|
/// ShutdownBar,
|
||||||
/// }
|
/// }
|
||||||
async fn set_leds_enabled(
|
async fn set_leds_power(
|
||||||
&mut self,
|
&mut self,
|
||||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||||
enabled: Vec<AuraControl>,
|
options: AuraPowerDev,
|
||||||
) {
|
enabled: bool,
|
||||||
|
) -> zbus::fdo::Result<()> {
|
||||||
let mut states = None;
|
let mut states = None;
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
for s in enabled {
|
for p in options.x1866 {
|
||||||
ctrl.config.enabled.insert(s);
|
ctrl.config.enabled.set_0x1866(p, enabled);
|
||||||
}
|
}
|
||||||
|
for p in options.x19b6 {
|
||||||
|
ctrl.config.enabled.set_0x19b6(p, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
ctrl.config.write();
|
ctrl.config.write();
|
||||||
|
|
||||||
ctrl.set_power_states(&ctrl.config)
|
ctrl.set_power_states(&ctrl.config).map_err(|e| {
|
||||||
.map_err(|err| warn!("{}", err))
|
warn!("{}", e);
|
||||||
.ok();
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
|
states = Some(AuraPowerDev::from(&ctrl.config.enabled));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
// Need to pull state out like this due to MutexGuard
|
// Need to pull state out like this due to MutexGuard
|
||||||
if let Some(states) = states {
|
if let Some(states) = states {
|
||||||
@@ -94,24 +72,22 @@ impl CtrlKbdLedZbus {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.unwrap_or_else(|err| warn!("{}", err));
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_led_mode(
|
async fn set_led_mode(
|
||||||
&mut self,
|
&mut self,
|
||||||
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
#[zbus(signal_context)] ctxt: SignalContext<'_>,
|
||||||
effect: AuraEffect,
|
effect: AuraEffect,
|
||||||
) {
|
) -> zbus::fdo::Result<()> {
|
||||||
let mut led = None;
|
let mut led = None;
|
||||||
if let Ok(mut ctrl) = self.0.try_lock() {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
match ctrl.do_command(effect) {
|
ctrl.set_effect(effect).map_err(|e| {
|
||||||
Ok(_) => {
|
warn!("{}", e);
|
||||||
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
e
|
||||||
led = Some(mode.clone());
|
})?;
|
||||||
}
|
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
||||||
}
|
led = Some(mode.clone());
|
||||||
Err(err) => {
|
|
||||||
warn!("{}", err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(led) = led {
|
if let Some(led) = led {
|
||||||
@@ -119,13 +95,19 @@ impl CtrlKbdLedZbus {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.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;
|
let mut led = None;
|
||||||
if let Ok(mut ctrl) = self.0.lock() {
|
if let Ok(mut ctrl) = self.0.lock() {
|
||||||
ctrl.toggle_mode(false)
|
ctrl.toggle_mode(false).map_err(|e| {
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
warn!("{}", e);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
||||||
led = Some(mode.clone());
|
led = Some(mode.clone());
|
||||||
@@ -136,13 +118,19 @@ impl CtrlKbdLedZbus {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.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;
|
let mut led = None;
|
||||||
if let Ok(mut ctrl) = self.0.lock() {
|
if let Ok(mut ctrl) = self.0.lock() {
|
||||||
ctrl.toggle_mode(true)
|
ctrl.toggle_mode(true).map_err(|e| {
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
warn!("{}", e);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
|
|
||||||
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
if let Some(mode) = ctrl.config.builtins.get(&ctrl.config.current_mode) {
|
||||||
led = Some(mode.clone());
|
led = Some(mode.clone());
|
||||||
@@ -153,29 +141,37 @@ impl CtrlKbdLedZbus {
|
|||||||
.await
|
.await
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
.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() {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
ctrl.next_brightness()
|
ctrl.next_brightness().map_err(|e| {
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
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() {
|
if let Ok(mut ctrl) = self.0.try_lock() {
|
||||||
ctrl.prev_brightness()
|
ctrl.prev_brightness().map_err(|e| {
|
||||||
.unwrap_or_else(|err| warn!("{}", err));
|
warn!("{}", e);
|
||||||
|
e
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[dbus_interface(property)]
|
// As property doesn't work for AuraPowerDev (complexity of serialization?)
|
||||||
async fn leds_enabled(&self) -> Vec<u8> {
|
// #[dbus_interface(property)]
|
||||||
if let Ok(ctrl) = self.0.try_lock() {
|
async fn leds_power(&self) -> AuraPowerDev {
|
||||||
let set: Vec<AuraControl> = ctrl.config.enabled.iter().map(|v| *v).collect();
|
loop {
|
||||||
return AuraControl::to_bytes(&set).to_vec();
|
if let Ok(ctrl) = self.0.try_lock() {
|
||||||
|
return AuraPowerDev::from(&ctrl.config.enabled);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vec![0, 0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the current mode data
|
/// Return the current mode data
|
||||||
@@ -220,6 +216,6 @@ impl CtrlKbdLedZbus {
|
|||||||
#[dbus_interface(signal)]
|
#[dbus_interface(signal)]
|
||||||
async fn notify_power_states(
|
async fn notify_power_states(
|
||||||
signal_ctxt: &SignalContext<'_>,
|
signal_ctxt: &SignalContext<'_>,
|
||||||
data: &[AuraControl],
|
data: &AuraPowerDev,
|
||||||
) -> zbus::Result<()>;
|
) -> zbus::Result<()>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ static ASUS_SWITCH_GRAPHIC_MODE: &str =
|
|||||||
"/sys/firmware/efi/efivars/AsusSwitchGraphicMode-607005d5-3f75-4b2e-98f0-85ba66797a3e";
|
"/sys/firmware/efi/efivars/AsusSwitchGraphicMode-607005d5-3f75-4b2e-98f0-85ba66797a3e";
|
||||||
static ASUS_POST_LOGO_SOUND: &str =
|
static ASUS_POST_LOGO_SOUND: &str =
|
||||||
"/sys/firmware/efi/efivars/AsusPostLogoSound-607005d5-3f75-4b2e-98f0-85ba66797a3e";
|
"/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 {
|
pub struct CtrlRogBios {
|
||||||
_config: Arc<Mutex<Config>>,
|
_config: Arc<Mutex<Config>>,
|
||||||
@@ -29,8 +32,11 @@ impl GetSupported for CtrlRogBios {
|
|||||||
|
|
||||||
fn get_supported() -> Self::A {
|
fn get_supported() -> Self::A {
|
||||||
RogBiosSupportedFunctions {
|
RogBiosSupportedFunctions {
|
||||||
post_sound_toggle: Path::new(ASUS_POST_LOGO_SOUND).exists(),
|
post_sound: Path::new(ASUS_POST_LOGO_SOUND).exists(),
|
||||||
dedicated_gfx_toggle: Path::new(ASUS_SWITCH_GRAPHIC_MODE).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)]
|
#[dbus_interface(signal)]
|
||||||
async fn notify_post_boot_sound(ctxt: &SignalContext<'_>, on: bool) -> zbus::Result<()> {}
|
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]
|
#[async_trait]
|
||||||
@@ -305,4 +357,43 @@ impl CtrlRogBios {
|
|||||||
}
|
}
|
||||||
Ok(())
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use rog_anime::error::AnimeError;
|
||||||
use rog_profiles::error::ProfileError;
|
use rog_profiles::error::ProfileError;
|
||||||
use std::convert::From;
|
use std::convert::From;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
@@ -23,6 +24,10 @@ pub enum RogError {
|
|||||||
Io(std::io::Error),
|
Io(std::io::Error),
|
||||||
Zbus(zbus::Error),
|
Zbus(zbus::Error),
|
||||||
ChargeLimit(u8),
|
ChargeLimit(u8),
|
||||||
|
AuraEffectNotSupported,
|
||||||
|
NoAuraKeyboard,
|
||||||
|
NoAuraNode,
|
||||||
|
Anime(AnimeError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for RogError {
|
impl fmt::Display for RogError {
|
||||||
@@ -48,6 +53,10 @@ impl fmt::Display for RogError {
|
|||||||
RogError::Io(detail) => write!(f, "std::io error: {}", detail),
|
RogError::Io(detail) => write!(f, "std::io error: {}", detail),
|
||||||
RogError::Zbus(detail) => write!(f, "Zbus 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::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 {
|
impl From<zbus::Error> for RogError {
|
||||||
fn from(err: zbus::Error) -> Self {
|
fn from(err: zbus::Error) -> Self {
|
||||||
RogError::Zbus(err)
|
RogError::Zbus(err)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rog_anime"
|
name = "rog_anime"
|
||||||
version = "1.3.4"
|
version = "1.3.5"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Luke <luke@ljones.dev>"]
|
authors = ["Luke <luke@ljones.dev>"]
|
||||||
@@ -14,7 +14,7 @@ exclude = ["data"]
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["dbus", "detect"]
|
default = ["dbus", "detect"]
|
||||||
dbus = ["zvariant"]
|
dbus = ["zvariant", "zbus"]
|
||||||
detect = ["udev", "sysfs-class"]
|
detect = ["udev", "sysfs-class"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@@ -29,6 +29,7 @@ serde_derive = "^1.0"
|
|||||||
glam = { version = "0.20.5", features = ["serde"] }
|
glam = { version = "0.20.5", features = ["serde"] }
|
||||||
|
|
||||||
zvariant = { version = "^3.0", optional = true }
|
zvariant = { version = "^3.0", optional = true }
|
||||||
|
zbus = { version = "^2.2", optional = true }
|
||||||
|
|
||||||
udev = { version = "^0.6", optional = true }
|
udev = { version = "^0.6", optional = true }
|
||||||
sysfs-class = { version = "^0.1", optional = true }
|
sysfs-class = { version = "^0.1", optional = true }
|
||||||
+20
-11
@@ -1,4 +1,5 @@
|
|||||||
use std::{
|
use std::{
|
||||||
|
convert::TryFrom,
|
||||||
thread::sleep,
|
thread::sleep,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
@@ -8,7 +9,10 @@ use serde_derive::{Deserialize, Serialize};
|
|||||||
#[cfg(feature = "dbus")]
|
#[cfg(feature = "dbus")]
|
||||||
use zvariant::Type;
|
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`
|
/// The first 7 bytes of a USB packet are accounted for by `USB_PREFIX1` and `USB_PREFIX2`
|
||||||
const BLOCK_START: usize = 7;
|
const BLOCK_START: usize = 7;
|
||||||
@@ -102,20 +106,25 @@ impl AnimeDataBuffer {
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
/// Will panic if the vector length is not `ANIME_DATA_LEN`
|
/// Will panic if the vector length is not `ANIME_DATA_LEN`
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_vec(anime: AnimeType, data: Vec<u8>) -> Self {
|
pub fn from_vec(anime: AnimeType, data: Vec<u8>) -> Result<Self> {
|
||||||
assert_eq!(data.len(), anime.data_length());
|
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
|
/// The two packets to be written to USB
|
||||||
pub type AnimePacketType = Vec<[u8; 640]>;
|
pub type AnimePacketType = Vec<[u8; 640]>;
|
||||||
|
|
||||||
impl From<AnimeDataBuffer> for AnimePacketType {
|
impl TryFrom<AnimeDataBuffer> for AnimePacketType {
|
||||||
#[inline]
|
type Error = AnimeError;
|
||||||
fn from(anime: AnimeDataBuffer) -> Self {
|
|
||||||
assert_eq!(anime.data.len(), anime.anime.data_length());
|
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 {
|
let mut buffers = match anime.anime {
|
||||||
AnimeType::GA401 => vec![[0; 640]; 2],
|
AnimeType::GA401 => vec![[0; 640]; 2],
|
||||||
@@ -131,7 +140,7 @@ impl From<AnimeDataBuffer> for AnimePacketType {
|
|||||||
if matches!(anime.anime, AnimeType::GA402) {
|
if matches!(anime.anime, AnimeType::GA402) {
|
||||||
buffers[2][..7].copy_from_slice(&USB_PREFIX3);
|
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.
|
/// If `callback` is `Ok(true)` then `run_animation` will exit the animation loop early.
|
||||||
pub fn run_animation(
|
pub fn run_animation(
|
||||||
frames: &AnimeGif,
|
frames: &AnimeGif,
|
||||||
callback: &dyn Fn(AnimeDataBuffer) -> Result<bool, AnimeError>,
|
callback: &dyn Fn(AnimeDataBuffer) -> Result<bool>,
|
||||||
) -> Result<(), AnimeError> {
|
) -> Result<()> {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
|
|||||||
+16
-12
@@ -1,6 +1,10 @@
|
|||||||
use std::{path::Path, time::Duration};
|
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)
|
/// Mostly intended to be used with ASUS gifs, but can be used for other purposes (like images)
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -40,7 +44,7 @@ impl AnimeDiagonal {
|
|||||||
duration: Option<Duration>,
|
duration: Option<Duration>,
|
||||||
bright: f32,
|
bright: f32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self> {
|
||||||
let data = std::fs::read(path)?;
|
let data = std::fs::read(path)?;
|
||||||
let data = std::io::Cursor::new(data);
|
let data = std::io::Cursor::new(data);
|
||||||
let decoder = png_pong::Decoder::new(data)?.into_steps();
|
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
|
/// Convert to a data buffer that can be sent over dbus
|
||||||
#[inline]
|
#[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 {
|
match anime_type {
|
||||||
AnimeType::GA401 => self.into_ga401_packets(),
|
AnimeType::GA401 => self.into_ga401_packets(),
|
||||||
AnimeType::GA402 => self.into_ga402_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
|
/// Do conversion from the nested Vec in AnimeMatrix to the two required
|
||||||
/// packets suitable for sending over USB
|
/// 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()];
|
let mut buf = vec![0u8; AnimeType::GA401.data_length()];
|
||||||
|
|
||||||
buf[1..=32].copy_from_slice(&self.get_row(0, 3, 32));
|
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)
|
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 buf = vec![0u8; AnimeType::GA402.data_length()];
|
||||||
let mut start_index: usize = 0;
|
let mut start_index: usize = 0;
|
||||||
|
|
||||||
@@ -282,7 +286,7 @@ impl AnimeDiagonal {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::path::PathBuf;
|
use std::{convert::TryFrom, path::PathBuf};
|
||||||
|
|
||||||
use crate::{AnimeDiagonal, AnimePacketType, AnimeType};
|
use crate::{AnimeDiagonal, AnimePacketType, AnimeType};
|
||||||
|
|
||||||
@@ -374,8 +378,8 @@ mod tests {
|
|||||||
path.push("test/ga401-diagonal.png");
|
path.push("test/ga401-diagonal.png");
|
||||||
|
|
||||||
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA401).unwrap();
|
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA401).unwrap();
|
||||||
let data = matrix.into_data_buffer(crate::AnimeType::GA401);
|
let data = matrix.into_data_buffer(crate::AnimeType::GA401).unwrap();
|
||||||
let pkt = AnimePacketType::from(data);
|
let pkt = AnimePacketType::try_from(data).unwrap();
|
||||||
|
|
||||||
assert_eq!(pkt[0], pkt0_check);
|
assert_eq!(pkt[0], pkt0_check);
|
||||||
assert_eq!(pkt[1], pkt1_check);
|
assert_eq!(pkt[1], pkt1_check);
|
||||||
@@ -509,8 +513,8 @@ mod tests {
|
|||||||
path.push("test/ga402-diagonal.png");
|
path.push("test/ga402-diagonal.png");
|
||||||
|
|
||||||
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA402).unwrap();
|
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA402).unwrap();
|
||||||
let data = matrix.into_data_buffer(crate::AnimeType::GA402);
|
let data = matrix.into_data_buffer(crate::AnimeType::GA402).unwrap();
|
||||||
let pkt = AnimePacketType::from(data);
|
let pkt = AnimePacketType::try_from(data).unwrap();
|
||||||
|
|
||||||
assert_eq!(pkt[0], pkt0_check);
|
assert_eq!(pkt[0], pkt0_check);
|
||||||
assert_eq!(pkt[1], pkt1_check);
|
assert_eq!(pkt[1], pkt1_check);
|
||||||
@@ -654,8 +658,8 @@ mod tests {
|
|||||||
path.push("test/ga402-diagonal-fullbright.png");
|
path.push("test/ga402-diagonal-fullbright.png");
|
||||||
|
|
||||||
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA402).unwrap();
|
let matrix = AnimeDiagonal::from_png(&path, None, 255.0, AnimeType::GA402).unwrap();
|
||||||
let data = matrix.into_data_buffer(crate::AnimeType::GA402);
|
let data = matrix.into_data_buffer(crate::AnimeType::GA402).unwrap();
|
||||||
let pkt = AnimePacketType::from(data);
|
let pkt = AnimePacketType::try_from(data).unwrap();
|
||||||
|
|
||||||
assert_eq!(pkt[0], pkt0_check);
|
assert_eq!(pkt[0], pkt0_check);
|
||||||
assert_eq!(pkt[1], pkt1_check);
|
assert_eq!(pkt[1], pkt1_check);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ use png_pong::decode::Error as PngError;
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
pub type Result<T> = std::result::Result<T, AnimeError>;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum AnimeError {
|
pub enum AnimeError {
|
||||||
NoFrames,
|
NoFrames,
|
||||||
@@ -17,6 +19,9 @@ pub enum AnimeError {
|
|||||||
NoDevice,
|
NoDevice,
|
||||||
UnsupportedDevice,
|
UnsupportedDevice,
|
||||||
InvalidBrightness(f32),
|
InvalidBrightness(f32),
|
||||||
|
DataBufferLength,
|
||||||
|
PixelGifWidth(usize),
|
||||||
|
PixelGifHeight(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for AnimeError {
|
impl fmt::Display for AnimeError {
|
||||||
@@ -36,12 +41,23 @@ impl fmt::Display for AnimeError {
|
|||||||
AnimeError::Dbus(detail) => write!(f, "{}", detail),
|
AnimeError::Dbus(detail) => write!(f, "{}", detail),
|
||||||
AnimeError::Udev(deets, error) => write!(f, "udev {}: {}", deets, error),
|
AnimeError::Udev(deets, error) => write!(f, "udev {}: {}", deets, error),
|
||||||
AnimeError::NoDevice => write!(f, "No AniMe Matrix device found"),
|
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::UnsupportedDevice => write!(f, "Unsupported AniMe Matrix device found"),
|
||||||
AnimeError::InvalidBrightness(bright) => write!(
|
AnimeError::InvalidBrightness(bright) => write!(
|
||||||
f,
|
f,
|
||||||
"Image brightness must be between 0.0 and 1.0 (inclusive), was {}",
|
"Image brightness must be between 0.0 and 1.0 (inclusive), was {}",
|
||||||
bright
|
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)
|
AnimeError::Gif(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<AnimeError> for zbus::fdo::Error {
|
||||||
|
#[inline]
|
||||||
|
fn from(err: AnimeError) -> Self {
|
||||||
|
zbus::fdo::Error::Failed(format!("{}", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+22
-11
@@ -1,8 +1,10 @@
|
|||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use std::convert::TryFrom;
|
||||||
use std::{fs::File, path::Path, time::Duration};
|
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)]
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||||
pub struct AnimeFrame {
|
pub struct AnimeFrame {
|
||||||
@@ -93,7 +95,7 @@ impl AnimeGif {
|
|||||||
duration: AnimTime,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self> {
|
||||||
let mut matrix = AnimeDiagonal::new(anime_type, None);
|
let mut matrix = AnimeDiagonal::new(anime_type, None);
|
||||||
|
|
||||||
let mut decoder = gif::DecodeOptions::new();
|
let mut decoder = gif::DecodeOptions::new();
|
||||||
@@ -116,13 +118,22 @@ impl AnimeGif {
|
|||||||
// should be t but not in some gifs? What, ASUS, what?
|
// should be t but not in some gifs? What, ASUS, what?
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
matrix.get_mut()[y + frame.top as usize][x + frame.left as usize] =
|
let tmp = matrix.get_mut();
|
||||||
(px[0] as f32 * brightness) as u8;
|
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 {
|
frames.push(AnimeFrame {
|
||||||
data: matrix.into_data_buffer(anime_type),
|
data: matrix.into_data_buffer(anime_type)?,
|
||||||
delay: Duration::from_millis(wait as u64),
|
delay: Duration::from_millis(wait as u64),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -136,7 +147,7 @@ impl AnimeGif {
|
|||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
duration: AnimTime,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self> {
|
||||||
let image = AnimeDiagonal::from_png(file_name, None, brightness, anime_type)?;
|
let image = AnimeDiagonal::from_png(file_name, None, brightness, anime_type)?;
|
||||||
|
|
||||||
let mut total = Duration::from_millis(1000);
|
let mut total = Duration::from_millis(1000);
|
||||||
@@ -150,7 +161,7 @@ impl AnimeGif {
|
|||||||
let frame_count = total.as_millis() / 30;
|
let frame_count = total.as_millis() / 30;
|
||||||
|
|
||||||
let single = AnimeFrame {
|
let single = AnimeFrame {
|
||||||
data: image.into_data_buffer(anime_type),
|
data: image.into_data_buffer(anime_type)?,
|
||||||
delay: Duration::from_millis(30),
|
delay: Duration::from_millis(30),
|
||||||
};
|
};
|
||||||
let frames = vec![single; frame_count as usize];
|
let frames = vec![single; frame_count as usize];
|
||||||
@@ -169,7 +180,7 @@ impl AnimeGif {
|
|||||||
duration: AnimTime,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self> {
|
||||||
let mut frames = Vec::new();
|
let mut frames = Vec::new();
|
||||||
|
|
||||||
let mut decoder = gif::DecodeOptions::new();
|
let mut decoder = gif::DecodeOptions::new();
|
||||||
@@ -225,7 +236,7 @@ impl AnimeGif {
|
|||||||
image.update();
|
image.update();
|
||||||
|
|
||||||
frames.push(AnimeFrame {
|
frames.push(AnimeFrame {
|
||||||
data: <AnimeDataBuffer>::from(&image),
|
data: <AnimeDataBuffer>::try_from(&image)?,
|
||||||
delay: Duration::from_millis(wait as u64),
|
delay: Duration::from_millis(wait as u64),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -244,7 +255,7 @@ impl AnimeGif {
|
|||||||
duration: AnimTime,
|
duration: AnimTime,
|
||||||
brightness: f32,
|
brightness: f32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self> {
|
||||||
let image =
|
let image =
|
||||||
AnimeImage::from_png(file_name, scale, angle, translation, brightness, anime_type)?;
|
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 frame_count = total.as_millis() / 30;
|
||||||
|
|
||||||
let single = AnimeFrame {
|
let single = AnimeFrame {
|
||||||
data: <AnimeDataBuffer>::from(&image),
|
data: <AnimeDataBuffer>::try_from(&image)?,
|
||||||
delay: Duration::from_millis(30),
|
delay: Duration::from_millis(30),
|
||||||
};
|
};
|
||||||
let frames = vec![single; frame_count as usize];
|
let frames = vec![single; frame_count as usize];
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
use crate::data::AnimeDataBuffer;
|
use crate::data::AnimeDataBuffer;
|
||||||
|
use crate::error::{AnimeError, Result};
|
||||||
use crate::{AnimeImage, AnimeType};
|
use crate::{AnimeImage, AnimeType};
|
||||||
|
|
||||||
// TODO: Adjust these sizes as WIDTH_GA401 WIDTH_GA402
|
// 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
|
/// Do conversion from the nested Vec in AniMeMatrix to the two required
|
||||||
/// packets suitable for sending over USB
|
/// packets suitable for sending over USB
|
||||||
#[inline]
|
fn try_from(anime: AnimeGrid) -> Result<Self> {
|
||||||
fn from(anime: AnimeGrid) -> Self {
|
|
||||||
let mut buf = vec![0u8; anime.anime_type.data_length()];
|
let mut buf = vec![0u8; anime.anime_type.data_length()];
|
||||||
|
|
||||||
for (idx, pos) in AnimeImage::generate_image_positioning(anime.anime_type)
|
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 = [
|
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,
|
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,
|
||||||
|
|||||||
+18
-12
@@ -1,9 +1,13 @@
|
|||||||
use std::path::Path;
|
use std::{convert::TryFrom, path::Path};
|
||||||
|
|
||||||
pub use glam::Vec2;
|
pub use glam::Vec2;
|
||||||
use glam::{Mat3, Vec3};
|
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
|
/// A single greyscale + alpha pixel in the image
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
@@ -83,7 +87,7 @@ impl AnimeImage {
|
|||||||
pixels: Vec<Pixel>,
|
pixels: Vec<Pixel>,
|
||||||
width: u32,
|
width: u32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self> {
|
||||||
if bright < 0.0 || bright > 1.0 {
|
if bright < 0.0 || bright > 1.0 {
|
||||||
return Err(AnimeError::InvalidBrightness(bright));
|
return Err(AnimeError::InvalidBrightness(bright));
|
||||||
}
|
}
|
||||||
@@ -388,7 +392,7 @@ impl AnimeImage {
|
|||||||
translation: Vec2,
|
translation: Vec2,
|
||||||
bright: f32,
|
bright: f32,
|
||||||
anime_type: AnimeType,
|
anime_type: AnimeType,
|
||||||
) -> Result<Self, AnimeError> {
|
) -> Result<Self> {
|
||||||
let data = std::fs::read(path)?;
|
let data = std::fs::read(path)?;
|
||||||
let data = std::io::Cursor::new(data);
|
let data = std::io::Cursor::new(data);
|
||||||
let decoder = png_pong::Decoder::new(data)?.into_steps();
|
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
|
/// Do conversion from the nested Vec in AnimeDataBuffer to the two required
|
||||||
/// packets suitable for sending over USB
|
/// packets suitable for sending over USB
|
||||||
#[inline]
|
fn try_from(leds: &AnimeImage) -> Result<Self> {
|
||||||
fn from(leds: &AnimeImage) -> Self {
|
|
||||||
let mut l: Vec<u8> = leds
|
let mut l: Vec<u8> = leds
|
||||||
.led_pos
|
.led_pos
|
||||||
.iter()
|
.iter()
|
||||||
@@ -506,7 +511,7 @@ impl From<&AnimeImage> for AnimeDataBuffer {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::path::PathBuf;
|
use std::{convert::TryFrom, path::PathBuf};
|
||||||
|
|
||||||
use crate::{image::*, AnimTime, AnimeGif, AnimePacketType};
|
use crate::{image::*, AnimTime, AnimeGif, AnimePacketType};
|
||||||
|
|
||||||
@@ -731,10 +736,11 @@ mod tests {
|
|||||||
vec![Pixel::default(); 1000],
|
vec![Pixel::default(); 1000],
|
||||||
100,
|
100,
|
||||||
AnimeType::GA402,
|
AnimeType::GA402,
|
||||||
);
|
)
|
||||||
|
.unwrap();
|
||||||
matrix._edge_outline();
|
matrix._edge_outline();
|
||||||
let data = AnimeDataBuffer::from(&matrix);
|
let data = AnimeDataBuffer::try_from(&matrix).unwrap();
|
||||||
let pkt = AnimePacketType::from(data);
|
let pkt = AnimePacketType::try_from(data).unwrap();
|
||||||
|
|
||||||
assert_eq!(pkt[0], pkt0_check);
|
assert_eq!(pkt[0], pkt0_check);
|
||||||
assert_eq!(pkt[1], pkt1_check);
|
assert_eq!(pkt[1], pkt1_check);
|
||||||
@@ -758,6 +764,6 @@ mod tests {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
matrix.frames()[0].frame();
|
matrix.frames()[0].frame();
|
||||||
let _pkt = AnimePacketType::from(matrix.frames()[0].frame().clone());
|
let _pkt = AnimePacketType::try_from(matrix.frames()[0].frame().clone()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use std::{path::PathBuf, time::Duration};
|
|
||||||
|
|
||||||
use glam::Vec2;
|
use glam::Vec2;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
use std::{path::PathBuf, time::Duration};
|
||||||
|
|
||||||
use crate::{
|
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
|
/// All the possible AniMe actions that can be used. This enum is intended to be
|
||||||
@@ -65,10 +65,7 @@ pub enum ActionData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActionData {
|
impl ActionData {
|
||||||
pub fn from_anime_action(
|
pub fn from_anime_action(anime_type: AnimeType, action: &ActionLoader) -> Result<ActionData> {
|
||||||
anime_type: AnimeType,
|
|
||||||
action: &ActionLoader,
|
|
||||||
) -> Result<ActionData, AnimeError> {
|
|
||||||
let a = match action {
|
let a = match action {
|
||||||
ActionLoader::AsusAnimation {
|
ActionLoader::AsusAnimation {
|
||||||
file,
|
file,
|
||||||
@@ -87,7 +84,7 @@ impl ActionData {
|
|||||||
} => match time {
|
} => match time {
|
||||||
AnimTime::Infinite => {
|
AnimTime::Infinite => {
|
||||||
let image = AnimeDiagonal::from_png(file, None, *brightness, anime_type)?;
|
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::Image(Box::new(data))
|
||||||
}
|
}
|
||||||
_ => ActionData::Animation(AnimeGif::from_diagonal_png(
|
_ => ActionData::Animation(AnimeGif::from_diagonal_png(
|
||||||
@@ -147,7 +144,7 @@ impl ActionData {
|
|||||||
*brightness,
|
*brightness,
|
||||||
anime_type,
|
anime_type,
|
||||||
)?;
|
)?;
|
||||||
let data = <AnimeDataBuffer>::from(&image);
|
let data = <AnimeDataBuffer>::try_from(&image)?;
|
||||||
ActionData::Image(Box::new(data))
|
ActionData::Image(Box::new(data))
|
||||||
}
|
}
|
||||||
_ => ActionData::Animation(AnimeGif::from_png(
|
_ => ActionData::Animation(AnimeGif::from_png(
|
||||||
@@ -180,7 +177,7 @@ impl Sequences {
|
|||||||
/// Use a base `AnimeAction` to generate the precomputed data and insert in to
|
/// Use a base `AnimeAction` to generate the precomputed data and insert in to
|
||||||
/// the run buffer
|
/// the run buffer
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn insert(&mut self, index: usize, action: &ActionLoader) -> Result<(), AnimeError> {
|
pub fn insert(&mut self, index: usize, action: &ActionLoader) -> Result<()> {
|
||||||
self.0
|
self.0
|
||||||
.insert(index, ActionData::from_anime_action(self.1, action)?);
|
.insert(index, ActionData::from_anime_action(self.1, action)?);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ pub fn get_anime_type() -> Result<AnimeType, AnimeError> {
|
|||||||
let dmi = sysfs_class::DmiId::default();
|
let dmi = sysfs_class::DmiId::default();
|
||||||
let board_name = dmi.board_name()?;
|
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);
|
return Ok(AnimeType::GA401);
|
||||||
} else if board_name.contains("GA402R") {
|
} else if board_name.contains("GA402R") {
|
||||||
return Ok(AnimeType::GA402);
|
return Ok(AnimeType::GA402);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rog_aura"
|
name = "rog_aura"
|
||||||
version = "1.1.1"
|
version = "1.2.0"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Luke <luke@ljones.dev>"]
|
authors = ["Luke <luke@ljones.dev>"]
|
||||||
|
|||||||
@@ -16,3 +16,12 @@ pub mod error;
|
|||||||
pub const LED_MSG_LEN: usize = 17;
|
pub const LED_MSG_LEN: usize = 17;
|
||||||
|
|
||||||
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
|
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];
|
||||||
|
|||||||
+202
-88
@@ -20,37 +20,110 @@ pub const fn aura_brightness_bytes(brightness: u8) -> [u8; 17] {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enable/disable LED control in various states such as
|
/// This struct is intended as a helper to pass args to generic dbus interface
|
||||||
/// when the device is awake, suspended, shutting down or
|
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||||
/// booting.
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
///
|
pub struct AuraPowerDev {
|
||||||
/// ```text
|
pub x1866: Vec<AuraDev1866>,
|
||||||
// byte 4 in the USB packet is for keyboard + logo power states
|
pub x19b6: Vec<AuraDev19b6>,
|
||||||
// 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
|
/// # Bits for older 0x1866 keyboard model
|
||||||
// | 1 | 2 | hex | action | bit |
|
///
|
||||||
// |------|------|-----|----------------------|-------|
|
/// Keybord and Lightbar require Awake, Boot and Sleep apply to both
|
||||||
// | 0000 | 0010 | 02 | lightbar off boot | bit 2 |
|
/// Keybord and Lightbar regardless of if either are enabled (or Awake is enabled)
|
||||||
// | 0000 | 0100 | 04 | lightbar on | bit 3 |
|
///
|
||||||
// | 0000 | 1000 | 08 | lightbar off sleep | bit 4 |
|
/// | Byte 1 | Byte 2 | Byte 3 | function | hex |
|
||||||
// | 0001 | 0000 | 10 | lightbar shtdn off | bit 5 |
|
/// |------------|------------|------------|----------|----------|
|
||||||
|
/// | 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))]
|
#[cfg_attr(feature = "dbus", derive(Type))]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
|
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, Serialize, Deserialize)]
|
||||||
#[repr(u16)]
|
#[repr(u16)]
|
||||||
pub enum AuraControl {
|
pub enum AuraDev19b6 {
|
||||||
BootLogo = 1,
|
BootLogo = 1,
|
||||||
BootKeyb = 1 << 1,
|
BootKeyb = 1 << 1,
|
||||||
AwakeLogo = 1 << 2,
|
AwakeLogo = 1 << 2,
|
||||||
@@ -65,133 +138,174 @@ pub enum AuraControl {
|
|||||||
ShutdownBar = 1 << 7 + 5,
|
ShutdownBar = 1 << 7 + 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<AuraControl> for u16 {
|
impl From<AuraDev19b6> for u16 {
|
||||||
fn from(a: AuraControl) -> Self {
|
fn from(a: AuraDev19b6) -> Self {
|
||||||
a as u16
|
a as u16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuraControl {
|
impl AuraDev19b6 {
|
||||||
pub fn to_bytes(control: &[Self]) -> [u8; 2] {
|
pub fn to_bytes(control: &[Self]) -> [u8; 3] {
|
||||||
let mut a: u16 = 0;
|
let mut a: u16 = 0;
|
||||||
control.iter().for_each(|n| {
|
control.iter().for_each(|n| {
|
||||||
a |= *n as u16;
|
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;
|
type Output = u16;
|
||||||
|
|
||||||
fn bitor(self, rhs: AuraControl) -> Self::Output {
|
fn bitor(self, rhs: AuraDev19b6) -> Self::Output {
|
||||||
return self as u16 | rhs as u16;
|
return self as u16 | rhs as u16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BitAnd<AuraControl> for AuraControl {
|
impl BitAnd<AuraDev19b6> for AuraDev19b6 {
|
||||||
type Output = u16;
|
type Output = u16;
|
||||||
|
|
||||||
fn bitand(self, rhs: AuraControl) -> Self::Output {
|
fn bitand(self, rhs: AuraDev19b6) -> Self::Output {
|
||||||
return self as u16 & rhs as u16;
|
return self as u16 & rhs as u16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::usb::AuraControl;
|
use crate::usb::AuraDev19b6;
|
||||||
|
|
||||||
|
use super::AuraDev1866;
|
||||||
|
|
||||||
#[test]
|
#[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
|
// All on
|
||||||
let byte1 = [
|
let byte1 = [
|
||||||
AuraControl::BootLogo,
|
AuraDev19b6::BootLogo,
|
||||||
AuraControl::BootKeyb,
|
AuraDev19b6::BootKeyb,
|
||||||
AuraControl::SleepLogo,
|
AuraDev19b6::SleepLogo,
|
||||||
AuraControl::SleepKeyb,
|
AuraDev19b6::SleepKeyb,
|
||||||
AuraControl::AwakeLogo,
|
AuraDev19b6::AwakeLogo,
|
||||||
AuraControl::AwakeKeyb,
|
AuraDev19b6::AwakeKeyb,
|
||||||
AuraControl::ShutdownLogo,
|
AuraDev19b6::ShutdownLogo,
|
||||||
AuraControl::ShutdownKeyb,
|
AuraDev19b6::ShutdownKeyb,
|
||||||
];
|
];
|
||||||
let bytes = AuraControl::to_bytes(&byte1);
|
let bytes = AuraDev19b6::to_bytes(&byte1);
|
||||||
println!("{:08b}", bytes[0]);
|
println!("{:08b}", bytes[0]);
|
||||||
assert_eq!(bytes[0], 0xff);
|
assert_eq!(bytes[0], 0xff);
|
||||||
|
|
||||||
//
|
//
|
||||||
let byte1 = [
|
let byte1 = [
|
||||||
// AuraControl::BootLogo,
|
// AuraControl::BootLogo,
|
||||||
AuraControl::BootKeyb,
|
AuraDev19b6::BootKeyb,
|
||||||
AuraControl::SleepLogo,
|
AuraDev19b6::SleepLogo,
|
||||||
AuraControl::SleepKeyb,
|
AuraDev19b6::SleepKeyb,
|
||||||
AuraControl::AwakeLogo,
|
AuraDev19b6::AwakeLogo,
|
||||||
AuraControl::AwakeKeyb,
|
AuraDev19b6::AwakeKeyb,
|
||||||
AuraControl::ShutdownLogo,
|
AuraDev19b6::ShutdownLogo,
|
||||||
AuraControl::ShutdownKeyb,
|
AuraDev19b6::ShutdownKeyb,
|
||||||
];
|
];
|
||||||
let bytes = AuraControl::to_bytes(&byte1);
|
let bytes = AuraDev19b6::to_bytes(&byte1);
|
||||||
println!("{:08b}", bytes[0]);
|
println!("{:08b}", bytes[0]);
|
||||||
assert_eq!(bytes[0], 0xfe);
|
assert_eq!(bytes[0], 0xfe);
|
||||||
|
|
||||||
let byte1 = [
|
let byte1 = [
|
||||||
AuraControl::BootLogo,
|
AuraDev19b6::BootLogo,
|
||||||
// AuraControl::BootKeyb,
|
// AuraControl::BootKeyb,
|
||||||
AuraControl::SleepLogo,
|
AuraDev19b6::SleepLogo,
|
||||||
AuraControl::SleepKeyb,
|
AuraDev19b6::SleepKeyb,
|
||||||
AuraControl::AwakeLogo,
|
AuraDev19b6::AwakeLogo,
|
||||||
AuraControl::AwakeKeyb,
|
AuraDev19b6::AwakeKeyb,
|
||||||
AuraControl::ShutdownLogo,
|
AuraDev19b6::ShutdownLogo,
|
||||||
AuraControl::ShutdownKeyb,
|
AuraDev19b6::ShutdownKeyb,
|
||||||
];
|
];
|
||||||
let bytes = AuraControl::to_bytes(&byte1);
|
let bytes = AuraDev19b6::to_bytes(&byte1);
|
||||||
println!("{:08b}", bytes[0]);
|
println!("{:08b}", bytes[0]);
|
||||||
assert_eq!(bytes[0], 0xfd);
|
assert_eq!(bytes[0], 0xfd);
|
||||||
|
|
||||||
let byte1 = [
|
let byte1 = [
|
||||||
AuraControl::BootLogo,
|
AuraDev19b6::BootLogo,
|
||||||
AuraControl::BootKeyb,
|
AuraDev19b6::BootKeyb,
|
||||||
// AuraControl::SleepLogo,
|
// AuraControl::SleepLogo,
|
||||||
AuraControl::SleepKeyb,
|
AuraDev19b6::SleepKeyb,
|
||||||
AuraControl::AwakeLogo,
|
AuraDev19b6::AwakeLogo,
|
||||||
AuraControl::AwakeKeyb,
|
AuraDev19b6::AwakeKeyb,
|
||||||
AuraControl::ShutdownLogo,
|
AuraDev19b6::ShutdownLogo,
|
||||||
AuraControl::ShutdownKeyb,
|
AuraDev19b6::ShutdownKeyb,
|
||||||
];
|
];
|
||||||
let bytes = AuraControl::to_bytes(&byte1);
|
let bytes = AuraDev19b6::to_bytes(&byte1);
|
||||||
println!("{:08b}", bytes[0]);
|
println!("{:08b}", bytes[0]);
|
||||||
assert_eq!(bytes[0], 0xef);
|
assert_eq!(bytes[0], 0xef);
|
||||||
|
|
||||||
let byte1 = [
|
let byte1 = [
|
||||||
AuraControl::BootLogo,
|
AuraDev19b6::BootLogo,
|
||||||
AuraControl::BootKeyb,
|
AuraDev19b6::BootKeyb,
|
||||||
AuraControl::SleepLogo,
|
AuraDev19b6::SleepLogo,
|
||||||
// AuraControl::SleepKeyb,
|
// AuraControl::SleepKeyb,
|
||||||
AuraControl::AwakeLogo,
|
AuraDev19b6::AwakeLogo,
|
||||||
AuraControl::AwakeKeyb,
|
AuraDev19b6::AwakeKeyb,
|
||||||
AuraControl::ShutdownLogo,
|
AuraDev19b6::ShutdownLogo,
|
||||||
AuraControl::ShutdownKeyb,
|
AuraDev19b6::ShutdownKeyb,
|
||||||
];
|
];
|
||||||
let bytes = AuraControl::to_bytes(&byte1);
|
let bytes = AuraDev19b6::to_bytes(&byte1);
|
||||||
println!("{:08b}", bytes[0]);
|
println!("{:08b}", bytes[0]);
|
||||||
assert_eq!(bytes[0], 0xdf);
|
assert_eq!(bytes[0], 0xdf);
|
||||||
|
|
||||||
let byte2 = [
|
let byte2 = [
|
||||||
AuraControl::AwakeBar,
|
AuraDev19b6::AwakeBar,
|
||||||
AuraControl::BootBar,
|
AuraDev19b6::BootBar,
|
||||||
AuraControl::SleepBar,
|
AuraDev19b6::SleepBar,
|
||||||
AuraControl::ShutdownBar,
|
AuraDev19b6::ShutdownBar,
|
||||||
];
|
];
|
||||||
let bytes = AuraControl::to_bytes(&byte2);
|
let bytes = AuraDev19b6::to_bytes(&byte2);
|
||||||
println!("{:08b}", bytes[1]);
|
println!("{:08b}", bytes[1]);
|
||||||
assert_eq!(bytes[1], 0x1e);
|
assert_eq!(bytes[1], 0x1e);
|
||||||
|
|
||||||
let byte2 = [
|
let byte2 = [
|
||||||
AuraControl::AwakeBar,
|
AuraDev19b6::AwakeBar,
|
||||||
AuraControl::BootBar,
|
AuraDev19b6::BootBar,
|
||||||
// AuraControl::SleepBar,
|
// AuraControl::SleepBar,
|
||||||
AuraControl::ShutdownBar,
|
AuraDev19b6::ShutdownBar,
|
||||||
];
|
];
|
||||||
let bytes = AuraControl::to_bytes(&byte2);
|
let bytes = AuraDev19b6::to_bytes(&byte2);
|
||||||
println!("{:08b}", bytes[1]);
|
println!("{:08b}", bytes[1]);
|
||||||
assert_eq!(bytes[1], 0x16);
|
assert_eq!(bytes[1], 0x16);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! # DBus interface proxy for: `org.asuslinux.Daemon`
|
//! # DBus interface proxy for: `org.asuslinux.Daemon`
|
||||||
//!
|
//!
|
||||||
//! This code was generated by `zbus-xmlgen` `1.0.0` from DBus introspection data.
|
//! 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.
|
//! You may prefer to adapt it, instead of using it verbatim.
|
||||||
//!
|
//!
|
||||||
@@ -22,13 +22,13 @@
|
|||||||
use zbus::{blocking::Connection, Result};
|
use zbus::{blocking::Connection, Result};
|
||||||
use zbus_macros::dbus_proxy;
|
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
|
const BLOCKING_TIME: u64 = 40; // 100ms = 10 FPS, max 50ms = 20 FPS, 40ms = 25 FPS
|
||||||
|
|
||||||
#[dbus_proxy(
|
#[dbus_proxy(
|
||||||
interface = "org.asuslinux.Daemon",
|
interface = "org.asuslinux.Daemon",
|
||||||
default_path = "/org/asuslinux/Led"
|
default_path = "/org/asuslinux/Aura"
|
||||||
)]
|
)]
|
||||||
trait Led {
|
trait Led {
|
||||||
/// NextLedMode method
|
/// NextLedMode method
|
||||||
@@ -49,16 +49,14 @@ trait Led {
|
|||||||
/// SetLedMode method
|
/// SetLedMode method
|
||||||
fn set_led_mode(&self, effect: &AuraEffect) -> zbus::Result<()>;
|
fn set_led_mode(&self, effect: &AuraEffect) -> zbus::Result<()>;
|
||||||
|
|
||||||
fn set_leds_enabled(&self, enabled: Vec<AuraControl>) -> zbus::Result<()>;
|
fn set_leds_power(&self, options: AuraPowerDev, enabled: bool) -> zbus::Result<()>;
|
||||||
|
|
||||||
fn set_leds_disabled(&self, disabled: Vec<AuraControl>) -> zbus::Result<()>;
|
|
||||||
|
|
||||||
/// NotifyLed signal
|
/// NotifyLed signal
|
||||||
#[dbus_proxy(signal)]
|
#[dbus_proxy(signal)]
|
||||||
fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>;
|
fn notify_led(&self, data: AuraEffect) -> zbus::Result<()>;
|
||||||
|
|
||||||
#[dbus_proxy(signal)]
|
#[dbus_proxy(signal)]
|
||||||
fn notify_power_states(&self, data: Vec<AuraControl>) -> zbus::Result<()>;
|
fn notify_power_states(&self, data: AuraPowerDev) -> zbus::Result<()>;
|
||||||
|
|
||||||
/// LedBrightness property
|
/// LedBrightness property
|
||||||
#[dbus_proxy(property)]
|
#[dbus_proxy(property)]
|
||||||
@@ -72,8 +70,9 @@ trait Led {
|
|||||||
#[dbus_proxy(property)]
|
#[dbus_proxy(property)]
|
||||||
fn led_modes(&self) -> zbus::Result<String>;
|
fn led_modes(&self) -> zbus::Result<String>;
|
||||||
|
|
||||||
#[dbus_proxy(property)]
|
// As property doesn't work for AuraPowerDev (complexity of serialization?)
|
||||||
fn leds_enabled(&self) -> zbus::Result<Vec<u8>>;
|
// #[dbus_proxy(property)]
|
||||||
|
fn leds_enabled(&self) -> zbus::Result<AuraPowerDev>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LedProxyPerkey<'a>(LedProxyBlocking<'a>);
|
pub struct LedProxyPerkey<'a>(LedProxyBlocking<'a>);
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ trait RogBios {
|
|||||||
/// SetPostBootSound method
|
/// SetPostBootSound method
|
||||||
fn set_post_boot_sound(&self, on: bool) -> zbus::Result<()>;
|
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
|
/// NotifyDedicatedGraphicMode signal
|
||||||
#[dbus_proxy(signal)]
|
#[dbus_proxy(signal)]
|
||||||
fn notify_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>;
|
fn notify_dedicated_graphic_mode(&self, dedicated: bool) -> zbus::Result<()>;
|
||||||
@@ -45,4 +51,8 @@ trait RogBios {
|
|||||||
/// NotifyPostBootSound signal
|
/// NotifyPostBootSound signal
|
||||||
#[dbus_proxy(signal)]
|
#[dbus_proxy(signal)]
|
||||||
fn notify_post_boot_sound(&self, sound: bool) -> zbus::Result<()>;
|
fn notify_post_boot_sound(&self, sound: bool) -> zbus::Result<()>;
|
||||||
|
|
||||||
|
/// NotifyPanelOverdrive signal
|
||||||
|
#[dbus_proxy(signal)]
|
||||||
|
fn notify_panel_overdrive(&self, overdrive: bool) -> zbus::Result<()>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rog_supported"
|
name = "rog_supported"
|
||||||
version = "4.0.0"
|
version = "4.2.1"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Luke <luke@ljones.dev>"]
|
authors = ["Luke <luke@ljones.dev>"]
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ pub struct PlatformProfileFunctions {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Type, Debug)]
|
#[derive(Serialize, Deserialize, Type, Debug)]
|
||||||
pub struct LedSupportedFunctions {
|
pub struct LedSupportedFunctions {
|
||||||
|
pub prod_id: String,
|
||||||
pub brightness_set: bool,
|
pub brightness_set: bool,
|
||||||
pub stock_led_modes: Vec<AuraModeNum>,
|
pub stock_led_modes: Vec<AuraModeNum>,
|
||||||
pub multizone_led_mode: Vec<AuraZone>,
|
pub multizone_led_mode: Vec<AuraZone>,
|
||||||
@@ -38,8 +39,11 @@ pub struct LedSupportedFunctions {
|
|||||||
|
|
||||||
#[derive(Serialize, Deserialize, Type, Debug)]
|
#[derive(Serialize, Deserialize, Type, Debug)]
|
||||||
pub struct RogBiosSupportedFunctions {
|
pub struct RogBiosSupportedFunctions {
|
||||||
pub post_sound_toggle: bool,
|
pub post_sound: bool,
|
||||||
pub dedicated_gfx_toggle: bool,
|
pub dedicated_gfx: bool,
|
||||||
|
pub panel_overdrive: bool,
|
||||||
|
pub dgpu_disable: bool,
|
||||||
|
pub egpu_enable: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for SupportedFunctions {
|
impl fmt::Display for SupportedFunctions {
|
||||||
@@ -87,7 +91,11 @@ impl fmt::Display for LedSupportedFunctions {
|
|||||||
impl fmt::Display for RogBiosSupportedFunctions {
|
impl fmt::Display for RogBiosSupportedFunctions {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
writeln!(f, "ROG BIOS:")?;
|
writeln!(f, "ROG BIOS:")?;
|
||||||
writeln!(f, "\tPOST sound toggle: {}", self.post_sound_toggle)?;
|
writeln!(f, "\tPOST sound switch: {}", self.post_sound)?;
|
||||||
writeln!(f, "\tDedicated GFX toggle: {}", self.dedicated_gfx_toggle)
|
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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user