fix code + dummy dac
This commit is contained in:
parent
ce86a1cecb
commit
f307fea63c
@ -15,6 +15,9 @@ 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"
|
||||||
|
@ -19,6 +19,8 @@ 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)]
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
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;
|
||||||
@ -57,9 +59,10 @@ 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 = match &config.dac {
|
let device : Box<dyn 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)
|
||||||
}
|
}
|
||||||
|
36
src/device/dummy.rs
Normal file
36
src/device/dummy.rs
Normal 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(())
|
||||||
|
}
|
||||||
|
}
|
@ -4,3 +4,4 @@ pub mod errors;
|
|||||||
pub mod device;
|
pub mod device;
|
||||||
pub mod point;
|
pub mod point;
|
||||||
pub mod transformer;
|
pub mod transformer;
|
||||||
|
pub mod worldstate;
|
||||||
|
@ -16,7 +16,7 @@ use std::sync::Arc;
|
|||||||
use redis_ctrl::{RedisCtrl, Order};
|
use redis_ctrl::{RedisCtrl, Order};
|
||||||
use conf::Conf;
|
use conf::Conf;
|
||||||
use errors::LJResult;
|
use errors::LJResult;
|
||||||
use point::{Point, Color};
|
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;
|
||||||
@ -50,7 +50,7 @@ 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();
|
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));
|
||||||
@ -100,7 +100,7 @@ fn run_all() -> LJResult<()> {
|
|||||||
tracer.draw(frame, 2_000)?;
|
tracer.draw(frame, 2_000)?;
|
||||||
}
|
}
|
||||||
Order::Edh => {
|
Order::Edh => {
|
||||||
let world_state.edh = rs.get_edh(),
|
world_state.edh = rs.get_edh()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order::ClientKey => rs.client_key(),
|
// Order::ClientKey => rs.client_key(),
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#[derive(Debug,Clone,Copy)]
|
#[derive(Debug,Clone,Copy,Default)]
|
||||||
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)]
|
#[derive(Debug,Clone,Copy,Default)]
|
||||||
pub struct Color {
|
pub struct Color {
|
||||||
r: u8,
|
r: u8,
|
||||||
g: u8,
|
g: u8,
|
||||||
|
@ -2,7 +2,7 @@ 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};
|
use crate::worldstate::{WorldState,EDH};
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -99,14 +99,13 @@ impl RedisCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_world_state( &mut self) -> LJResult<WorldState>{
|
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
|
||||||
// Get new EDH
|
let edh : String = self.connection.get("/EDH/0")?;
|
||||||
let edh = self.get("/EDH/1");
|
let edh : Vec<Vec<f32>> = from_str(&edh)?;
|
||||||
EDH( edh )
|
Ok(EDH { matrix: edh })
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ mod flip_vertical;
|
|||||||
mod grid;
|
mod grid;
|
||||||
|
|
||||||
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,5 +18,9 @@ pub use flip_vertical::FlipVertical;
|
|||||||
pub use grid::Grid;
|
pub use grid::Grid;
|
||||||
|
|
||||||
pub trait Transformers {
|
pub trait Transformers {
|
||||||
fn apply(&self, point_list: &[Point]) -> Vec<Point>;
|
fn apply(
|
||||||
|
&self,
|
||||||
|
point_list: &[Point],
|
||||||
|
world_state: &WorldState
|
||||||
|
) -> Vec<Point>;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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
|
||||||
@ -10,7 +12,7 @@ pub struct FlipHorizontal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Transformers for 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()
|
point_list.iter()
|
||||||
.map(| pt | {
|
.map(| pt | {
|
||||||
let dx = pt.x - self.x;
|
let dx = pt.x - self.x;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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
|
||||||
@ -10,7 +12,7 @@ pub struct FlipVertical {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Transformers for 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()
|
point_list.iter()
|
||||||
.map(| pt | {
|
.map(| pt | {
|
||||||
let dy = pt.y - self.y;
|
let dy = pt.y - self.y;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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
|
||||||
@ -44,7 +46,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]) -> Vec<Point> {
|
fn apply(&self, _point_list: &[Point], _ws: &WorldState) -> 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);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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
|
||||||
@ -12,7 +14,7 @@ pub enum Replicate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Transformers for 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![];
|
let mut point_list2 = vec![];
|
||||||
match self {
|
match self {
|
||||||
Replicate::Until(n) => {
|
Replicate::Until(n) => {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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;
|
||||||
|
|
||||||
@ -14,7 +16,7 @@ pub struct Rotate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Transformers for 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()
|
point_list.iter()
|
||||||
.map(| pt | {
|
.map(| pt | {
|
||||||
let dx = pt.x - self.cx;
|
let dx = pt.x - self.cx;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
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
|
||||||
@ -11,7 +12,7 @@ pub struct Translate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Transformers for 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()
|
point_list.iter()
|
||||||
.map(| pt | {
|
.map(| pt | {
|
||||||
Point { x: pt.x + self.x,
|
Point { x: pt.x + self.x,
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
|
use crate::point::Color;
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
pub struct EDH {
|
pub struct EDH {
|
||||||
pub matrix: Matrix3
|
pub matrix: Vec<Vec<f32>> //Matrix3
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default )]
|
|
||||||
impl EDH {
|
impl EDH {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
pub struct WorldState {
|
pub struct WorldState {
|
||||||
pub edh: EDH,
|
pub edh: EDH,
|
||||||
pub resampler: Vec<f32>,
|
pub resampler: Vec<f32>,
|
||||||
|
Loading…
Reference in New Issue
Block a user