add our own point definition

This commit is contained in:
Marc Planard 2023-06-04 21:31:32 +02:00
parent edba874ae7
commit d9450e903f
2 changed files with 47 additions and 23 deletions

View File

@ -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<Frame> {
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
let line: Vec<Point> = line.iter().map(tuple_to_point).collect();
let line: Vec<helios_dac::Point> = 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()
}

34
src/point.rs Normal file
View File

@ -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<Point> 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
}
}
}