From d9450e903f50e18a709b7bb06e70c13777c25ced Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Sun, 4 Jun 2023 21:31:32 +0200 Subject: [PATCH] add our own point definition --- src/main.rs | 36 +++++++++++++----------------------- src/point.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 src/point.rs diff --git a/src/main.rs b/src/main.rs index a431c5e..3e81384 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,21 +5,21 @@ mod redis_ctrl; mod conf; mod errors; +mod point; use helios_dac::{ + self, NativeHeliosDacController, NativeHeliosDac, - // Coordinate, - Color, DeviceStatus, Frame, - Point, }; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use redis_ctrl::{RedisCtrl,Order}; use conf::Conf; use errors::{LJError,LJResult}; +use point::Point; const CENTER : (u16,u16) = (2000, 2000); @@ -84,7 +84,7 @@ fn get_next_frame( ) -> LJResult { let line = rs.get(&format!("/pl/{}/0", config.laser_id))?; - let line: Vec = line.iter().map(tuple_to_point).collect(); + let line: Vec = line.iter().map(tuple_to_point).collect(); let mut line2 = vec![]; while line2.len() < 48 { @@ -98,25 +98,15 @@ fn get_next_frame( Ok(Frame::new(speed, line2)) } -fn tuple_to_point(tpl: &(f32, f32, u32)) -> Point { - let (x, y, col) = tpl; +fn tuple_to_point(tpl: &(f32, f32, u32)) -> helios_dac::Point { + let mut point : Point = (*tpl).into(); - let r = (col >> 16) as u8 ; - let g = ((col >> 8) & 255) as u8 ; - let b = (col & 255) as u8 ; + point.x = (CENTER.0 + point.x as u16 * 2).into(); + point.y = (CENTER.1 + point.y as u16 * 2).into(); + + if point.x >= 4096.0 || point.y >= 4096.0 { + println!("WARN: coordinate out of range: {:?}", point); + } - let x = CENTER.0 + *x as u16 * 2; - let y = CENTER.1 + *y as u16 * 2; - - 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, - } + point.into() } diff --git a/src/point.rs b/src/point.rs new file mode 100644 index 0000000..1d43bfe --- /dev/null +++ b/src/point.rs @@ -0,0 +1,34 @@ +#[derive(Debug,Clone,Copy)] +pub struct Point { + pub x: f32, + pub y: f32, + pub color: Color +} + +#[derive(Debug,Clone,Copy)] +pub struct Color { + r: u8, + g: u8, + b: u8 +} + +impl From<(f32,f32,u32)> for Point { + fn from((x, y, color) : (f32, f32, u32)) -> Point { + let r = (color >> 16) as u8 ; + let g = ((color >> 8) & 255) as u8 ; + let b = (color & 255) as u8 ; + Point { x, y, color: Color { r, g, b } } + } +} + +impl From for helios_dac::Point { + fn from(pt: Point) -> helios_dac::Point { + let x = pt.x.clamp(0.0, 4095.0) as u16; + let y = pt.y.clamp(0.0, 4095.0) as u16; + helios_dac::Point { + coordinate: (x, y).into(), + color: helios_dac::Color::new(pt.color.r, pt.color.g, pt.color.b), + intensity: 0xFF + } + } +}