mirror of
https://gitlab.com/asus-linux/asusctl.git
synced 2026-01-22 09:23:19 +01:00
Animatrix: simulators, add features
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use rog_anime::AnimeType;
|
||||
|
||||
use self::map_ga401::GA401;
|
||||
use self::map_ga402::GA402;
|
||||
use self::map_gu604::GU604;
|
||||
@@ -6,12 +8,6 @@ mod map_ga401;
|
||||
mod map_ga402;
|
||||
mod map_gu604;
|
||||
|
||||
pub enum Model {
|
||||
GA401,
|
||||
GA402,
|
||||
GU604,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Row(
|
||||
/// The USB packet index, this is mapped to the 4th byte (idx = 3) and is
|
||||
@@ -41,17 +37,17 @@ pub struct AniMatrix {
|
||||
}
|
||||
|
||||
impl AniMatrix {
|
||||
pub fn new(model: Model) -> Self {
|
||||
pub fn new(model: AnimeType) -> Self {
|
||||
let led_shape = match model {
|
||||
Model::GA401 => LedShape {
|
||||
AnimeType::GA401 => LedShape {
|
||||
vertical: 2,
|
||||
horizontal: 5,
|
||||
},
|
||||
Model::GA402 => LedShape {
|
||||
AnimeType::GA402 | AnimeType::Unknown => LedShape {
|
||||
vertical: 2,
|
||||
horizontal: 5,
|
||||
},
|
||||
Model::GU604 => LedShape {
|
||||
AnimeType::GU604 => LedShape {
|
||||
vertical: 2,
|
||||
horizontal: 5,
|
||||
},
|
||||
@@ -59,9 +55,9 @@ impl AniMatrix {
|
||||
|
||||
// Do a hard mapping of each (derived from wireshardk captures)
|
||||
let rows = match model {
|
||||
Model::GA401 => GA401.to_vec(),
|
||||
Model::GA402 => GA402.to_vec(),
|
||||
Model::GU604 => GU604.to_vec(),
|
||||
AnimeType::GA401 => GA401.to_vec(),
|
||||
AnimeType::GA402 | AnimeType::Unknown => GA402.to_vec(),
|
||||
AnimeType::GU604 => GU604.to_vec(),
|
||||
};
|
||||
|
||||
Self { rows, led_shape }
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::str::FromStr;
|
||||
|
||||
use log::error;
|
||||
use rog_anime::usb::{PROD_ID, VENDOR_ID};
|
||||
use rog_anime::USB_PREFIX2;
|
||||
use rog_anime::{AnimeType, USB_PREFIX2};
|
||||
use sdl2::event::Event;
|
||||
use sdl2::keyboard::Keycode;
|
||||
use sdl2::pixels::Color;
|
||||
@@ -19,7 +21,7 @@ pub struct VirtAnimeMatrix {
|
||||
}
|
||||
|
||||
impl VirtAnimeMatrix {
|
||||
pub fn new(model: Model) -> Self {
|
||||
pub fn new(model: AnimeType) -> Self {
|
||||
VirtAnimeMatrix {
|
||||
buffer: [0; 640],
|
||||
animatrix: AniMatrix::new(model),
|
||||
@@ -110,6 +112,13 @@ impl VirtAnimeMatrix {
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() <= 1 {
|
||||
println!("Must supply arg, one of <GA401, GA402, GU604>");
|
||||
return Ok(());
|
||||
}
|
||||
let anime_type = AnimeType::from_str(&args[1])?;
|
||||
|
||||
let sdl_context = sdl2::init().unwrap();
|
||||
let video_subsystem = sdl_context.video().unwrap();
|
||||
|
||||
@@ -121,7 +130,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let mut canvas = window.into_canvas().build().unwrap();
|
||||
|
||||
let mut dev = VirtAnimeMatrix::new(Model::GU604);
|
||||
let mut dev = VirtAnimeMatrix::new(anime_type);
|
||||
|
||||
canvas.set_draw_color(Color::RGB(0, 0, 0));
|
||||
canvas.clear();
|
||||
@@ -130,7 +139,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
dev.read(); // it's blocking, and damned hard to sync with arc/mutex
|
||||
// let one = dev.buffer[0..7] != USB_PREFIX2;
|
||||
let index = dev.buffer[3];
|
||||
println!("{:02x}", index);
|
||||
|
||||
let w = dev.animatrix.led_shape().horizontal * 6;
|
||||
let h = dev.animatrix.led_shape().vertical * 6;
|
||||
@@ -147,7 +155,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
}
|
||||
for (x_count, b) in dev.buffer[start..=end].iter().enumerate() {
|
||||
// print!("{b},");
|
||||
canvas.set_draw_color(Color::RGB(*b as u8, *b as u8, *b as u8));
|
||||
|
||||
let x: i32 = w + x_count as i32 * w
|
||||
@@ -162,7 +169,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
.fill_rect(Rect::new(x, y, w as u32, h as u32))
|
||||
.unwrap();
|
||||
}
|
||||
// println!();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user