From 76cc1c12755e452514098e18c76e0926a8f144bc Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 6 Jul 2023 22:18:44 +0200 Subject: [PATCH 1/9] wip --- Cargo.toml | 1 + copyme.settings.toml | 5 ++ src/device.rs | 3 +- src/device/etherdream.rs | 108 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/device/etherdream.rs diff --git a/Cargo.toml b/Cargo.toml index 61520a8..ca0464a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ chrono = "0.4.26" config = "0.13.3" ctrlc = "3.4.0" env_logger = "0.10.0" +ether-dream = "0.2.5" helios-dac = { version = "0.1", default-features = false, features = ["native"] } log = "0.4.18" diff --git a/copyme.settings.toml b/copyme.settings.toml index 5f9eaff..19182bb 100644 --- a/copyme.settings.toml +++ b/copyme.settings.toml @@ -29,3 +29,8 @@ y = 2000 [[transformers]] [transformers.replicate] Until = 48 + +# Never remove this : this is mandatory +[[transformers]] +[transformers.intensity] + diff --git a/src/device.rs b/src/device.rs index c97276c..91027d8 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,6 +1,7 @@ mod helios; mod dummy; +mod etherdream; use std::fmt; use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/}; @@ -35,7 +36,7 @@ impl fmt::Display for PlaybackState { } } -#[derive(Debug)] +#[derive(Debug, Default )] pub struct Status { pub last_traced_at: String, pub properties: Vec, diff --git a/src/device/etherdream.rs b/src/device/etherdream.rs new file mode 100644 index 0000000..fec964e --- /dev/null +++ b/src/device/etherdream.rs @@ -0,0 +1,108 @@ +use ether_dream::{dac}; + + + +use crate::conf::EtherDreamConf; +use crate::device::{Device, Status, PlaybackState}; +use crate::errors::{LJError, LJResult}; +use crate::point::Point; +use chrono::Utc; + +pub struct EtherdreamDevice { + pub conf: EtherDreamConf, + dac: dac, + sent_points: u16, + state: PlaybackState, + lack: String, + last_traced_at : String +} + +impl EtherdreamDevice { + pub fn new(conf: &EtherDreamConf) -> LJResult { + let id = conf.id; + + // // Todo : use the config + // let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts() + // .expect("failed to bind to UDP socket") + // .filter_map(Result::ok) + // .next() + // .unwrap(); + // let mac_address = dac::MacAddress(dac_broadcast.mac_address); + // + // println!( + // "Discovered DAC \"{}\" at \"{}\"! Connecting...", + // mac_address, source_addr + // ); + + + // Establish the TCP connection. + let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap(); + + // If we want to create an animation (in our case a moving sine wave) we need a frame rate. + let frames_per_second = 60.0; + // Lets use the DAC at an eighth the maximum scan rate. + let points_per_second = stream.dac().max_point_rate / 32; + // Determine the number of points per frame given our target frame and point rates. + let points_per_frame = (points_per_second as f32 / frames_per_second) as u16; + + // Prepare the DAC's playback engine and await the repsonse. + stream + .queue_commands() + .prepare_stream() + .submit() + .err() + .map(|err| { + eprintln!( + "err occurred when submitting PREPARE_STREAM \ + command and listening for response: {}", + err + ); + }); + + println!("Ready for playback!"); + + Ok(Self { + conf: (*conf).clone(), + dac, + sent_points: 0, + state: PlaybackState::PREPARE, + lack: "".to_string(), + last_traced_at: "1985-04-12T23:20:50.52Z".to_string() + }) + } +} + +impl Device for EtherdreamDevice { + fn status(&self) -> Status { + + let lack = self.lack.clone(); + Status { + last_traced_at: self.last_traced_at.clone(), + properties: vec!["foo".to_string()], + playback_state: self.state, + capacity: self.sent_points, + lack, + } + } + + fn draw(&mut self, + line: Vec, + speed: u32, + ) -> LJResult<()> { + self.state = PlaybackState::IDLE; + while let Ok(DeviceStatus::NotReady) = self.dac.status() {} + self.state = PlaybackState::PLAYING; + + let points: Vec = line.into_iter().map(|p| p.into()).collect(); + let frame = Frame::new(speed, points.clone()); + self.dac.write_frame(frame.clone())?; + self.sent_points = points.len() as u16; + self.last_traced_at = Utc::now().to_rfc3339(); + Ok(()) + } + + fn stop(&mut self) -> LJResult<()> { + self.dac.stop()?; + Ok(()) + } +} From e4580e0e538d58a494fd61093a9f0fa00ba41c89 Mon Sep 17 00:00:00 2001 From: alban Date: Sun, 9 Jul 2023 22:16:01 +0200 Subject: [PATCH 2/9] feat: add grid --- src/device.rs | 2 + src/device/common.rs | 31 ------------ src/device/dummy.rs | 7 ++- src/device/helios.rs | 33 ++++++++++-- src/main.rs | 116 +++++++++++++++++++++++-------------------- src/point.rs | 55 +++++++++++--------- src/worldstate.rs | 65 ++++++++++++------------ 7 files changed, 164 insertions(+), 145 deletions(-) delete mode 100644 src/device/common.rs diff --git a/src/device.rs b/src/device.rs index c97276c..79f0114 100644 --- a/src/device.rs +++ b/src/device.rs @@ -9,6 +9,7 @@ use crate::device::dummy::DummyDevice; use crate::errors::LJResult; use crate::point::Point; use serde::Serialize; +use crate::redis_ctrl::Line; /* self.protocol_version, @@ -56,6 +57,7 @@ pub trait Device { speed: u32, ) -> LJResult<()>; fn stop(&mut self) -> LJResult<()>; + fn grid(&mut self) -> Vec; } pub fn device_factory(config: &Conf) -> LJResult> { diff --git a/src/device/common.rs b/src/device/common.rs deleted file mode 100644 index 020ad4d..0000000 --- a/src/device/common.rs +++ /dev/null @@ -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 -} - -pub trait Device { - /** - fn intersect(&self, orig : &Vec3, dir : &Vec3) -> Option; - fn get_surface(&self, v : &Vec3) -> Vec3; - fn get_normal(&self, v : &Vec3) -> Vec3; - fn get_material(&self) -> &dyn Material; - **/ - - fn status( &self ) -> Status; - -} diff --git a/src/device/dummy.rs b/src/device/dummy.rs index e4c9e42..544d6c8 100644 --- a/src/device/dummy.rs +++ b/src/device/dummy.rs @@ -1,6 +1,6 @@ use crate::device::{Device, Status, PlaybackState}; use crate::errors::LJResult; -use crate::point::Point; +use crate::point::{Color, Point}; use log::debug; pub struct DummyDevice { @@ -35,4 +35,9 @@ impl Device for DummyDevice { fn stop(&mut self) -> LJResult<()> { Ok(()) } + fn grid(&mut self) -> Vec { + vec!( + Point{ x: 0 as f32, y: 0 as f32, color:Color{ r: 0, g: 0, b: 0 }} + ) + } } diff --git a/src/device/helios.rs b/src/device/helios.rs index eb59d16..42373f0 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -13,8 +13,9 @@ use helios_dac::{ use crate::conf::HeliosConf; use crate::device::{Device, Status, PlaybackState}; use crate::errors::{LJError, LJResult}; -use crate::point::Point; +use crate::point::{Color, Point}; use chrono::Utc; +use crate::redis_ctrl::Line; pub struct HeliosDevice { pub conf: HeliosConf, @@ -22,7 +23,7 @@ pub struct HeliosDevice { sent_points: u16, state: PlaybackState, lack: String, - last_traced_at : String + last_traced_at: String, } impl HeliosDevice { @@ -40,17 +41,16 @@ impl HeliosDevice { sent_points: 0, state: PlaybackState::PREPARE, 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 { fn status(&self) -> Status { - let lack = self.lack.clone(); Status { - last_traced_at: self.last_traced_at.clone(), + last_traced_at: self.last_traced_at.clone(), properties: vec!["foo".to_string()], playback_state: self.state, capacity: self.sent_points, @@ -78,4 +78,27 @@ impl Device for HeliosDevice { self.dac.stop()?; Ok(()) } + + fn grid(&mut self) -> Vec { + 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 }, + ] + } } diff --git a/src/main.rs b/src/main.rs index 9eeca6d..c7e8ccb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,10 +13,10 @@ mod worldstate; use device::device_factory; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use redis_ctrl::{RedisCtrl, Order}; +use redis_ctrl::{RedisCtrl, Order, Line}; use conf::Conf; use errors::LJResult; -use point::{Point,Color}; +use point::{Point, Color}; use transformer::Transformers; use log::{LevelFilter, info, /* warn, */ error}; use env_logger::Builder; @@ -51,8 +51,8 @@ fn run_all() -> LJResult<()> { let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?; let mut world_state = rs.init_world_state()?; - info!("WorldState: {:?}", world_state); - + info!("WorldState: {:?}", world_state); + // Setup handler for interrupt Signals let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); @@ -62,6 +62,7 @@ fn run_all() -> LJResult<()> { // Setup Laser Device based on conf 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... //dbg!(tracer); @@ -78,8 +79,6 @@ fn run_all() -> LJResult<()> { // 2 : Draw BLACK point list // 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) @@ -88,28 +87,29 @@ fn run_all() -> LJResult<()> { // 7 : kpps change = reread redis key /kpps // 8 : color balance change = reread redis keys /red /green /blue match order { - Order::Draw | Order::Black => { - world_state.black = order == Order::Black; - + Order::Draw | Order::Black | Order::Grid => { + world_state.draw_black = order == Order::Black; + world_state.draw_grid = order == Order::Grid; + let frame = get_next_frame( &config, &transformers, - &mut rs, - &world_state + &mut rs, + &world_state, )?; // For now, draw all the time tracer.draw(frame, world_state.kpps)?; - }, - Order::Intensity => { - world_state.intensity = rs.get_int("intensity")? - .try_into()?; - }, + } + Order::Intensity => { + world_state.intensity = rs.get_int("intensity")? + .try_into()?; + } Order::Edh => { world_state.edh = rs.get_edh()?; - }, + } Order::Kpps => { world_state.kpps = rs.get_int("kpps")?; - }, + } // Order::ClientKey => rs.client_key(), // Order::ColorBalance => {}, @@ -143,42 +143,52 @@ fn get_next_frame( config: &Conf, transformers: &[Box], rs: &mut RedisCtrl, - world_state : &WorldState + world_state: &WorldState, ) -> LJResult> { - let format_key = format!("{}{}", - world_state.client_key, - config.laser_id); - let line = rs.get_line(&format_key)?; - let mut line: Vec = line.into_iter() - .map(|tpl| tpl.into()) - .collect(); - - for transformer in transformers { - line = transformer.apply(&line, world_state); - } + let format_key = format!("{}{}", + world_state.client_key, + config.laser_id); - info!("-> {}", world_state.black); - - // LIMITER and BLACK - line = line.into_iter() - .map(| p | { - - let color = if world_state.black { - Color { r: 0, g: 0, b: 0 } - } else { - Color { - r: p.color.r.min(world_state.intensity), - g: p.color.g.min(world_state.intensity), - b: p.color.b.min(world_state.intensity) - } - }; - Point { color, - ..p - } - }) - .collect(); - - //info!("Line: {:?}", line); - Ok(line) + // Handle the grid case + + let mut line : Vec; + 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()) + .collect(); + }; + + + for transformer in transformers { + line = transformer.apply(&line, world_state); + } + + info!("Draw Black -> {}", world_state.draw_black); + info!("Draw Grid -> {}", world_state.draw_grid); + + // LIMITER and BLACK + line = line.into_iter() + .map(|p| { + let color = if world_state.draw_black { + Color { r: 0, g: 0, b: 0 } + } else { + Color { + r: p.color.r.min(world_state.intensity), + g: p.color.g.min(world_state.intensity), + b: p.color.b.min(world_state.intensity), + } + }; + Point { + color, + ..p + } + }) + .collect(); + + //info!("Line: {:?}", line); + Ok(line) } diff --git a/src/point.rs b/src/point.rs index 21c65c8..ed18697 100644 --- a/src/point.rs +++ b/src/point.rs @@ -1,34 +1,43 @@ -#[derive(Debug,Clone,Copy,Default,PartialEq)] +#[derive(Debug, Clone, Copy, Default, PartialEq)] pub struct Point { - pub x: f32, - pub y: f32, - pub color: Color + pub x: f32, + pub y: f32, + pub color: Color, } -#[derive(Debug,Clone,Copy,Default,PartialEq)] +#[derive(Debug, Clone, Copy, Default, PartialEq)] pub struct Color { - pub r: u8, - pub g: u8, - pub b: u8 + pub r: u8, + pub g: u8, + pub 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 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 { + 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 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 + 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, + } } - } } diff --git a/src/worldstate.rs b/src/worldstate.rs index 24bb22a..7461c14 100644 --- a/src/worldstate.rs +++ b/src/worldstate.rs @@ -1,52 +1,53 @@ -use crate::point::{Point,Color}; -use nalgebra::base::{Matrix3,Matrix1x3}; -use crate::errors::{LJError,LJResult}; +use crate::point::{Point, Color}; +use nalgebra::base::{Matrix3, Matrix1x3}; +use crate::errors::{LJError, LJResult}; use log::debug; +use crate::redis_ctrl::Line; #[derive(Debug, Default)] pub struct EDH { - pub matrix: Matrix3 + pub matrix: Matrix3, } impl EDH { - pub fn new(vec: Vec>) -> LJResult { - if vec.len() != 3 || - vec[0].len() != 3 || - vec[1].len() != 3 || - vec[2].len() != 3 { - return Err(Box::new(LJError::BadEDH)); - } + pub fn new(vec: Vec>) -> LJResult { + 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]); + // 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 }) - } + 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 - } + 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, - pub client_key: String, //u8, + pub client_key: String, pub intensity: u8, pub kpps: u32, - pub color: Color, - pub black: bool + pub color: Color, + pub draw_black: bool, + pub draw_grid: bool, + pub grid: Vec, } -impl WorldState { - -} +impl WorldState {} From 6fa884699760832fdc9b2e1c596b80545bd567e7 Mon Sep 17 00:00:00 2001 From: alban Date: Sun, 9 Jul 2023 22:44:15 +0200 Subject: [PATCH 3/9] feat: add get_client_key + cleanup --- src/device.rs | 1 - src/device/helios.rs | 1 - src/main.rs | 31 ++++++++++++++++--------------- src/redis_ctrl.rs | 5 +++++ src/worldstate.rs | 3 +-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/device.rs b/src/device.rs index 79f0114..e3a6270 100644 --- a/src/device.rs +++ b/src/device.rs @@ -9,7 +9,6 @@ use crate::device::dummy::DummyDevice; use crate::errors::LJResult; use crate::point::Point; use serde::Serialize; -use crate::redis_ctrl::Line; /* self.protocol_version, diff --git a/src/device/helios.rs b/src/device/helios.rs index 42373f0..59e5a54 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -15,7 +15,6 @@ use crate::device::{Device, Status, PlaybackState}; use crate::errors::{LJError, LJResult}; use crate::point::{Color, Point}; use chrono::Utc; -use crate::redis_ctrl::Line; pub struct HeliosDevice { pub conf: HeliosConf, diff --git a/src/main.rs b/src/main.rs index c7e8ccb..16cf14d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ mod worldstate; use device::device_factory; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use redis_ctrl::{RedisCtrl, Order, Line}; +use redis_ctrl::{RedisCtrl, Order}; use conf::Conf; use errors::LJResult; use point::{Point, Color}; @@ -75,22 +75,15 @@ fn run_all() -> LJResult<()> { rs.set_status(tracer.status())?; let order = rs.get_order(config.laser_id)?; - // 0 : Draw Normal point list - // 2 : Draw BLACK point list - // 3 : Draw GRID point list - // 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 | Order::Black | Order::Grid => { + // 0 : Draw Normal point list + // 2 : Draw BLACK point list + // 3 : Draw GRID point list world_state.draw_black = order == Order::Black; world_state.draw_grid = order == Order::Grid; - let frame = get_next_frame( &config, &transformers, @@ -101,19 +94,27 @@ fn run_all() -> LJResult<()> { tracer.draw(frame, world_state.kpps)?; } Order::Intensity => { + // 6 : Max Intensity Change = reread redis key /intensity world_state.intensity = rs.get_int("intensity")? .try_into()?; } Order::Edh => { + // 1 : Get the new EDH = reread redis key /EDH/lasernumber world_state.edh = rs.get_edh()?; } Order::Kpps => { + // 7 : kpps change = reread redis key /kpps world_state.kpps = rs.get_int("kpps")?; } - - // Order::ClientKey => rs.client_key(), + Order::ClientKey => { + world_state.client_key = rs.get_client_key()?; + }, // Order::ColorBalance => {}, _ => { + // 4 : Resampler Change (longs and shorts lsteps) + // 5 : Client Key Change = reread redis key /clientkey + // 8 : color balance change = reread redis keys /red /green /blue + // 9 : poweroff LJ world_state.intensity = rs.get_int("intensity")? info!("Order: {:?}", order); } } @@ -151,12 +152,12 @@ fn get_next_frame( // Handle the grid case - let mut line : Vec; + let mut line: Vec; if world_state.draw_grid { line = world_state.grid.clone(); } else { let redis_line = rs.get_line(&format_key)?; - line = redis_line.into_iter() + line = redis_line.into_iter() .map(|tpl| tpl.into()) .collect(); }; diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index 4b13d8a..363fdc1 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -118,6 +118,11 @@ impl RedisCtrl { Ok(edh) } + pub fn get_client_key( &mut self ) -> LJResult { + let key : u8 = self.connection.get("/clientkey")?; + Ok(key as u8) + } + pub fn get_int(&mut self, key: &str ) -> LJResult { // Get new Int let fmt = format!("/{key}/{}", self.laser_id); diff --git a/src/worldstate.rs b/src/worldstate.rs index 7461c14..1f6bea2 100644 --- a/src/worldstate.rs +++ b/src/worldstate.rs @@ -2,7 +2,6 @@ use crate::point::{Point, Color}; use nalgebra::base::{Matrix3, Matrix1x3}; use crate::errors::{LJError, LJResult}; use log::debug; -use crate::redis_ctrl::Line; #[derive(Debug, Default)] pub struct EDH { @@ -41,7 +40,7 @@ impl EDH { pub struct WorldState { pub edh: EDH, pub resampler: Vec, - pub client_key: String, + pub client_key: u8, pub intensity: u8, pub kpps: u32, pub color: Color, From ffba2efeedfbb15d84ae79d0eef26237a32ff17d Mon Sep 17 00:00:00 2001 From: alban Date: Sun, 16 Jul 2023 20:26:45 +0200 Subject: [PATCH 4/9] fix: conf for etherdream uses ip --- src/conf.rs | 2 +- tests/settings/valid_etherdream.toml | 2 +- tests/test_conf.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf.rs b/src/conf.rs index 7d91cad..2996c7d 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -30,7 +30,7 @@ pub struct HeliosConf { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct EtherDreamConf { - pub url: String + pub ip: String } #[derive(Serialize, Deserialize, Debug, Clone)] diff --git a/tests/settings/valid_etherdream.toml b/tests/settings/valid_etherdream.toml index b136ccf..836e934 100644 --- a/tests/settings/valid_etherdream.toml +++ b/tests/settings/valid_etherdream.toml @@ -12,4 +12,4 @@ redis_url = "redis://127.0.0.1:6379/" # For Etherdream. IP of the DAC [dac.etherdream] -url = "192.168.1.68" +ip = "192.168.1.68" diff --git a/tests/test_conf.rs b/tests/test_conf.rs index 1c7b77b..0dcb123 100644 --- a/tests/test_conf.rs +++ b/tests/test_conf.rs @@ -28,7 +28,7 @@ fn it_finds_struct_fields() { fn it_finds_etherdream_fields() { let config = Conf::new("tests/settings/valid_etherdream").unwrap(); assert!(match config.dac { - DacFamily::Etherdream(EtherDreamConf { url }) if url == "192.168.1.68" => true, + DacFamily::Etherdream(EtherDreamConf { ip }) if ip == "192.168.1.68" => true, _ => false, }); } From 86e32e08b11bff69cadd49bf7010eacba9e22f4e Mon Sep 17 00:00:00 2001 From: alban Date: Sun, 16 Jul 2023 20:28:06 +0200 Subject: [PATCH 5/9] feat: adds Etherdream device --- src/device.rs | 32 +++---- src/device/dummy.rs | 2 +- src/device/etherdream.rs | 181 ++++++++++++++++++++++++--------------- src/device/helios.rs | 2 +- src/errors.rs | 63 ++++++++------ src/main.rs | 12 ++- src/point.rs | 21 +++++ 7 files changed, 190 insertions(+), 123 deletions(-) diff --git a/src/device.rs b/src/device.rs index 83ae0fe..fe28f74 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,4 +1,3 @@ - mod helios; mod dummy; mod etherdream; @@ -10,6 +9,7 @@ use crate::device::dummy::DummyDevice; use crate::errors::LJResult; use crate::point::Point; use serde::Serialize; +use crate::device::etherdream::EtherdreamDevice; /* self.protocol_version, @@ -27,22 +27,24 @@ self.point_count #[derive(Debug, PartialEq, Serialize, Copy, Clone)] pub enum PlaybackState { IDLE = 0, - PREPARE, - PLAYING, -} -impl fmt::Display for PlaybackState { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{:?}", self) - } + PREPARE = 1, + PLAYING = 2, + UNKNOWN = 99, } -#[derive(Debug, Default )] +impl fmt::Display for PlaybackState { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{:?}", self) + } +} + +#[derive(Debug)] pub struct Status { pub last_traced_at: String, pub properties: Vec, pub playback_state: PlaybackState, pub capacity: u16, - pub lack: String + pub lack: String, } // /lstt/lasernumber etherdream last_status.playback_state (0: idle 1: prepare 2: playing) @@ -50,7 +52,7 @@ pub struct Status { // /lack/lasernumber "a": ACK "F": Full "I": invalid. 64 or 35 for no connection. pub trait Device { - fn status(&self) -> Status; + fn status(&mut self) -> Status; fn draw( &mut self, frame: Vec, @@ -61,10 +63,10 @@ pub trait Device { } pub fn device_factory(config: &Conf) -> LJResult> { - let device : Box = match &config.dac { - DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?), - DacFamily::Etherdream(_conf) => todo!(), - DacFamily::Dummy => Box::new(DummyDevice::new()?) + let device: Box = match &config.dac { + DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)?), + DacFamily::Etherdream( conf) => Box::new( EtherdreamDevice::new(conf)?), + DacFamily::Dummy => Box::new(DummyDevice::new()?) }; Ok(device) } diff --git a/src/device/dummy.rs b/src/device/dummy.rs index 544d6c8..724d132 100644 --- a/src/device/dummy.rs +++ b/src/device/dummy.rs @@ -14,7 +14,7 @@ impl DummyDevice { } impl Device for DummyDevice { - fn status(&self) -> Status { + fn status(&mut self) -> Status { Status { last_traced_at: "never".to_string(), properties: vec!["foo".to_string()], diff --git a/src/device/etherdream.rs b/src/device/etherdream.rs index fec964e..e620f61 100644 --- a/src/device/etherdream.rs +++ b/src/device/etherdream.rs @@ -1,108 +1,147 @@ -use ether_dream::{dac}; - - +use std::time; +use std::net::SocketAddr; +use ether_dream::dac::stream::connect; +use ether_dream::dac::Stream; use crate::conf::EtherDreamConf; use crate::device::{Device, Status, PlaybackState}; use crate::errors::{LJError, LJResult}; -use crate::point::Point; -use chrono::Utc; +use crate::point::{Color, Point}; +use ether_dream::protocol::{DacBroadcast, DacStatus}; +use log::info; +#[warn(dead_code)] pub struct EtherdreamDevice { pub conf: EtherDreamConf, - dac: dac, - sent_points: u16, - state: PlaybackState, + dac: DacBroadcast, + // source_address: SocketAddr, + stream: Stream, + // sent_points: u16, lack: String, - last_traced_at : String + last_traced_at: String, } impl EtherdreamDevice { pub fn new(conf: &EtherDreamConf) -> LJResult { - let id = conf.id; - - // // Todo : use the config - // let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts() - // .expect("failed to bind to UDP socket") - // .filter_map(Result::ok) - // .next() - // .unwrap(); - // let mac_address = dac::MacAddress(dac_broadcast.mac_address); - // - // println!( - // "Discovered DAC \"{}\" at \"{}\"! Connecting...", - // mac_address, source_addr - // ); - - - // Establish the TCP connection. - let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap(); - - // If we want to create an animation (in our case a moving sine wave) we need a frame rate. - let frames_per_second = 60.0; - // Lets use the DAC at an eighth the maximum scan rate. - let points_per_second = stream.dac().max_point_rate / 32; - // Determine the number of points per frame given our target frame and point rates. - let points_per_frame = (points_per_second as f32 / frames_per_second) as u16; - - // Prepare the DAC's playback engine and await the repsonse. - stream - .queue_commands() - .prepare_stream() - .submit() - .err() - .map(|err| { - eprintln!( - "err occurred when submitting PREPARE_STREAM \ - command and listening for response: {}", - err - ); - }); - - println!("Ready for playback!"); - + let (dac, _source_address, stream) = EtherdreamDevice::get_dac(conf)?; + // let (dac, source_address) = EtherdreamDevice::get_dac(conf)?; Ok(Self { conf: (*conf).clone(), dac, - sent_points: 0, - state: PlaybackState::PREPARE, + // source_address, + stream, + // sent_points: 0, 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(), }) } + pub fn get_dac(conf: &EtherDreamConf) -> LJResult<(DacBroadcast, SocketAddr, Stream)> { + let ip = &conf.ip; + let dac_broadcast = ether_dream::recv_dac_broadcasts()?; + dac_broadcast.set_nonblocking(true)?; + dac_broadcast.set_timeout(Some(time::Duration::new(60, 30)))?; + let broadcast = dac_broadcast + .filter_map(|result| { + info!("Received new broadcast {:?}", result); + if result.is_err() { return None; } + let (dac, source_addr) = result.unwrap(); + if source_addr.is_ipv6() { return None; } + if source_addr.ip().to_string() != ip.clone() { return None; } + info!("Valid broadcast"); + Some(Ok((dac, source_addr))) + }) + .next() + .ok_or(LJError::EtherdreamError("Failed to receive broadcast".to_string()))?; + match broadcast { + Err(err) => { + Err(Box::new(LJError::EtherdreamConnectError(err))) + } + Ok((dac, source_addr)) => { + let stream = EtherdreamDevice::get_tcp_stream(&dac, &source_addr)?; + Ok((dac, source_addr, stream)) + } + } + } + + pub fn get_tcp_stream(dac: &DacBroadcast, source_address: &SocketAddr) -> LJResult { + // Establish the TCP connection. + let mut stream = connect(dac, source_address.ip())?; + + // Prepare stream + stream + .queue_commands() + .prepare_stream() + .submit() + .err() + .map(|err| { + eprintln!( + "err occurred when submitting PREPARE_STREAM \ + command and listening for response: {}", + err + ); + }); + + Ok(stream) + } + + + pub fn check_tcp_stream(&mut self) -> LJResult<()> { + // todo Reinit stream if needed + // self.stream = EtherdreamDevice::get_tcp_stream(&self.dac, &self.source_address)? + Ok(()) + } + + // Determine the number of points needed to fill the DAC. + fn points_to_generate(&self) -> usize { + self.dac.buffer_capacity as usize - 1 - self.dac.dac_status.buffer_fullness as usize + } } impl Device for EtherdreamDevice { - fn status(&self) -> Status { + fn status(&mut self) -> Status { + let _ = self.check_tcp_stream(); + + // "a": ACK "F": Full "I": invalid. 64 or 35 for no connection. + let playback_state = match self.dac.dac_status.playback_state { + DacStatus::PLAYBACK_IDLE => PlaybackState::IDLE, + DacStatus::PLAYBACK_PREPARED => PlaybackState::PREPARE, + DacStatus::PLAYBACK_PLAYING => PlaybackState::PLAYING, + _ => PlaybackState::UNKNOWN + }; - let lack = self.lack.clone(); Status { - last_traced_at: self.last_traced_at.clone(), + last_traced_at: self.last_traced_at.clone(), properties: vec!["foo".to_string()], - playback_state: self.state, - capacity: self.sent_points, - lack, + playback_state, + capacity: self.dac.dac_status.buffer_fullness, + lack: String::from(&self.lack), } } fn draw(&mut self, line: Vec, - speed: u32, + _speed: u32, ) -> LJResult<()> { - self.state = PlaybackState::IDLE; - while let Ok(DeviceStatus::NotReady) = self.dac.status() {} - self.state = PlaybackState::PLAYING; - - let points: Vec = line.into_iter().map(|p| p.into()).collect(); - let frame = Frame::new(speed, points.clone()); - self.dac.write_frame(frame.clone())?; - self.sent_points = points.len() as u16; - self.last_traced_at = Utc::now().to_rfc3339(); + let n_points = self.points_to_generate(); + self.stream + .queue_commands() + .data(line.into_iter().map(|point| point.into()).take(n_points)) + .submit()?; Ok(()) } fn stop(&mut self) -> LJResult<()> { - self.dac.stop()?; + self.stream + .queue_commands() + .stop() + .submit() + .expect("err occurred when submitting STOP command and listening for response"); Ok(()) } + + fn grid(&mut self) -> Vec { + vec!( + Point { x: 0.0, y: 0.0, color: Color { r: 255, g: 255, b: 255 } } + ) + } } diff --git a/src/device/helios.rs b/src/device/helios.rs index 59e5a54..19a346c 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -46,7 +46,7 @@ impl HeliosDevice { } impl Device for HeliosDevice { - fn status(&self) -> Status { + fn status(&mut self) -> Status { let lack = self.lack.clone(); Status { last_traced_at: self.last_traced_at.clone(), diff --git a/src/errors.rs b/src/errors.rs index 1173dbe..16237d5 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,5 +1,5 @@ use std::error::Error; -use std::fmt; +use std::{fmt, io}; use redis::RedisError; use config::ConfigError; @@ -7,41 +7,48 @@ pub type LJResult = Result>; #[derive(Debug)] pub enum LJError { - Config(ConfigError), - RedisConnect(RedisError), - HeliosDeviceMissing, - BadEDH + Config(ConfigError), + RedisConnect(RedisError), + HeliosDeviceMissing, + BadEDH, + EtherdreamError(String), + EtherdreamConnectError(io::Error), } impl fmt::Display for LJError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - use LJError::*; - - match self { - Config(err) => { - write!(f, "unable to load config file: {err}") - }, + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use LJError::*; - RedisConnect(err) => { - write!(f, "unable to connect to redis server: {err}") - }, - HeliosDeviceMissing => { - write!(f, "helios device not found") - }, - BadEDH => { - write!(f, "EDH matrix is not a 3x3 matrix") - } + match self { + Config(err) => { + write!(f, "unable to load config file: {err}") + } + RedisConnect(err) => { + write!(f, "unable to connect to redis server: {err}") + } + HeliosDeviceMissing => { + write!(f, "helios device not found") + } + BadEDH => { + write!(f, "EDH matrix is not a 3x3 matrix") + } + EtherdreamError(msg) => { + write!(f, "Unexpected Etherdream device error: {msg}") + } + EtherdreamConnectError(err) => { + write!(f, "Failed to retrieve Etherdream device: {err}") + } + } } - } } impl Error for LJError { - fn source(&self) -> Option<&(dyn Error + 'static)> { - use LJError::*; + fn source(&self) -> Option<&(dyn Error + 'static)> { + use LJError::*; - match self { - RedisConnect(err) => Some(err), - _ => None + match self { + RedisConnect(err) => Some(err), + _ => None + } } - } } diff --git a/src/main.rs b/src/main.rs index 16cf14d..8e88018 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,7 +114,7 @@ fn run_all() -> LJResult<()> { // 4 : Resampler Change (longs and shorts lsteps) // 5 : Client Key Change = reread redis key /clientkey // 8 : color balance change = reread redis keys /red /green /blue - // 9 : poweroff LJ world_state.intensity = rs.get_int("intensity")? + // 9 : poweroff LJ info!("Order: {:?}", order); } } @@ -152,17 +152,15 @@ fn get_next_frame( // Handle the grid case - let mut line: Vec; - if world_state.draw_grid { - line = world_state.grid.clone(); + let mut line: Vec = if world_state.draw_grid { + world_state.grid.clone() } else { let redis_line = rs.get_line(&format_key)?; - line = redis_line.into_iter() + redis_line.into_iter() .map(|tpl| tpl.into()) - .collect(); + .collect() }; - for transformer in transformers { line = transformer.apply(&line, world_state); } diff --git a/src/point.rs b/src/point.rs index ed18697..b64a01d 100644 --- a/src/point.rs +++ b/src/point.rs @@ -1,3 +1,5 @@ +use ether_dream::protocol::DacPoint; + #[derive(Debug, Clone, Copy, Default, PartialEq)] pub struct Point { pub x: f32, @@ -41,3 +43,22 @@ impl From for helios_dac::Point { } } } + +impl From for DacPoint { + fn from(pt: Point) -> DacPoint { + let control = 0; + let (u1, u2) = (0, 0); + let i = 255; + DacPoint { + control, + x: pt.x as i16, + y: pt.y as i16, + i, + r: pt.color.r.into(), + g: pt.color.g.into(), + b: pt.color.b.into(), + u1, + u2, + } + } +} From afaa397a524bcb0a6fdea875a96bf473299af8d2 Mon Sep 17 00:00:00 2001 From: alban Date: Sun, 16 Jul 2023 23:12:10 +0200 Subject: [PATCH 6/9] fix: the settings should use ip for etherdream --- copyme.settings.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/copyme.settings.toml b/copyme.settings.toml index 19182bb..fa9d255 100644 --- a/copyme.settings.toml +++ b/copyme.settings.toml @@ -20,7 +20,7 @@ id = 0 # For Etherdream. IP of the DAC # [dac.etherdream] -# url = "192.168.1.68" +# ip = "192.168.1.68" [[transformers]] [transformers.translate] From 60121a01c263a7c8ba84edd75b6d376acade61b1 Mon Sep 17 00:00:00 2001 From: alban Date: Mon, 17 Jul 2023 10:24:02 +0200 Subject: [PATCH 7/9] fix: client_key is a string --- src/redis_ctrl.rs | 8 ++++---- src/worldstate.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index 363fdc1..9c245f5 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -101,7 +101,7 @@ impl RedisCtrl { pub fn init_world_state( &mut self) -> LJResult{ Ok(WorldState { - client_key: self.connection.get("/clientkey")?, + client_key: self.get_client_key()?, edh: self.get_edh()?, kpps: self.get_int("kpps")?.try_into()?, intensity: self.get_int("intensity")?.try_into()?, @@ -118,9 +118,9 @@ impl RedisCtrl { Ok(edh) } - pub fn get_client_key( &mut self ) -> LJResult { - let key : u8 = self.connection.get("/clientkey")?; - Ok(key as u8) + pub fn get_client_key( &mut self ) -> LJResult { + let key : String = self.connection.get("/clientkey")?; + Ok(key) } pub fn get_int(&mut self, key: &str ) -> LJResult { diff --git a/src/worldstate.rs b/src/worldstate.rs index 1f6bea2..e03edb1 100644 --- a/src/worldstate.rs +++ b/src/worldstate.rs @@ -40,7 +40,7 @@ impl EDH { pub struct WorldState { pub edh: EDH, pub resampler: Vec, - pub client_key: u8, + pub client_key: String, pub intensity: u8, pub kpps: u32, pub color: Color, From fd9ad6227899f91a39d162d891c5ea92dc38800f Mon Sep 17 00:00:00 2001 From: alban Date: Mon, 17 Jul 2023 22:44:06 +0200 Subject: [PATCH 8/9] feat: add redis populate --- README.md | 0 examples/populate_redis.rs | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 README.md create mode 100644 examples/populate_redis.rs diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/examples/populate_redis.rs b/examples/populate_redis.rs new file mode 100644 index 0000000..cd95e77 --- /dev/null +++ b/examples/populate_redis.rs @@ -0,0 +1,24 @@ +/// +/// $ cargo run --example populate_redis +/// + +use redis::{ + //RedisResult, + Client, + Commands, + Connection, +}; + +fn do_something() -> redis::RedisResult<()> { + let client = Client::open("redis://127.0.0.1/")?; + let mut con: Connection = client.get_connection()?; + + let _ = con.set("/clientkey", "/pl/0/")?; + let _ = con.set("/EDH/0", "[[1.0, 0.0, 0.0],\n [ 0.0, 1.0, 0.0],\n [ 0.0, 0.0, 1.0]]")?; + let _ = con.set("/kpps/0", "5000")?; + let _ = con.set("/intensity/0", "255")?; + Ok(()) +} +fn main() { + _ = do_something(); +} From 4a87821c22264078c892ec12dd4999d15db867a3 Mon Sep 17 00:00:00 2001 From: alban Date: Mon, 17 Jul 2023 22:44:27 +0200 Subject: [PATCH 9/9] fix: various fixes for etherdream and debug --- README.md | 16 ++++++++++++++++ copyme.settings.toml | 9 +++++---- src/device/etherdream.rs | 28 +++++++++++++++++----------- src/errors.rs | 4 ---- src/main.rs | 2 +- src/redis_ctrl.rs | 8 ++++---- 6 files changed, 43 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index e69de29..f9ebc29 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,16 @@ +# LJ rust + +## Crashcourse + +```shell + +# Copy and edit the settings file +$ cp copyme.settings.toml settings.toml + +# Populate the redis database +$ cargo run --example populate_redis + +# Run +$ cargo run --release + +``` \ No newline at end of file diff --git a/copyme.settings.toml b/copyme.settings.toml index fa9d255..ea131ff 100644 --- a/copyme.settings.toml +++ b/copyme.settings.toml @@ -1,4 +1,4 @@ -# file: Settings.toml +# file: settings.toml # Rename me ! # The main key of your laser in LJ @@ -12,11 +12,11 @@ redis_url = "redis://127.0.0.1:6379/" # Either Helios or Etherdream # For Helios. USB Device Id of the DAC -[dac.helios] -id = 0 +#[dac.helios] +#id = 0 # For dummy dac: -# [dac.dummy] + [dac.dummy] # For Etherdream. IP of the DAC # [dac.etherdream] @@ -26,6 +26,7 @@ id = 0 [transformers.translate] x = 2000 y = 2000 + [[transformers]] [transformers.replicate] Until = 48 diff --git a/src/device/etherdream.rs b/src/device/etherdream.rs index e620f61..d1aaac6 100644 --- a/src/device/etherdream.rs +++ b/src/device/etherdream.rs @@ -8,7 +8,7 @@ use crate::device::{Device, Status, PlaybackState}; use crate::errors::{LJError, LJResult}; use crate::point::{Color, Point}; use ether_dream::protocol::{DacBroadcast, DacStatus}; -use log::info; +use log::{info, warn}; #[warn(dead_code)] pub struct EtherdreamDevice { @@ -38,20 +38,26 @@ impl EtherdreamDevice { pub fn get_dac(conf: &EtherDreamConf) -> LJResult<(DacBroadcast, SocketAddr, Stream)> { let ip = &conf.ip; let dac_broadcast = ether_dream::recv_dac_broadcasts()?; - dac_broadcast.set_nonblocking(true)?; - dac_broadcast.set_timeout(Some(time::Duration::new(60, 30)))?; + dac_broadcast.set_timeout(Some(time::Duration::new(10, 0)))?; + info!("Attempting to get DAC broadcast..."); let broadcast = dac_broadcast .filter_map(|result| { - info!("Received new broadcast {:?}", result); - if result.is_err() { return None; } - let (dac, source_addr) = result.unwrap(); - if source_addr.is_ipv6() { return None; } - if source_addr.ip().to_string() != ip.clone() { return None; } - info!("Valid broadcast"); - Some(Ok((dac, source_addr))) + match result { + Err(err) => { + warn!( "Failed to find a valid DAC via broadcast. Error: {:?}", err); + info!( "Retrying..."); + None + }, + Ok((dac, source_addr)) => { + if source_addr.is_ipv6() { return None; } + if &source_addr.ip().to_string() != ip { return None; } + info!("Valid broadcast"); + Some(Ok((dac, source_addr))) + } + } }) .next() - .ok_or(LJError::EtherdreamError("Failed to receive broadcast".to_string()))?; + .expect("Failed to receive broadcast."); match broadcast { Err(err) => { Err(Box::new(LJError::EtherdreamConnectError(err))) diff --git a/src/errors.rs b/src/errors.rs index 16237d5..9640b11 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -11,7 +11,6 @@ pub enum LJError { RedisConnect(RedisError), HeliosDeviceMissing, BadEDH, - EtherdreamError(String), EtherdreamConnectError(io::Error), } @@ -32,9 +31,6 @@ impl fmt::Display for LJError { BadEDH => { write!(f, "EDH matrix is not a 3x3 matrix") } - EtherdreamError(msg) => { - write!(f, "Unexpected Etherdream device error: {msg}") - } EtherdreamConnectError(err) => { write!(f, "Failed to retrieve Etherdream device: {err}") } diff --git a/src/main.rs b/src/main.rs index 8e88018..501d8cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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().unwrap(); info!("WorldState: {:?}", world_state); // Setup handler for interrupt Signals diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index 9c245f5..74ac5a0 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -101,10 +101,10 @@ impl RedisCtrl { pub fn init_world_state( &mut self) -> LJResult{ Ok(WorldState { - client_key: self.get_client_key()?, - edh: self.get_edh()?, - kpps: self.get_int("kpps")?.try_into()?, - intensity: self.get_int("intensity")?.try_into()?, + client_key: self.get_client_key().unwrap(), + edh: self.get_edh().unwrap(), + kpps: self.get_int("kpps").unwrap().try_into().unwrap(), + intensity: self.get_int("intensity").unwrap().try_into().unwrap(), ..WorldState::default() }) }