fix code + dummy dac

This commit is contained in:
Marc Planard 2023-06-29 23:24:56 +02:00
parent ce86a1cecb
commit f307fea63c
16 changed files with 88 additions and 26 deletions

View File

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

View File

@ -19,6 +19,8 @@ pub enum DacFamily {
Helios(HeliosConf),
#[serde(rename = "etherdream")]
Etherdream(EtherDreamConf),
#[serde(rename = "dummy")]
Dummy,
}
#[derive(Serialize, Deserialize, Debug, Clone)]

View File

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

36
src/device/dummy.rs Normal file
View File

@ -0,0 +1,36 @@
use crate::device::{Device, Status, PlaybackState};
use crate::errors::{LJError, LJResult};
use crate::point::Point;
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<()> {
Ok(())
}
fn stop(&mut self) -> LJResult<()> {
Ok(())
}
}

View File

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

View File

@ -16,7 +16,7 @@ use std::sync::Arc;
use redis_ctrl::{RedisCtrl, Order};
use conf::Conf;
use errors::LJResult;
use point::{Point, Color};
use point::Point;
use transformer::Transformers;
use log::{LevelFilter, info, /* warn, */ error};
use env_logger::Builder;
@ -50,7 +50,7 @@ fn run_all() -> LJResult<()> {
// Setup Redis Service
let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?;
let mut world_state = rs.init_world_state();
let mut world_state = rs.init_world_state()?;
// Setup handler for interrupt Signals
let running = Arc::new(AtomicBool::new(true));
@ -100,7 +100,7 @@ fn run_all() -> LJResult<()> {
tracer.draw(frame, 2_000)?;
}
Order::Edh => {
let world_state.edh = rs.get_edh(),
world_state.edh = rs.get_edh()?;
}
// Order::ClientKey => rs.client_key(),

View File

@ -1,11 +1,11 @@
#[derive(Debug,Clone,Copy)]
#[derive(Debug,Clone,Copy,Default)]
pub struct Point {
pub x: f32,
pub y: f32,
pub color: Color
}
#[derive(Debug,Clone,Copy)]
#[derive(Debug,Clone,Copy,Default)]
pub struct Color {
r: u8,
g: u8,

View File

@ -2,7 +2,7 @@ use redis::{Client, Commands, Connection};
use ron::de::from_str;
use crate::device::Status;
use crate::errors::{LJError, LJResult};
use crate::worldstate::{WorldState};
use crate::worldstate::{WorldState,EDH};
#[repr(u8)]
#[derive(Debug, PartialEq)]
@ -99,14 +99,13 @@ impl RedisCtrl {
}
pub fn init_world_state( &mut self) -> LJResult<WorldState>{
WorldState
Ok(WorldState::default())
}
pub fn get_edh( &mut self ) -> LJResult<()> {
pub fn get_edh( &mut self ) -> LJResult<EDH> {
// Get new EDH
let edh = self.get("/EDH/1");
EDH( edh )
let edh : String = self.connection.get("/EDH/0")?;
let edh : Vec<Vec<f32>> = from_str(&edh)?;
Ok(EDH { matrix: edh })
}
}

View File

@ -7,6 +7,7 @@ mod flip_vertical;
mod grid;
use crate::point::Point;
use crate::worldstate::WorldState;
// re-export transformers to be abe to use it directly from transformer::
pub use translate::Translate;
@ -17,5 +18,9 @@ pub use flip_vertical::FlipVertical;
pub use grid::Grid;
pub trait Transformers {
fn apply(&self, point_list: &[Point]) -> Vec<Point>;
fn apply(
&self,
point_list: &[Point],
world_state: &WorldState
) -> Vec<Point>;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,14 +1,16 @@
use crate::point::Color;
#[derive(Debug, Default)]
pub struct EDH {
pub matrix: Matrix3
pub matrix: Vec<Vec<f32>> //Matrix3
}
#[derive(Debug, Default )]
impl EDH {
}
#[derive(Debug, Default)]
pub struct WorldState {
pub edh: EDH,
pub resampler: Vec<f32>,