Compare commits

..

No commits in common. "e5e8ad878b7abf4f6038cea2ff152547202d626f" and "9b9e04ad6304f0e8b918cb4ecd9d9a9f94cdb034" have entirely different histories.

19 changed files with 29 additions and 273 deletions

View File

@ -11,10 +11,8 @@ config = "0.13.3"
ctrlc = "3.4.0" ctrlc = "3.4.0"
env_logger = "0.10.0" env_logger = "0.10.0"
helios-dac = { version = "0.1", default-features = false, features = ["native"] } helios-dac = { version = "0.1", default-features = false, features = ["native"] }
log = "0.4.18" log = "0.4.18"
redis = "0.23.0" redis = "0.23.0"
ron = "0.8.0" ron = "0.8.0"
serde = { version = "1.0.163", features = ["derive"] } serde = { version = "1.0.163", features = ["derive"] }
toml = "0.7.4" toml = "0.7.4"
nalgebra = "0.32.2"

View File

@ -15,9 +15,6 @@ redis_url = "redis://127.0.0.1:6379/"
[dac.helios] [dac.helios]
id = 0 id = 0
# For dummy dac:
# [dac.dummy]
# For Etherdream. IP of the DAC # For Etherdream. IP of the DAC
# [dac.etherdream] # [dac.etherdream]
# url = "192.168.1.68" # url = "192.168.1.68"

View File

@ -19,8 +19,6 @@ pub enum DacFamily {
Helios(HeliosConf), Helios(HeliosConf),
#[serde(rename = "etherdream")] #[serde(rename = "etherdream")]
Etherdream(EtherDreamConf), Etherdream(EtherDreamConf),
#[serde(rename = "dummy")]
Dummy,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
@ -46,9 +44,8 @@ pub enum TransformConf {
#[serde(rename = "flip_vertical")] #[serde(rename = "flip_vertical")]
FlipV(transformer::FlipVertical), FlipV(transformer::FlipVertical),
#[serde(rename = "grid")] #[serde(rename = "grid")]
Grid(transformer::Grid), Grid(transformer::Grid)
#[serde(rename = "homography")]
Homography(transformer::Homography)
} }
@ -71,8 +68,7 @@ impl Conf {
TransformConf::Rotate(r) => Box::new(*r), TransformConf::Rotate(r) => Box::new(*r),
TransformConf::FlipH(r) => Box::new(*r), TransformConf::FlipH(r) => Box::new(*r),
TransformConf::FlipV(r) => Box::new(*r), TransformConf::FlipV(r) => Box::new(*r),
TransformConf::Grid(r) => Box::new(*r), TransformConf::Grid(r) => Box::new(*r)
TransformConf::Homography(r) => Box::new(*r),
}; };
v.push(t); v.push(t);
} }

View File

@ -1,11 +1,9 @@
mod helios; mod helios;
mod dummy;
use std::fmt; use std::fmt;
use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/}; use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/};
use crate::device::helios::HeliosDevice; use crate::device::helios::HeliosDevice;
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;
@ -59,10 +57,9 @@ pub trait Device {
} }
pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> { pub fn device_factory(config: &Conf) -> LJResult<Box<dyn Device>> {
let device : Box<dyn Device> = match &config.dac { let device = match &config.dac {
DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?), DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?),
DacFamily::Etherdream(_conf) => todo!(), DacFamily::Etherdream(_conf) => todo!(),
DacFamily::Dummy => Box::new(DummyDevice::new()?)
}; };
Ok(device) Ok(device)
} }

View File

@ -1,38 +0,0 @@
use crate::device::{Device, Status, PlaybackState};
use crate::errors::LJResult;
use crate::point::Point;
use log::debug;
pub struct DummyDevice {
state: PlaybackState
}
impl DummyDevice {
pub fn new() -> LJResult<Self> {
Ok(Self { state: PlaybackState::IDLE })
}
}
impl Device for DummyDevice {
fn status(&self) -> Status {
Status {
last_traced_at: "never".to_string(),
properties: vec!["foo".to_string()],
playback_state: self.state,
capacity: 0,
lack: "lack".to_string()
}
}
fn draw(&mut self,
line: Vec<Point>,
speed: u32,
) -> LJResult<()> {
debug!("Draw Line at speed {speed} : {:?}", line);
Ok(())
}
fn stop(&mut self) -> LJResult<()> {
Ok(())
}
}

View File

@ -9,8 +9,7 @@ pub type LJResult<T> = Result<T, Box<dyn std::error::Error>>;
pub enum LJError { pub enum LJError {
Config(ConfigError), Config(ConfigError),
RedisConnect(RedisError), RedisConnect(RedisError),
HeliosDeviceMissing, HeliosDeviceMissing
BadEDH
} }
impl fmt::Display for LJError { impl fmt::Display for LJError {
@ -27,9 +26,6 @@ impl fmt::Display for LJError {
}, },
HeliosDeviceMissing => { HeliosDeviceMissing => {
write!(f, "helios device not found") write!(f, "helios device not found")
},
BadEDH => {
write!(f, "EDH matrix is not a 3x3 matrix")
} }
} }
} }

View File

@ -4,4 +4,3 @@ pub mod errors;
pub mod device; pub mod device;
pub mod point; pub mod point;
pub mod transformer; pub mod transformer;
pub mod worldstate;

View File

@ -8,7 +8,6 @@ mod errors;
mod point; mod point;
mod transformer; mod transformer;
mod device; mod device;
mod worldstate;
use device::device_factory; use device::device_factory;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -20,7 +19,6 @@ use point::Point;
use transformer::Transformers; use transformer::Transformers;
use log::{LevelFilter, info, /* warn, */ error}; use log::{LevelFilter, info, /* warn, */ error};
use env_logger::Builder; use env_logger::Builder;
use worldstate::WorldState;
const DEFAULT_CONF_FILE: &str = "settings.toml"; const DEFAULT_CONF_FILE: &str = "settings.toml";
@ -33,7 +31,6 @@ pub fn main() {
} }
} }
fn run_all() -> LJResult<()> { fn run_all() -> LJResult<()> {
// Setup configuration file and set up logs // Setup configuration file and set up logs
let filename = std::env::args().nth(1).unwrap_or_else(|| { let filename = std::env::args().nth(1).unwrap_or_else(|| {
@ -50,8 +47,6 @@ fn run_all() -> LJResult<()> {
// Setup Redis Service // Setup Redis Service
let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?; let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?;
let mut world_state = rs.init_world_state()?;
// Setup handler for interrupt Signals // Setup handler for interrupt Signals
let running = Arc::new(AtomicBool::new(true)); let running = Arc::new(AtomicBool::new(true));
let r = running.clone(); let r = running.clone();
@ -66,49 +61,20 @@ fn run_all() -> LJResult<()> {
//dbg!(tracer); //dbg!(tracer);
// Setup geometry transformers on points lists // Setup geometry transformers on points lists
let transformers = config.get_transformers(); let transformers = config.get_transformers();
// Dispatch based on redis requests // Dispatch based on redis requests
while running.load(Ordering::SeqCst) { while running.load(Ordering::SeqCst) {
rs.set_status(tracer.status())?; rs.set_status( tracer.status())?;
let order = rs.get_order(config.laser_id)?; let order = rs.get_order(config.laser_id)?;
// 0 : Draw Normal point list if order != Order::Draw {
// 2 : Draw BLACK point list info!("Order: {:?}", order);
// 3 : Draw GRID point list
// /worldstate.rs
// /edh.rs
// 1 : Get the new EDH = reread redis key /EDH/lasernumber
// 4 : Resampler Change (longs and shorts lsteps)
// 5 : Client Key Change = reread redis key /clientkey
// 6 : Max Intensity Change = reread redis key /intensity
// 7 : kpps change = reread redis key /kpps
// 8 : color balance change = reread redis keys /red /green /blue
match order {
Order::Draw => {
let frame = get_next_frame(
&config,
&transformers,
&mut rs,
// order == Order::Black,
&world_state
)?;
// For now, draw all the time
tracer.draw(frame, 2_000)?;
}
Order::Edh => {
world_state.edh = rs.get_edh()?;
}
// Order::ClientKey => rs.client_key(),
// Order::ColorBalance => {},
_ => {
info!("Order: {:?}", order);
}
} }
let frame = get_next_frame(&config, &transformers,
&mut rs, order == Order::Black)?;
// For now, draw all the time
tracer.draw(frame, 2_000)?;
} }
info!("Exiting, stoping device."); info!("Exiting, stoping device.");
@ -135,18 +101,17 @@ 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 _black: bool,
) -> LJResult<Vec<Point>> { ) -> LJResult<Vec<Point>> {
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?; let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
let mut line: Vec<Point> = line.into_iter() let mut line: Vec<Point> = 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);
} }
//info!("Line: {:?}", line); //info!("Line: {:?}", line);
Ok(line) Ok(line)
} }

View File

@ -1,11 +1,11 @@
#[derive(Debug,Clone,Copy,Default,PartialEq)] #[derive(Debug,Clone,Copy)]
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)]
pub struct Color { pub struct Color {
r: u8, r: u8,
g: u8, g: u8,

View File

@ -2,8 +2,6 @@ use redis::{Client, Commands, Connection};
use ron::de::from_str; use ron::de::from_str;
use crate::device::Status; use crate::device::Status;
use crate::errors::{LJError, LJResult}; use crate::errors::{LJError, LJResult};
use crate::worldstate::{WorldState,EDH};
use log::info;
#[repr(u8)] #[repr(u8)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -98,23 +96,4 @@ impl RedisCtrl {
self.set(lack_key, status.lack.to_string())?; self.set(lack_key, status.lack.to_string())?;
Ok(()) Ok(())
} }
pub fn init_world_state( &mut self) -> LJResult<WorldState>{
let edh = self.get_edh()?;
info!("EDH: {:?}", edh);
Ok(WorldState {
edh,
..WorldState::default()
})
}
pub fn get_edh( &mut self ) -> LJResult<EDH> {
// Get new EDH
let edh_key = format!("/EDH/{}", self.laser_id);
let edh : String = self.connection.get(edh_key)?;
let edh : Vec<Vec<f32>> = from_str(&edh)?;
let edh = EDH::new(edh)?;
Ok(edh)
}
} }

View File

@ -5,10 +5,8 @@ mod rotate;
mod flip_horizontal; mod flip_horizontal;
mod flip_vertical; mod flip_vertical;
mod grid; mod grid;
mod homography;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState;
// re-export transformers to be abe to use it directly from transformer:: // re-export transformers to be abe to use it directly from transformer::
pub use translate::Translate; pub use translate::Translate;
@ -17,12 +15,7 @@ pub use rotate::Rotate;
pub use flip_horizontal::FlipHorizontal; pub use flip_horizontal::FlipHorizontal;
pub use flip_vertical::FlipVertical; pub use flip_vertical::FlipVertical;
pub use grid::Grid; pub use grid::Grid;
pub use self::homography::Homography;
pub trait Transformers { pub trait Transformers {
fn apply( fn apply(&self, point_list: &[Point]) -> Vec<Point>;
&self,
point_list: &[Point],
world_state: &WorldState
) -> Vec<Point>;
} }

View File

@ -1,7 +1,5 @@
use crate::transformer::Transformers; use crate::transformer::Transformers;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
/// Flip Horizontal /// Flip Horizontal
@ -12,7 +10,7 @@ pub struct FlipHorizontal {
} }
impl Transformers for FlipHorizontal { impl Transformers for FlipHorizontal {
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> { fn apply(&self, point_list: &[Point]) -> Vec<Point> {
point_list.iter() point_list.iter()
.map(| pt | { .map(| pt | {
let dx = pt.x - self.x; let dx = pt.x - self.x;

View File

@ -1,7 +1,5 @@
use crate::transformer::Transformers; use crate::transformer::Transformers;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
/// Flip Vertical /// Flip Vertical
@ -12,7 +10,7 @@ pub struct FlipVertical {
} }
impl Transformers for FlipVertical { impl Transformers for FlipVertical {
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> { fn apply(&self, point_list: &[Point]) -> Vec<Point> {
point_list.iter() point_list.iter()
.map(| pt | { .map(| pt | {
let dy = pt.y - self.y; let dy = pt.y - self.y;

View File

@ -1,7 +1,5 @@
use crate::transformer::Transformers; use crate::transformer::Transformers;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
/// Translate /// Translate
@ -46,7 +44,7 @@ fn square_box(size: f32, color: u32) -> Vec<(f32, f32, u32)> {
} }
impl Transformers for Grid { impl Transformers for Grid {
fn apply(&self, _point_list: &[Point], _ws: &WorldState) -> Vec<Point> { fn apply(&self, _point_list: &[Point]) -> Vec<Point> {
let mut sq1 = square_box(1000.0, 255 << 8); let mut sq1 = square_box(1000.0, 255 << 8);
let mut line = square_box(2000.0, 255); let mut line = square_box(2000.0, 255);
line.append(&mut sq1); line.append(&mut sq1);

View File

@ -1,64 +0,0 @@
use crate::transformer::Transformers;
use crate::point::Point;
use crate::worldstate::{WorldState,EDH};
use serde::{Serialize,Deserialize};
/// Homography
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
pub struct Homography {}
impl Transformers for Homography {
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
let edh : &EDH = &ws.edh;
point_list.iter()
.map(| point | edh.apply(point))
.collect()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn identity_matrix_let_point_unchanged() {
let p0 = Point { x: -1500.0, y: 1500.0, ..Point::default() };
let edh = EDH::new(vec![
vec![ 1.0, 0.0, 0.0 ],
vec![ 0.0, 1.0, 0.0 ],
vec![ 0.0, 0.0, 1.0 ]
]).unwrap();
let ws = WorldState { edh : edh, ..WorldState::default() };
let homography = Homography{};
let result = homography.apply(&[p0], &ws);
assert_eq!(result, vec![Point { x: -1500.0,
y: 1500.0,
..Point::default() }]);
}
#[test]
fn rotation_matrix_rotate_the_point() {
let p0 = Point { x: -1500.0, y: 1500.0, ..Point::default() };
let edh = EDH::new(vec![
vec![ 1.24107321e-03, 1.00500127e-03, 7.15439347e-01],
vec![-9.93223912e-04, 1.22652939e-03,-6.98671238e-01],
vec![ 1.06017142e-17,-4.69459541e-17, 3.32700590e-05]
]).unwrap();
let ws = WorldState { edh : edh, ..WorldState::default() };
let homography = Homography{};
let result = homography.apply(&[p0], &ws);
assert_eq!(result, vec![Point { x: 10860.557,
y: 79078.87,
..Point::default() }]);
}
}

View File

@ -1,7 +1,5 @@
use crate::transformer::Transformers; use crate::transformer::Transformers;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
/// Replicate /// Replicate
@ -14,7 +12,7 @@ pub enum Replicate {
} }
impl Transformers for Replicate { impl Transformers for Replicate {
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> { fn apply(&self, point_list: &[Point]) -> Vec<Point> {
let mut point_list2 = vec![]; let mut point_list2 = vec![];
match self { match self {
Replicate::Until(n) => { Replicate::Until(n) => {

View File

@ -1,7 +1,5 @@
use crate::transformer::Transformers; use crate::transformer::Transformers;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
//use std::f32::consts::PI; //use std::f32::consts::PI;
@ -16,7 +14,7 @@ pub struct Rotate {
} }
impl Transformers for Rotate { impl Transformers for Rotate {
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> { fn apply(&self, point_list: &[Point]) -> Vec<Point> {
point_list.iter() point_list.iter()
.map(| pt | { .map(| pt | {
let dx = pt.x - self.cx; let dx = pt.x - self.cx;

View File

@ -1,6 +1,5 @@
use crate::transformer::Transformers; use crate::transformer::Transformers;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
/// Translate /// Translate
@ -12,7 +11,7 @@ pub struct Translate {
} }
impl Transformers for Translate { impl Transformers for Translate {
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> { fn apply(&self, point_list: &[Point]) -> Vec<Point> {
point_list.iter() point_list.iter()
.map(| pt | { .map(| pt | {
Point { x: pt.x + self.x, Point { x: pt.x + self.x,

View File

@ -1,51 +0,0 @@
use crate::point::{Point,Color};
use nalgebra::base::{Matrix3,Matrix1x3};
use crate::errors::{LJError,LJResult};
use log::debug;
#[derive(Debug, Default)]
pub struct EDH {
pub matrix: Matrix3<f32>
}
impl EDH {
pub fn new(vec: Vec<Vec<f32>>) -> LJResult<EDH> {
if vec.len() != 3 ||
vec[0].len() != 3 ||
vec[1].len() != 3 ||
vec[2].len() != 3 {
return Err(Box::new(LJError::BadEDH));
}
// this is the matrix already transposed.
let matrix = Matrix3::new(vec[0][0], vec[1][0], vec[2][0],
vec[0][1], vec[1][1], vec[2][1],
vec[0][2], vec[1][2], vec[2][2]);
Ok(EDH { matrix })
}
pub fn apply(&self, point: &Point) -> Point {
let p = Matrix1x3::new(point.x, point.y, 1.0);
let p = p * self.matrix;
let new_p = Point { x: p[0] / p[2], y: p[1] / p[2], ..*point };
debug!("{:?} => {:?}", point, new_p);
new_p
}
}
#[derive(Debug, Default)]
pub struct WorldState {
pub edh: EDH,
pub resampler: Vec<f32>,
pub client_key: u8,
pub intensity: u8,
pub kpps: u32,
pub color: Color
}
impl WorldState {
}