feat: add grid
This commit is contained in:
parent
69b619dbf5
commit
e4580e0e53
@ -9,6 +9,7 @@ use crate::device::dummy::DummyDevice;
|
|||||||
use crate::errors::LJResult;
|
use crate::errors::LJResult;
|
||||||
use crate::point::Point;
|
use crate::point::Point;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use crate::redis_ctrl::Line;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
self.protocol_version,
|
self.protocol_version,
|
||||||
@ -56,6 +57,7 @@ pub trait Device {
|
|||||||
speed: u32,
|
speed: u32,
|
||||||
) -> LJResult<()>;
|
) -> LJResult<()>;
|
||||||
fn stop(&mut self) -> LJResult<()>;
|
fn stop(&mut self) -> LJResult<()>;
|
||||||
|
fn grid(&mut self) -> Vec<Point>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
|
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
self.protocol_version,
|
|
||||||
self.le_state,
|
|
||||||
self.playback_state,
|
|
||||||
self.source,
|
|
||||||
self.le_flags,
|
|
||||||
self.playback_flags,
|
|
||||||
self.source_flags,
|
|
||||||
self.fullness,
|
|
||||||
self.point_rate,
|
|
||||||
self.point_count
|
|
||||||
*/
|
|
||||||
|
|
||||||
pub struct Status {
|
|
||||||
pub active: bool,
|
|
||||||
pub last_traced_at: String,
|
|
||||||
pub properties: Vec<String>
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Device {
|
|
||||||
/**
|
|
||||||
fn intersect(&self, orig : &Vec3, dir : &Vec3) -> Option<Float>;
|
|
||||||
fn get_surface(&self, v : &Vec3) -> Vec3;
|
|
||||||
fn get_normal(&self, v : &Vec3) -> Vec3;
|
|
||||||
fn get_material(&self) -> &dyn Material;
|
|
||||||
**/
|
|
||||||
|
|
||||||
fn status( &self ) -> Status;
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
use crate::device::{Device, Status, PlaybackState};
|
use crate::device::{Device, Status, PlaybackState};
|
||||||
use crate::errors::LJResult;
|
use crate::errors::LJResult;
|
||||||
use crate::point::Point;
|
use crate::point::{Color, Point};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
pub struct DummyDevice {
|
pub struct DummyDevice {
|
||||||
@ -35,4 +35,9 @@ impl Device for DummyDevice {
|
|||||||
fn stop(&mut self) -> LJResult<()> {
|
fn stop(&mut self) -> LJResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
fn grid(&mut self) -> Vec<Point> {
|
||||||
|
vec!(
|
||||||
|
Point{ x: 0 as f32, y: 0 as f32, color:Color{ r: 0, g: 0, b: 0 }}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,9 @@ use helios_dac::{
|
|||||||
use crate::conf::HeliosConf;
|
use crate::conf::HeliosConf;
|
||||||
use crate::device::{Device, Status, PlaybackState};
|
use crate::device::{Device, Status, PlaybackState};
|
||||||
use crate::errors::{LJError, LJResult};
|
use crate::errors::{LJError, LJResult};
|
||||||
use crate::point::Point;
|
use crate::point::{Color, Point};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
use crate::redis_ctrl::Line;
|
||||||
|
|
||||||
pub struct HeliosDevice {
|
pub struct HeliosDevice {
|
||||||
pub conf: HeliosConf,
|
pub conf: HeliosConf,
|
||||||
@ -22,7 +23,7 @@ pub struct HeliosDevice {
|
|||||||
sent_points: u16,
|
sent_points: u16,
|
||||||
state: PlaybackState,
|
state: PlaybackState,
|
||||||
lack: String,
|
lack: String,
|
||||||
last_traced_at : String
|
last_traced_at: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeliosDevice {
|
impl HeliosDevice {
|
||||||
@ -40,14 +41,13 @@ impl HeliosDevice {
|
|||||||
sent_points: 0,
|
sent_points: 0,
|
||||||
state: PlaybackState::PREPARE,
|
state: PlaybackState::PREPARE,
|
||||||
lack: "".to_string(),
|
lack: "".to_string(),
|
||||||
last_traced_at: "1985-04-12T23:20:50.52Z".to_string()
|
last_traced_at: "1985-04-12T23:20:50.52Z".to_string(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Device for HeliosDevice {
|
impl Device for HeliosDevice {
|
||||||
fn status(&self) -> Status {
|
fn status(&self) -> Status {
|
||||||
|
|
||||||
let lack = self.lack.clone();
|
let lack = self.lack.clone();
|
||||||
Status {
|
Status {
|
||||||
last_traced_at: self.last_traced_at.clone(),
|
last_traced_at: self.last_traced_at.clone(),
|
||||||
@ -78,4 +78,27 @@ impl Device for HeliosDevice {
|
|||||||
self.dac.stop()?;
|
self.dac.stop()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn grid(&mut self) -> Vec<Point> {
|
||||||
|
let dim_min = 0 as f32;
|
||||||
|
let dim_mid = 2047 as f32;
|
||||||
|
let dim_max = 4095 as f32;
|
||||||
|
let col_min = Color { r: 0, g: 0, b: 0 };
|
||||||
|
let col_max = Color { r: 255, g: 255, b: 255 };
|
||||||
|
|
||||||
|
vec![
|
||||||
|
Point { x: dim_min, y: dim_max, color: col_min },
|
||||||
|
Point { x: dim_min, y: dim_max, color: col_max },
|
||||||
|
Point { x: dim_max, y: dim_max, color: col_max },
|
||||||
|
Point { x: dim_max, y: dim_min, color: col_max },
|
||||||
|
Point { x: dim_min, y: dim_min, color: col_max },
|
||||||
|
Point { x: dim_min, y: dim_min, color: col_min },
|
||||||
|
Point { x: dim_min, y: dim_mid, color: col_min },
|
||||||
|
Point { x: dim_min, y: dim_mid, color: col_max },
|
||||||
|
Point { x: dim_mid, y: dim_mid, color: col_max },
|
||||||
|
Point { x: dim_mid, y: dim_min, color: col_max },
|
||||||
|
Point { x: dim_min, y: dim_min, color: col_max },
|
||||||
|
Point { x: dim_min, y: dim_min, color: col_min },
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
46
src/main.rs
46
src/main.rs
@ -13,7 +13,7 @@ mod worldstate;
|
|||||||
use device::device_factory;
|
use device::device_factory;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use redis_ctrl::{RedisCtrl, Order};
|
use redis_ctrl::{RedisCtrl, Order, Line};
|
||||||
use conf::Conf;
|
use conf::Conf;
|
||||||
use errors::LJResult;
|
use errors::LJResult;
|
||||||
use point::{Point, Color};
|
use point::{Point, Color};
|
||||||
@ -62,6 +62,7 @@ fn run_all() -> LJResult<()> {
|
|||||||
|
|
||||||
// Setup Laser Device based on conf
|
// Setup Laser Device based on conf
|
||||||
let mut tracer = device_factory(&config)?;
|
let mut tracer = device_factory(&config)?;
|
||||||
|
world_state.grid = tracer.grid();
|
||||||
|
|
||||||
// can't work, but we can add + Debug to Device to make it work...
|
// can't work, but we can add + Debug to Device to make it work...
|
||||||
//dbg!(tracer);
|
//dbg!(tracer);
|
||||||
@ -78,8 +79,6 @@ fn run_all() -> LJResult<()> {
|
|||||||
// 2 : Draw BLACK point list
|
// 2 : Draw BLACK point list
|
||||||
// 3 : Draw GRID point list
|
// 3 : Draw GRID point list
|
||||||
|
|
||||||
// /worldstate.rs
|
|
||||||
// /edh.rs
|
|
||||||
|
|
||||||
// 1 : Get the new EDH = reread redis key /EDH/lasernumber
|
// 1 : Get the new EDH = reread redis key /EDH/lasernumber
|
||||||
// 4 : Resampler Change (longs and shorts lsteps)
|
// 4 : Resampler Change (longs and shorts lsteps)
|
||||||
@ -88,28 +87,29 @@ fn run_all() -> LJResult<()> {
|
|||||||
// 7 : kpps change = reread redis key /kpps
|
// 7 : kpps change = reread redis key /kpps
|
||||||
// 8 : color balance change = reread redis keys /red /green /blue
|
// 8 : color balance change = reread redis keys /red /green /blue
|
||||||
match order {
|
match order {
|
||||||
Order::Draw | Order::Black => {
|
Order::Draw | Order::Black | Order::Grid => {
|
||||||
world_state.black = order == Order::Black;
|
world_state.draw_black = order == Order::Black;
|
||||||
|
world_state.draw_grid = order == Order::Grid;
|
||||||
|
|
||||||
let frame = get_next_frame(
|
let frame = get_next_frame(
|
||||||
&config,
|
&config,
|
||||||
&transformers,
|
&transformers,
|
||||||
&mut rs,
|
&mut rs,
|
||||||
&world_state
|
&world_state,
|
||||||
)?;
|
)?;
|
||||||
// For now, draw all the time
|
// For now, draw all the time
|
||||||
tracer.draw(frame, world_state.kpps)?;
|
tracer.draw(frame, world_state.kpps)?;
|
||||||
},
|
}
|
||||||
Order::Intensity => {
|
Order::Intensity => {
|
||||||
world_state.intensity = rs.get_int("intensity")?
|
world_state.intensity = rs.get_int("intensity")?
|
||||||
.try_into()?;
|
.try_into()?;
|
||||||
},
|
}
|
||||||
Order::Edh => {
|
Order::Edh => {
|
||||||
world_state.edh = rs.get_edh()?;
|
world_state.edh = rs.get_edh()?;
|
||||||
},
|
}
|
||||||
Order::Kpps => {
|
Order::Kpps => {
|
||||||
world_state.kpps = rs.get_int("kpps")?;
|
world_state.kpps = rs.get_int("kpps")?;
|
||||||
},
|
}
|
||||||
|
|
||||||
// Order::ClientKey => rs.client_key(),
|
// Order::ClientKey => rs.client_key(),
|
||||||
// Order::ColorBalance => {},
|
// Order::ColorBalance => {},
|
||||||
@ -143,36 +143,46 @@ fn get_next_frame(
|
|||||||
config: &Conf,
|
config: &Conf,
|
||||||
transformers: &[Box<dyn Transformers>],
|
transformers: &[Box<dyn Transformers>],
|
||||||
rs: &mut RedisCtrl,
|
rs: &mut RedisCtrl,
|
||||||
world_state : &WorldState
|
world_state: &WorldState,
|
||||||
) -> LJResult<Vec<Point>> {
|
) -> LJResult<Vec<Point>> {
|
||||||
let format_key = format!("{}{}",
|
let format_key = format!("{}{}",
|
||||||
world_state.client_key,
|
world_state.client_key,
|
||||||
config.laser_id);
|
config.laser_id);
|
||||||
let line = rs.get_line(&format_key)?;
|
|
||||||
let mut line: Vec<Point> = line.into_iter()
|
// Handle the grid case
|
||||||
|
|
||||||
|
let mut line : Vec<Point>;
|
||||||
|
if world_state.draw_grid {
|
||||||
|
line = world_state.grid.clone();
|
||||||
|
} else {
|
||||||
|
let redis_line = rs.get_line(&format_key)?;
|
||||||
|
line = redis_line.into_iter()
|
||||||
.map(|tpl| tpl.into())
|
.map(|tpl| tpl.into())
|
||||||
.collect();
|
.collect();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
for transformer in transformers {
|
for transformer in transformers {
|
||||||
line = transformer.apply(&line, world_state);
|
line = transformer.apply(&line, world_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("-> {}", world_state.black);
|
info!("Draw Black -> {}", world_state.draw_black);
|
||||||
|
info!("Draw Grid -> {}", world_state.draw_grid);
|
||||||
|
|
||||||
// LIMITER and BLACK
|
// LIMITER and BLACK
|
||||||
line = line.into_iter()
|
line = line.into_iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
|
let color = if world_state.draw_black {
|
||||||
let color = if world_state.black {
|
|
||||||
Color { r: 0, g: 0, b: 0 }
|
Color { r: 0, g: 0, b: 0 }
|
||||||
} else {
|
} else {
|
||||||
Color {
|
Color {
|
||||||
r: p.color.r.min(world_state.intensity),
|
r: p.color.r.min(world_state.intensity),
|
||||||
g: p.color.g.min(world_state.intensity),
|
g: p.color.g.min(world_state.intensity),
|
||||||
b: p.color.b.min(world_state.intensity)
|
b: p.color.b.min(world_state.intensity),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Point { color,
|
Point {
|
||||||
|
color,
|
||||||
..p
|
..p
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
15
src/point.rs
15
src/point.rs
@ -2,14 +2,23 @@
|
|||||||
pub struct Point {
|
pub struct Point {
|
||||||
pub x: f32,
|
pub x: f32,
|
||||||
pub y: f32,
|
pub y: f32,
|
||||||
pub color: Color
|
pub color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, PartialEq)]
|
#[derive(Debug, Clone, Copy, Default, PartialEq)]
|
||||||
pub struct Color {
|
pub struct Color {
|
||||||
pub r: u8,
|
pub r: u8,
|
||||||
pub g: u8,
|
pub g: u8,
|
||||||
pub b: u8
|
pub b: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Color> for u32 {
|
||||||
|
fn from(value: Color) -> Self {
|
||||||
|
let r = value.r as u32;
|
||||||
|
let g = value.g as u32;
|
||||||
|
let b = (value.b) as u32;
|
||||||
|
(r << 16) + (g << 8) + b
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<(f32, f32, u32)> for Point {
|
impl From<(f32, f32, u32)> for Point {
|
||||||
@ -28,7 +37,7 @@ impl From<Point> for helios_dac::Point {
|
|||||||
helios_dac::Point {
|
helios_dac::Point {
|
||||||
coordinate: (x, y).into(),
|
coordinate: (x, y).into(),
|
||||||
color: helios_dac::Color::new(pt.color.r, pt.color.g, pt.color.b),
|
color: helios_dac::Color::new(pt.color.r, pt.color.g, pt.color.b),
|
||||||
intensity: 0xFF
|
intensity: 0xFF,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@ use crate::point::{Point,Color};
|
|||||||
use nalgebra::base::{Matrix3, Matrix1x3};
|
use nalgebra::base::{Matrix3, Matrix1x3};
|
||||||
use crate::errors::{LJError, LJResult};
|
use crate::errors::{LJError, LJResult};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
use crate::redis_ctrl::Line;
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct EDH {
|
pub struct EDH {
|
||||||
pub matrix: Matrix3<f32>
|
pub matrix: Matrix3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EDH {
|
impl EDH {
|
||||||
@ -40,13 +41,13 @@ impl EDH {
|
|||||||
pub struct WorldState {
|
pub struct WorldState {
|
||||||
pub edh: EDH,
|
pub edh: EDH,
|
||||||
pub resampler: Vec<f32>,
|
pub resampler: Vec<f32>,
|
||||||
pub client_key: String, //u8,
|
pub client_key: String,
|
||||||
pub intensity: u8,
|
pub intensity: u8,
|
||||||
pub kpps: u32,
|
pub kpps: u32,
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
pub black: bool
|
pub draw_black: bool,
|
||||||
|
pub draw_grid: bool,
|
||||||
|
pub grid: Vec<Point>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorldState {
|
impl WorldState {}
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user