From 3a18506510b92c776e52d44dc3760eaf9c97a5e8 Mon Sep 17 00:00:00 2001 From: "Luke D. Jones" Date: Sun, 28 May 2023 21:04:43 +1200 Subject: [PATCH] Add "Unknown" to (not really) supported AniMe list Intention is to allow users to at least control the power state of the device (turn off) if the phyciscal display isn't yet supported. Partial address of #354 --- rog-anime/src/data.rs | 5 +++++ rog-anime/src/diagonal.rs | 6 ++++++ rog-anime/src/image.rs | 8 ++++++++ rog-anime/src/usb.rs | 3 ++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/rog-anime/src/data.rs b/rog-anime/src/data.rs index e4b325e3..e6dd11fc 100644 --- a/rog-anime/src/data.rs +++ b/rog-anime/src/data.rs @@ -38,6 +38,7 @@ pub struct AnimePowerStates { pub enum AnimeType { GA401, GA402, + Unknown, } impl AnimeType { @@ -45,6 +46,7 @@ impl AnimeType { pub fn width(&self) -> usize { match self { AnimeType::GA401 | AnimeType::GA402 => 74, + AnimeType::Unknown => 0, } } @@ -53,6 +55,7 @@ impl AnimeType { match self { AnimeType::GA401 => 36, AnimeType::GA402 => 39, + AnimeType::Unknown => 0, } } @@ -61,6 +64,7 @@ impl AnimeType { match self { AnimeType::GA401 => PANE_LEN * 2, AnimeType::GA402 => PANE_LEN * 3, + AnimeType::Unknown => 0, } } } @@ -125,6 +129,7 @@ impl TryFrom for AnimePacketType { let mut buffers = match anime.anime { AnimeType::GA401 => vec![[0; 640]; 2], AnimeType::GA402 => vec![[0; 640]; 3], + AnimeType::Unknown => vec![[0; 640]; 1], }; for (idx, chunk) in anime.data.as_slice().chunks(PANE_LEN).enumerate() { diff --git a/rog-anime/src/diagonal.rs b/rog-anime/src/diagonal.rs index 1c99556b..d6008cea 100644 --- a/rog-anime/src/diagonal.rs +++ b/rog-anime/src/diagonal.rs @@ -139,6 +139,7 @@ impl AnimeDiagonal { match anime_type { AnimeType::GA401 => self.to_ga401_packets(), AnimeType::GA402 => self.to_ga402_packets(), + AnimeType::Unknown => self.to_unknown_packets(), } } @@ -288,6 +289,11 @@ impl AnimeDiagonal { AnimeDataBuffer::from_vec(crate::AnimeType::GA402, buf) } + + fn to_unknown_packets(&self) -> Result { + let buf = vec![0u8; AnimeType::Unknown.data_length()]; + AnimeDataBuffer::from_vec(crate::AnimeType::Unknown, buf) + } } #[cfg(test)] diff --git a/rog-anime/src/image.rs b/rog-anime/src/image.rs index c6f4d186..0a2e20c7 100644 --- a/rog-anime/src/image.rs +++ b/rog-anime/src/image.rs @@ -118,6 +118,7 @@ impl AnimeImage { match anime_type { AnimeType::GA401 => 0.8, AnimeType::GA402 => 0.77, + AnimeType::Unknown => 0.0, } } @@ -133,6 +134,7 @@ impl AnimeImage { match anime_type { AnimeType::GA401 => 0.3, AnimeType::GA402 => 0.283, + AnimeType::Unknown => 0.0, } } @@ -173,6 +175,7 @@ impl AnimeImage { // and then their offset grows by one every two rows (y + 1) / 2 - 5 } + AnimeType::Unknown => 0, } } @@ -206,6 +209,7 @@ impl AnimeImage { } 39 - y / 2 } + AnimeType::Unknown => 0, } } @@ -215,6 +219,7 @@ impl AnimeImage { // 33.0 = Longest row LED count (physical) plus half-pixel offset AnimeType::GA401 => (33.0 + 0.5) * Self::scale_x(anime_type), AnimeType::GA402 => (35.0 + 0.5) * Self::scale_x(anime_type), + AnimeType::Unknown => 0.0, } } @@ -223,6 +228,7 @@ impl AnimeImage { match anime_type { AnimeType::GA401 => 55, AnimeType::GA402 => 61, + AnimeType::Unknown => 0, } } @@ -233,6 +239,7 @@ impl AnimeImage { AnimeType::GA401 => (54.0 + 1.0) * Self::scale_y(anime_type), // GA402 may not have dead pixels and require only the physical LED count AnimeType::GA402 => 61.0 * Self::scale_y(anime_type), + AnimeType::Unknown => 0.0, } } @@ -246,6 +253,7 @@ impl AnimeImage { }, // GA402 does not have padding, equivalent to width AnimeType::GA402 => AnimeImage::width(anime_type, y), + AnimeType::Unknown => 0, } } diff --git a/rog-anime/src/usb.rs b/rog-anime/src/usb.rs index 83ef866d..d5e0c43a 100644 --- a/rog-anime/src/usb.rs +++ b/rog-anime/src/usb.rs @@ -34,7 +34,8 @@ pub fn get_anime_type() -> Result { } else if board_name.contains("GA402R") { return Ok(AnimeType::GA402); } - Err(AnimeError::UnsupportedDevice) + log::warn!("AniMe Matrix device found but not yet supported"); + Ok(AnimeType::Unknown) } /// Get the two device initialization packets. These are required for device