diff --git a/CHANGELOG.md b/CHANGELOG.md index b0a7118d..18df1aaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Minor updates in aura controller to ensure configs are updated if the support file changes - Don't panic if -ENODEV on fan_curve enable - Adjust the G513Q support to match what is on the asus website. +- Adjust init sequence of anime to prevent accidental use of Slash as Anime ## [v6.0.9] diff --git a/asusctl/examples/anime-diag-png.rs b/asusctl/examples/anime-diag-png.rs index b4285601..0440840b 100644 --- a/asusctl/examples/anime-diag-png.rs +++ b/asusctl/examples/anime-diag-png.rs @@ -3,7 +3,7 @@ use std::error::Error; use std::path::Path; use std::process::exit; -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::{AnimeDiagonal, AnimeType}; use rog_dbus::zbus_anime::AnimeProxyBlocking; use zbus::blocking::Connection; @@ -26,7 +26,7 @@ fn main() -> Result<(), Box> { AnimeType::GA401, )?; - let anime_type = get_anime_type()?; + let anime_type = get_maybe_anime_type()?; proxy.write(matrix.into_data_buffer(anime_type)?).unwrap(); diff --git a/asusctl/examples/anime-diag.rs b/asusctl/examples/anime-diag.rs index 21cc1722..98f04a7d 100644 --- a/asusctl/examples/anime-diag.rs +++ b/asusctl/examples/anime-diag.rs @@ -1,7 +1,7 @@ use std::thread::sleep; use std::time::Duration; -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::{AnimeDiagonal, AnimeType}; use rog_dbus::zbus_anime::AnimeProxyBlocking; use zbus::blocking::Connection; @@ -29,7 +29,7 @@ fn main() { } } - let anime_type = get_anime_type().unwrap(); + let anime_type = get_maybe_anime_type().unwrap(); proxy .write(matrix.into_data_buffer(anime_type).unwrap()) .unwrap(); diff --git a/asusctl/examples/anime-gif.rs b/asusctl/examples/anime-gif.rs index 044b35ba..4f0b5847 100644 --- a/asusctl/examples/anime-gif.rs +++ b/asusctl/examples/anime-gif.rs @@ -2,7 +2,7 @@ use std::env; use std::path::Path; use std::thread::sleep; -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::{ActionData, ActionLoader, Sequences}; use rog_dbus::zbus_anime::AnimeProxyBlocking; use zbus::blocking::Connection; @@ -19,7 +19,7 @@ fn main() { let path = Path::new(&args[1]); let brightness = args[2].parse::().unwrap(); - let anime_type = get_anime_type().unwrap(); + let anime_type = get_maybe_anime_type().unwrap(); let mut seq = Sequences::new(anime_type); seq.insert( 0, diff --git a/asusctl/examples/anime-grid.rs b/asusctl/examples/anime-grid.rs index 83def5ea..299f8d66 100644 --- a/asusctl/examples/anime-grid.rs +++ b/asusctl/examples/anime-grid.rs @@ -1,6 +1,6 @@ use std::convert::TryFrom; -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::{AnimeDataBuffer, AnimeGrid}; use rog_dbus::zbus_anime::AnimeProxyBlocking; use zbus::blocking::Connection; @@ -14,7 +14,7 @@ fn main() { let conn = Connection::system().unwrap(); let proxy = AnimeProxyBlocking::new(&conn).unwrap(); - let anime_type = get_anime_type().unwrap(); + let anime_type = get_maybe_anime_type().unwrap(); let mut matrix = AnimeGrid::new(anime_type); let tmp = matrix.get_mut(); diff --git a/asusctl/examples/anime-outline.rs b/asusctl/examples/anime-outline.rs index 140427a6..1e6d9545 100644 --- a/asusctl/examples/anime-outline.rs +++ b/asusctl/examples/anime-outline.rs @@ -1,4 +1,4 @@ -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::AnimeDataBuffer; use rog_dbus::zbus_anime::AnimeProxyBlocking; use zbus::blocking::Connection; @@ -9,7 +9,7 @@ use zbus::blocking::Connection; fn main() { let conn = Connection::system().unwrap(); let proxy = AnimeProxyBlocking::new(&conn).unwrap(); - let anime_type = get_anime_type().unwrap(); + let anime_type = get_maybe_anime_type().unwrap(); let mut matrix = AnimeDataBuffer::new(anime_type); matrix.data_mut()[1] = 100; // start = 1 for n in matrix.data_mut()[2..32].iter_mut() { diff --git a/asusctl/examples/anime-png.rs b/asusctl/examples/anime-png.rs index add92456..915ff9b5 100644 --- a/asusctl/examples/anime-png.rs +++ b/asusctl/examples/anime-png.rs @@ -4,7 +4,7 @@ use std::error::Error; use std::path::Path; use std::process::exit; -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2}; use rog_dbus::zbus_anime::AnimeProxyBlocking; use zbus::blocking::Connection; @@ -20,7 +20,7 @@ fn main() -> Result<(), Box> { exit(-1); } - let anime_type = get_anime_type()?; + let anime_type = get_maybe_anime_type()?; let matrix = AnimeImage::from_png( Path::new(&args[1]), args[2].parse::().unwrap(), diff --git a/asusctl/examples/anime-spinning.rs b/asusctl/examples/anime-spinning.rs index 611e7db2..2a700a64 100644 --- a/asusctl/examples/anime-spinning.rs +++ b/asusctl/examples/anime-spinning.rs @@ -7,7 +7,7 @@ use std::process::exit; use std::thread::sleep; use std::time::Duration; -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::{AnimeDataBuffer, AnimeImage, Vec2}; use rog_dbus::zbus_anime::AnimeProxyBlocking; use zbus::blocking::Connection; @@ -23,7 +23,7 @@ fn main() -> Result<(), Box> { exit(-1); } - let anime_type = get_anime_type()?; + let anime_type = get_maybe_anime_type()?; let mut matrix = AnimeImage::from_png( Path::new(&args[1]), args[2].parse::().unwrap(), diff --git a/asusctl/src/main.rs b/asusctl/src/main.rs index 52d7dd3e..206bbb2b 100644 --- a/asusctl/src/main.rs +++ b/asusctl/src/main.rs @@ -9,7 +9,7 @@ use aura_cli::{LedPowerCommand1, LedPowerCommand2}; use dmi_id::DMIID; use fan_curve_cli::FanCurveCommand; use gumdrop::{Opt, Options}; -use rog_anime::usb::get_anime_type; +use rog_anime::usb::get_maybe_anime_type; use rog_anime::{AnimTime, AnimeDataBuffer, AnimeDiagonal, AnimeGif, AnimeImage, AnimeType, Vec2}; use rog_aura::keyboard::{AuraPowerState, LaptopAuraPower}; use rog_aura::{self, AuraDeviceType, AuraEffect, PowerZones}; @@ -365,8 +365,8 @@ fn handle_anime(conn: &Connection, cmd: &AnimeCommand) -> Result<(), Box Result<(), Box> { // Set up the anime data and run loop/thread if supported.contains(&"org.asuslinux.Anime".to_string()) { if let Some(cfg) = config.active_anime { - let anime_type = get_anime_type()?; + let anime_type = get_maybe_anime_type()?; let anime_config = ConfigAnime::new().set_name(cfg).load(); let anime = anime_config.create(anime_type)?; let anime_config = Arc::new(Mutex::new(anime_config)); diff --git a/asusd/src/ctrl_anime/config.rs b/asusd/src/ctrl_anime/config.rs index ac556ad0..b3c86a65 100644 --- a/asusd/src/ctrl_anime/config.rs +++ b/asusd/src/ctrl_anime/config.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use config_traits::{StdConfig, StdConfigLoad2}; +use config_traits::{StdConfig, StdConfigLoad}; use rog_anime::error::AnimeError; use rog_anime::usb::Brightness; use rog_anime::{ @@ -10,60 +10,6 @@ use serde_derive::{Deserialize, Serialize}; const CONFIG_FILE: &str = "anime.ron"; -#[derive(Deserialize, Serialize)] -pub struct AnimeConfigV460 { - pub system: Vec, - pub boot: Vec, - pub wake: Vec, - pub sleep: Vec, - pub shutdown: Vec, - pub brightness: f32, -} - -impl From for AnimeConfig { - fn from(c: AnimeConfigV460) -> AnimeConfig { - AnimeConfig { - system: c.system, - boot: c.boot, - wake: c.wake, - shutdown: c.shutdown, - ..Default::default() - } - } -} - -#[derive(Deserialize, Serialize, Debug)] -pub struct AnimeConfigV472 { - pub model_override: Option, - pub system: Vec, - pub boot: Vec, - pub wake: Vec, - pub sleep: Vec, - pub shutdown: Vec, - pub brightness: f32, - pub display_enabled: bool, - pub display_brightness: Brightness, - pub builtin_anims_enabled: bool, - pub builtin_anims: Animations, -} - -impl From for AnimeConfig { - fn from(c: AnimeConfigV472) -> AnimeConfig { - AnimeConfig { - system: c.system, - boot: c.boot, - wake: c.wake, - shutdown: c.shutdown, - model_override: c.model_override, - display_enabled: c.display_enabled, - display_brightness: c.display_brightness, - builtin_anims_enabled: c.builtin_anims_enabled, - builtin_anims: c.builtin_anims, - ..Default::default() - } - } -} - #[derive(Deserialize, Serialize, Default)] pub struct AnimeConfigCached { pub system: Vec, @@ -108,7 +54,6 @@ impl AnimeConfigCached { /// Config for base system actions for the anime display #[derive(Deserialize, Serialize, Debug, Clone)] pub struct AnimeConfig { - pub model_override: Option, pub system: Vec, pub boot: Vec, pub wake: Vec, @@ -127,7 +72,6 @@ pub struct AnimeConfig { impl Default for AnimeConfig { fn default() -> Self { AnimeConfig { - model_override: None, system: Vec::new(), boot: Vec::new(), wake: Vec::new(), @@ -159,7 +103,7 @@ impl StdConfig for AnimeConfig { } } -impl StdConfigLoad2 for AnimeConfig {} +impl StdConfigLoad for AnimeConfig {} impl From<&AnimeConfig> for DeviceState { fn from(config: &AnimeConfig) -> Self { diff --git a/asusd/src/ctrl_anime/mod.rs b/asusd/src/ctrl_anime/mod.rs index fc9a6823..8807e057 100644 --- a/asusd/src/ctrl_anime/mod.rs +++ b/asusd/src/ctrl_anime/mod.rs @@ -8,11 +8,11 @@ use std::sync::Arc; use std::thread::sleep; use ::zbus::export::futures_util::lock::Mutex; -use config_traits::{StdConfig, StdConfigLoad2}; +use config_traits::{StdConfig, StdConfigLoad}; use log::{error, info, warn}; use rog_anime::error::AnimeError; use rog_anime::usb::{ - get_anime_type, pkt_flush, pkt_set_brightness, pkt_set_enable_display, + get_maybe_anime_type, pkt_flush, pkt_set_brightness, pkt_set_enable_display, pkt_set_enable_powersave_anim, pkts_for_init, Brightness, }; use rog_anime::{ActionData, AnimeDataBuffer, AnimePacketType, AnimeType}; @@ -64,6 +64,12 @@ pub struct CtrlAnime { impl CtrlAnime { #[inline] pub fn new() -> Result { + let anime_type = get_maybe_anime_type()?; + if matches!(anime_type, AnimeType::Unsupported) { + info!("No Anime Matrix capable laptop found"); + return Err(RogError::Anime(AnimeError::NoDevice)); + } + let usb = USBRaw::new(0x193b).ok(); let hid = HidRaw::new("193b").ok(); let node = if usb.is_some() { @@ -91,13 +97,6 @@ impl CtrlAnime { // } let mut config = AnimeConfig::new().load(); - let mut anime_type = get_anime_type()?; - if let AnimeType::Unknown = anime_type { - if let Some(model) = config.model_override { - warn!("Overriding the Animatrix type as {model:?}"); - anime_type = model; - } - } info!("Device has an AniMe Matrix display: {anime_type:?}"); let mut cache = AnimeConfigCached::default(); diff --git a/asusd/src/ctrl_slash/mod.rs b/asusd/src/ctrl_slash/mod.rs index 52ac85de..849a7fb4 100644 --- a/asusd/src/ctrl_slash/mod.rs +++ b/asusd/src/ctrl_slash/mod.rs @@ -2,10 +2,11 @@ pub mod config; pub mod trait_impls; use config_traits::{StdConfig, StdConfigLoad}; +use log::info; use rog_platform::hid_raw::HidRaw; use rog_platform::usb_raw::USBRaw; use rog_slash::error::SlashError; -use rog_slash::usb::{get_slash_type, pkt_set_mode, pkt_set_options, pkts_for_init}; +use rog_slash::usb::{get_maybe_slash_type, pkt_set_mode, pkt_set_options, pkts_for_init}; use rog_slash::{SlashMode, SlashType}; use crate::ctrl_slash::config::SlashConfig; @@ -39,8 +40,9 @@ pub struct CtrlSlash { impl CtrlSlash { #[inline] pub fn new() -> Result { - let slash_type = get_slash_type()?; - if matches!(slash_type, SlashType::Unknown | SlashType::Unsupported) { + let slash_type = get_maybe_slash_type()?; + if matches!(slash_type, SlashType::Unsupported) { + info!("No Slash capable laptop found"); return Err(RogError::Slash(SlashError::NoDevice)); } @@ -51,7 +53,7 @@ impl CtrlSlash { } else if hid.is_some() { unsafe { Node::Hid(hid.unwrap_unchecked()) } } else { - return Err(RogError::NotSupported); + return Err(RogError::Slash(SlashError::NoDevice)); }; let ctrl = CtrlSlash { diff --git a/rog-anime/src/data.rs b/rog-anime/src/data.rs index eff64b83..7f9e920e 100644 --- a/rog-anime/src/data.rs +++ b/rog-anime/src/data.rs @@ -62,7 +62,7 @@ pub enum AnimeType { GA401, GA402, GU604, - Unknown, + Unsupported, } impl FromStr for AnimeType { @@ -73,7 +73,7 @@ impl FromStr for AnimeType { "ga401" | "GA401" => Self::GA401, "ga402" | "GA402" => Self::GA402, "gu604" | "GU604" => Self::GU604, - _ => Self::Unknown, + _ => Self::Unsupported, }) } } @@ -165,7 +165,7 @@ impl TryFrom for AnimePacketType { let mut buffers = match anime.anime { AnimeType::GA401 => vec![[0; 640]; 2], - AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unknown => vec![[0; 640]; 3], + AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unsupported => vec![[0; 640]; 3], }; for (idx, chunk) in anime.data.as_slice().chunks(PANE_LEN).enumerate() { @@ -176,7 +176,7 @@ impl TryFrom for AnimePacketType { if matches!( anime.anime, - AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unknown + AnimeType::GA402 | AnimeType::GU604 | AnimeType::Unsupported ) { buffers[2][..7].copy_from_slice(&USB_PREFIX3); } diff --git a/rog-anime/src/usb.rs b/rog-anime/src/usb.rs index 3800ae95..da821c15 100644 --- a/rog-anime/src/usb.rs +++ b/rog-anime/src/usb.rs @@ -241,13 +241,13 @@ impl From for i32 { } } -/// `get_anime_type` is very broad, matching on part of the laptop board name -/// only. For this reason `find_node()` must be used also to verify if the USB -/// device is available. +/// `get_maybe_anime_type` is very broad, matching on part of the laptop board +/// name only. For this reason `find_node()` must be used also to verify if the +/// USB device is available. /// /// The currently known USB device is `19b6`. #[inline] -pub fn get_anime_type() -> Result { +pub fn get_maybe_anime_type() -> Result { let dmi = DMIID::new().map_err(|_| AnimeError::NoDevice)?; // TODO: better error let board_name = dmi.board_name; @@ -258,8 +258,8 @@ pub fn get_anime_type() -> Result { } else if board_name.contains("GU604V") { return Ok(AnimeType::GU604); } - log::warn!("AniMe Matrix device found but not yet supported, will default to a GA402 layout"); - Ok(AnimeType::Unknown) + log::warn!("AniMe Matrix device found but could be a slash"); + Ok(AnimeType::Unsupported) } /// Get the two device initialization packets. These are required for device diff --git a/rog-slash/src/data.rs b/rog-slash/src/data.rs index c68b26dc..15e50b7b 100644 --- a/rog-slash/src/data.rs +++ b/rog-slash/src/data.rs @@ -12,7 +12,7 @@ use crate::error::SlashError; #[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum SlashType { GA403, - Unknown, + GA605, Unsupported, } @@ -22,7 +22,8 @@ impl FromStr for SlashType { fn from_str(s: &str) -> std::result::Result { Ok(match s { "ga403" | "GA403" => Self::GA403, - _ => Self::Unknown, + "ga605" | "GA605" => Self::GA605, + _ => Self::Unsupported, }) } } diff --git a/rog-slash/src/usb.rs b/rog-slash/src/usb.rs index b07c470c..ab73ed0e 100644 --- a/rog-slash/src/usb.rs +++ b/rog-slash/src/usb.rs @@ -28,12 +28,14 @@ pub type SlashUsbPacket = [u8; PACKET_SIZE]; /// /// The currently known USB device is `193B`. #[inline] -pub fn get_slash_type() -> Result { +pub fn get_maybe_slash_type() -> Result { let dmi = DMIID::new().map_err(|_| SlashError::NoDevice)?; // TODO: better error let board_name = dmi.board_name; if board_name.contains("GA403") { return Ok(SlashType::GA403); + } else if board_name.contains("GA605") { + return Ok(SlashType::GA605); } Ok(SlashType::Unsupported) } diff --git a/simulators/src/animatrix/mod.rs b/simulators/src/animatrix/mod.rs index a2e7d869..22be55d9 100644 --- a/simulators/src/animatrix/mod.rs +++ b/simulators/src/animatrix/mod.rs @@ -43,7 +43,7 @@ impl AniMatrix { vertical: 2, horizontal: 5, }, - AnimeType::GA402 | AnimeType::Unknown => LedShape { + AnimeType::GA402 | AnimeType::Unsupported => LedShape { vertical: 2, horizontal: 5, }, @@ -56,7 +56,7 @@ impl AniMatrix { // Do a hard mapping of each (derived from wireshardk captures) let rows = match model { AnimeType::GA401 => GA401.to_vec(), - AnimeType::GA402 | AnimeType::Unknown => GA402.to_vec(), + AnimeType::GA402 | AnimeType::Unsupported => GA402.to_vec(), AnimeType::GU604 => GU604.to_vec(), };