commit b5f6f03151ac3397baefd23c90a8ee4b94f4deea Author: Marc Planard Date: Thu Jun 1 23:11:40 2023 +0200 initial commit diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..31004fa --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "lazer" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +helios-dac = { version = "0.1", default-features = false, features = ["native"] } +redis = "0.23.0" +ron = "0.8.0" +serde = { version = "1.0.163", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..09c5336 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,90 @@ +/// +/// Configure udev: +/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md +/// + +use helios_dac::{Frame, + Point, + DeviceStatus, + // Coordinate, + Color}; + +use redis::{ //RedisResult, + Client, + Connection, + Commands +}; + +use ron::de::from_str; + +type Line = Vec<(f32,f32,u32)>; + + +const CENTER : (u16,u16) = (2000, 2000); + +pub fn main() -> Result<(), Box> { + use helios_dac::NativeHeliosDacController; + + let client = Client::open("redis://127.0.0.1/")?; + let mut con = client.get_connection()?; + + let controller = NativeHeliosDacController::new()?; + let devices = controller.list_devices()?; + + let device = devices.into_iter().next().unwrap(); + let mut device = device.open()?; + + for _ in 0..100 { + let frame = get_next_frame(1000, &mut con)?; + + while let Ok(DeviceStatus::NotReady) = device.status() { + } + device.write_frame(frame)?; + } + + device.stop()?; + Ok(()) +} + +fn get_next_frame( + speed: u32, + con: &mut Connection +) -> Result> { + let val : String = con.get("/pl/0/0")?; + let line : Line = from_str(&val)?; + let line : Vec = line.iter() + .map(tuple_to_point) + .collect(); + + let mut line2 = vec![]; + while line2.len() < 48 { + for p in &line { + line2.push(*p); + } + } + + Ok(Frame::new(speed, line2)) +} + +fn tuple_to_point(tpl: &(f32,f32,u32)) -> Point { + let (x, y, col) = tpl; + + let r = (col >> 16) as u8; + let g = ((col >> 8) & 255) as u8; + let b = (col & 255) as u8; + + let x = CENTER.0 + *x as u16; + let y = CENTER.1 + *y as u16; + + if x >= 4096 || y >= 4096 { + println!("WARN: coordinate out of range: {} {}", x, y); + } + let x = x.clamp(0, 4095); + let y = y.clamp(0, 4095); + + Point { + coordinate: (x, y).into(), + color: Color::new(r, g, b), + intensity: 0xFF + } +}