From 3588e3f4a2ae3ad0cc366b974bb1c9d8b0da4b83 Mon Sep 17 00:00:00 2001 From: alban Date: Mon, 5 Jun 2023 21:03:55 +0200 Subject: [PATCH 01/13] wip --- src/device.rs | 15 ++++ src/device/common.rs | 31 ++++++++ src/device/helios.rs | 36 +++++++++ src/lib.rs | 1 + src/main.rs | 175 ++++++++++++++++++++++--------------------- 5 files changed, 171 insertions(+), 87 deletions(-) create mode 100644 src/device.rs create mode 100644 src/device/common.rs create mode 100644 src/device/helios.rs diff --git a/src/device.rs b/src/device.rs new file mode 100644 index 0000000..88d7759 --- /dev/null +++ b/src/device.rs @@ -0,0 +1,15 @@ +mod common; +mod helios; + +use crate::conf::{Conf, DacFamily, EtherDreamConf, HeliosConf}; +use crate::device::common::Device; +use crate::device::helios::HeliosDevice; + +pub fn device_factory(config: Conf) -> Box { + let device = match config.dac { + DacFamily::Helios(conf) => Box::new(HeliosDevice { conf }), + DacFamily::Etherdream( conf) => todo!(), + }; + + device +} \ No newline at end of file diff --git a/src/device/common.rs b/src/device/common.rs new file mode 100644 index 0000000..020ad4d --- /dev/null +++ b/src/device/common.rs @@ -0,0 +1,31 @@ + +/* +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/helios.rs b/src/device/helios.rs new file mode 100644 index 0000000..e5ff34d --- /dev/null +++ b/src/device/helios.rs @@ -0,0 +1,36 @@ +/// +/// Configure udev: +/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md +/// +use helios_dac::NativeHeliosDacController; +use helios_dac::{ + // Coordinate, + Color, + DeviceStatus, + Frame, + Point, +}; +use crate::conf::HeliosConf; +use crate::device::common::{Device, Status}; + +pub struct HeliosDevice { + pub conf: HeliosConf, +} + +impl HeliosDevice { + + pub fn new ( conf: HeliosConf) -> Self{ + Self{ conf } + } + +} + +impl Device for HeliosDevice { + fn status(&self) -> Status { + return Status { + active: true, + last_traced_at: "now".to_string(), + properties: vec!["foo".to_string()], + }; + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index f3347b9..41e05b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ pub mod conf; pub mod redis_ctrl; pub mod errors; +pub mod device; diff --git a/src/main.rs b/src/main.rs index bba4514..dc1884a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,122 +7,123 @@ mod conf; mod errors; mod point; mod transformer; +mod device; + +use device::device_factory; use helios_dac::{ - self, - NativeHeliosDacController, - NativeHeliosDac, - DeviceStatus, - Frame, + self, + NativeHeliosDacController, + NativeHeliosDac, + DeviceStatus, + Frame, }; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use redis_ctrl::{RedisCtrl,Order}; +use redis_ctrl::{RedisCtrl, Order}; use conf::Conf; -use errors::{LJError,LJResult}; +use errors::{LJError, LJResult}; use point::Point; -use transformer::{Transformers,Translate,Replicate}; -use log::{LevelFilter,info,/* warn, */ error}; +use transformer::{Transformers, Translate, Replicate}; +use log::{LevelFilter, info, /* warn, */ error}; use env_logger::Builder; -const DEFAULT_CONF_FILE : &str = "settings.toml"; -const CENTER : (f32,f32) = (2000.0, 2000.0); +const DEFAULT_CONF_FILE: &str = "settings.toml"; +const CENTER: (f32, f32) = (2000.0, 2000.0); -pub fn main() { - match run_all() { - Ok(()) => {}, - Err(err) => { - error!("Error: {}", err); +pub fn main() { + match run_all() { + Ok(()) => {} + Err(err) => { + error!("Error: {}", err); + } } - } } fn run_all() -> LJResult<()> { - let filename = std::env::args().nth(1).unwrap_or_else(|| { - DEFAULT_CONF_FILE.to_string() - }); - - let config = Conf::new(&filename); - init_logging(&config); - let config = config?; - info!("*** Starting up ***"); - - let mut rs = RedisCtrl::new(&config.redis_url)?; - - let running = Arc::new(AtomicBool::new(true)); - let r = running.clone(); - ctrlc::set_handler(move || { - r.store(false, Ordering::SeqCst); - })?; + let filename = std::env::args().nth(1).unwrap_or_else(|| { + DEFAULT_CONF_FILE.to_string() + }); - let mut device = get_helios_device()?; + let config = Conf::new(&filename); + init_logging(&config); + let config = config?; + info!("*** Starting up ***"); - let transformers : Vec> = vec![ - Box::new(Translate::new(CENTER.0, CENTER.1)), - Box::new(Replicate::Until(48)) - ]; - - while running.load(Ordering::SeqCst) { - let order = rs.get_order(config.laser_id)?; - if order != Order::Draw { - info!("Order: {:?}", order); + let mut rs = RedisCtrl::new(&config.redis_url)?; + + let running = Arc::new(AtomicBool::new(true)); + let r = running.clone(); + ctrlc::set_handler(move || { + r.store(false, Ordering::SeqCst); + })?; + + let mut device = get_helios_device()?; + + let transformers: Vec> = vec![ + Box::new(Translate::new(CENTER.0, CENTER.1)), + Box::new(Replicate::Until(48)), + ]; + + while running.load(Ordering::SeqCst) { + + let order = rs.get_order(config.laser_id)?; + if order != Order::Draw { + info!("Order: {:?}", order); + } + + let frame = get_next_frame(&config, 1000, &transformers, + &mut rs, order == Order::Black)?; + + while let Ok(DeviceStatus::NotReady) = device.status() {} + device.write_frame(frame)?; } - let frame = get_next_frame(&config, 1000, &transformers, - &mut rs, order == Order::Black)?; - - while let Ok(DeviceStatus::NotReady) = device.status() { - } - device.write_frame(frame)?; - } - - info!("Exiting, stoping device."); - device.stop()?; - Ok(()) + info!("Exiting, stoping device."); + device.stop()?; + Ok(()) } fn init_logging(config: &LJResult) { - if let Ok(ref config) = config { - if config.debug { - let mut builder = Builder::from_default_env(); - builder - .filter(None, LevelFilter::Info) - .init(); - info!("Debug mode enabled from configuration file"); - return; + if let Ok(ref config) = config { + if config.debug { + let mut builder = Builder::from_default_env(); + builder + .filter(None, LevelFilter::Info) + .init(); + info!("Debug mode enabled from configuration file"); + return; + } } - } - info!("Logging level inherited from env"); - env_logger::init(); + info!("Logging level inherited from env"); + env_logger::init(); } fn get_helios_device() -> LJResult { - let controller = NativeHeliosDacController::new()?; - let devices = controller.list_devices()?; - let Some(device) = devices.into_iter().next() else { - return Err(Box::new(LJError::HeliosDeviceMissing)); - }; - let device = device.open()?; - Ok(device) + let controller = NativeHeliosDacController::new()?; + let devices = controller.list_devices()?; + let Some(device) = devices.into_iter().next() else { + return Err(Box::new(LJError::HeliosDeviceMissing)); + }; + let device = device.open()?; + Ok(device) } fn get_next_frame( - config: &Conf, - speed: u32, - transformers: &[Box], - rs: &mut RedisCtrl, - _black: bool + config: &Conf, + speed: u32, + transformers: &[Box], + rs: &mut RedisCtrl, + _black: bool, ) -> LJResult { + let line = rs.get(&format!("/pl/{}/0", config.laser_id))?; + let mut line: Vec = line.into_iter().map(|tpl| tpl.into()).collect(); + for transformer in transformers { + line = transformer.apply(&line); + } - - let line = rs.get(&format!("/pl/{}/0", config.laser_id))?; - let mut line: Vec = line.into_iter().map(| tpl | tpl.into()).collect(); - for transformer in transformers { - line = transformer.apply(&line); - } + info!("Line: {:?}", line); - info!("Line: {:?}", line); - - let line2 : Vec = line.into_iter().map(| p | p.into()).collect(); - Ok(Frame::new(speed, line2)) + let line2: Vec = line.into_iter().map(|p| p.into()).collect(); + Ok(Frame::new(speed, line2)) } From 7d7eec66958d386c1c9036820fb9055af3d2f7e1 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Tue, 6 Jun 2023 11:30:46 +0200 Subject: [PATCH 02/13] refacto transformer with module hierarchy --- src/device.rs | 8 +++--- src/device/helios.rs | 4 ++- src/main.rs | 16 ++++++------ src/transformer.rs | 60 -------------------------------------------- 4 files changed, 16 insertions(+), 72 deletions(-) delete mode 100644 src/transformer.rs diff --git a/src/device.rs b/src/device.rs index 88d7759..e245e5e 100644 --- a/src/device.rs +++ b/src/device.rs @@ -1,15 +1,15 @@ mod common; mod helios; -use crate::conf::{Conf, DacFamily, EtherDreamConf, HeliosConf}; +use crate::conf::{Conf, DacFamily}; //, EtherDreamConf, HeliosConf}; use crate::device::common::Device; use crate::device::helios::HeliosDevice; pub fn device_factory(config: Conf) -> Box { let device = match config.dac { - DacFamily::Helios(conf) => Box::new(HeliosDevice { conf }), - DacFamily::Etherdream( conf) => todo!(), + DacFamily::Helios(conf) => Box::new(HeliosDevice::new(conf)), + DacFamily::Etherdream(_conf) => todo!(), }; device -} \ No newline at end of file +} diff --git a/src/device/helios.rs b/src/device/helios.rs index e5ff34d..b87a8f8 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -2,6 +2,7 @@ /// Configure udev: /// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md /// +/* use helios_dac::NativeHeliosDacController; use helios_dac::{ // Coordinate, @@ -10,6 +11,7 @@ use helios_dac::{ Frame, Point, }; +*/ use crate::conf::HeliosConf; use crate::device::common::{Device, Status}; @@ -33,4 +35,4 @@ impl Device for HeliosDevice { properties: vec!["foo".to_string()], }; } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index dc1884a..c9c77b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,8 +9,6 @@ mod point; mod transformer; mod device; -use device::device_factory; - use helios_dac::{ self, NativeHeliosDacController, @@ -18,15 +16,19 @@ use helios_dac::{ DeviceStatus, Frame, }; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc +}; use redis_ctrl::{RedisCtrl, Order}; +use log::{LevelFilter, info, /* warn, */ error}; +use env_logger::Builder; + use conf::Conf; use errors::{LJError, LJResult}; use point::Point; -use transformer::{Transformers, Translate, Replicate}; -use log::{LevelFilter, info, /* warn, */ error}; -use env_logger::Builder; +use device::device_factory; +use transformer::{Transformers,Translate,Replicate}; const DEFAULT_CONF_FILE: &str = "settings.toml"; const CENTER: (f32, f32) = (2000.0, 2000.0); diff --git a/src/transformer.rs b/src/transformer.rs deleted file mode 100644 index 3728f94..0000000 --- a/src/transformer.rs +++ /dev/null @@ -1,60 +0,0 @@ -use crate::point::Point; - -pub trait Transformers { - fn apply(&self, point_list: &[Point]) -> Vec; -} - -/// Translate - -#[derive(Debug,Clone,Copy)] -pub struct Translate { - x: f32, - y: f32 -} - -impl Translate { - pub fn new(x: f32, y: f32) -> Self { - Self { x, y } - } -} - -impl Transformers for Translate { - fn apply(&self, point_list: &[Point]) -> Vec { - point_list.iter() - .map(| pt | { - Point { x: pt.x + self.x, - y: pt.y + self.y, - ..*pt - } - }).collect() - } -} - -/// Replicate - -#[allow(dead_code)] -#[derive(Debug,Clone,Copy)] -pub enum Replicate { - Until(usize), - Times(usize) -} - -impl Transformers for Replicate { - fn apply(&self, point_list: &[Point]) -> Vec { - let mut point_list2 = vec![]; - match self { - Replicate::Until(n) => { - while point_list2.len() < *n { - point_list2.append(&mut point_list.to_vec()); - } - }, - Replicate::Times(n) => { - for _ in 0..*n { - point_list2.append(&mut point_list.to_vec()); - } - } - } - point_list2 - } -} - From e899d8061c837064a50abceb9fe28a73e326de09 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Tue, 6 Jun 2023 11:31:45 +0200 Subject: [PATCH 03/13] refacto transformer with module hierarchy --- src/transformer/replicate.rs | 31 +++++++++++++++++++++++++++++++ src/transformer/translate.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 src/transformer/replicate.rs create mode 100644 src/transformer/translate.rs diff --git a/src/transformer/replicate.rs b/src/transformer/replicate.rs new file mode 100644 index 0000000..bb56fec --- /dev/null +++ b/src/transformer/replicate.rs @@ -0,0 +1,31 @@ +use crate::Transformers; +use crate::point::Point; + +/// Replicate + +#[allow(dead_code)] +#[derive(Debug,Clone,Copy)] +pub enum Replicate { + Until(usize), + Times(usize) +} + +impl Transformers for Replicate { + fn apply(&self, point_list: &[Point]) -> Vec { + let mut point_list2 = vec![]; + match self { + Replicate::Until(n) => { + while point_list2.len() < *n { + point_list2.append(&mut point_list.to_vec()); + } + }, + Replicate::Times(n) => { + for _ in 0..*n { + point_list2.append(&mut point_list.to_vec()); + } + } + } + point_list2 + } +} + diff --git a/src/transformer/translate.rs b/src/transformer/translate.rs new file mode 100644 index 0000000..6b0c029 --- /dev/null +++ b/src/transformer/translate.rs @@ -0,0 +1,27 @@ +use crate::Transformers; +use crate::point::Point; +/// Translate + +#[derive(Debug,Clone,Copy)] +pub struct Translate { + x: f32, + y: f32 +} + +impl Translate { + pub fn new(x: f32, y: f32) -> Self { + Self { x, y } + } +} + +impl Transformers for Translate { + fn apply(&self, point_list: &[Point]) -> Vec { + point_list.iter() + .map(| pt | { + Point { x: pt.x + self.x, + y: pt.y + self.y, + ..*pt + } + }).collect() + } +} From bc78b30b09d02cb081b31a7326777c5981aaa548 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Tue, 6 Jun 2023 11:32:05 +0200 Subject: [PATCH 04/13] refacto transformer with module hierarchy --- src/transformer.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/transformer.rs diff --git a/src/transformer.rs b/src/transformer.rs new file mode 100644 index 0000000..edfea5f --- /dev/null +++ b/src/transformer.rs @@ -0,0 +1,13 @@ +//pub mod common; +pub mod translate; +pub mod replicate; + +use crate::point::Point; + +// re-export transformers to be abe to use it directly from transformer:: +pub use translate::Translate; +pub use replicate::Replicate; + +pub trait Transformers { + fn apply(&self, point_list: &[Point]) -> Vec; +} From 40abb3ac57617775a70c51b0d2bd96f8a31f4ebd Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Tue, 6 Jun 2023 11:44:33 +0200 Subject: [PATCH 05/13] no need for these mod to be pub anymore --- src/transformer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transformer.rs b/src/transformer.rs index edfea5f..564b981 100644 --- a/src/transformer.rs +++ b/src/transformer.rs @@ -1,6 +1,6 @@ //pub mod common; -pub mod translate; -pub mod replicate; +mod translate; +mod replicate; use crate::point::Point; From ad3b3803cee3df42e531dfa56aa4cd589babac3f Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Wed, 7 Jun 2023 17:26:30 +0200 Subject: [PATCH 06/13] load transformers from config file --- Cargo.toml | 1 + copyme.Settings.toml | 8 ++++++++ src/conf.rs | 40 +++++++++++++++++++++++++++++++++++- src/lib.rs | 4 +++- src/main.rs | 11 ++++------ src/transformer/replicate.rs | 3 ++- src/transformer/translate.rs | 4 +++- 7 files changed, 60 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ccbd534..18f311d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,4 @@ log = "0.4.18" redis = "0.23.0" ron = "0.8.0" serde = { version = "1.0.163", features = ["derive"] } +toml = "0.7.4" diff --git a/copyme.Settings.toml b/copyme.Settings.toml index d0055a3..f440bc0 100644 --- a/copyme.Settings.toml +++ b/copyme.Settings.toml @@ -18,3 +18,11 @@ id = 0 # For Etherdream. IP of the DAC # [dac.etherdream] # url = "192.168.1.68" + +[[transformers]] +[transformers.translate] +x = 2000 +y = 2000 +[[transformers]] +[transformers.replicate] +Until = 48 diff --git a/src/conf.rs b/src/conf.rs index a92dcff..781bcaa 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1,13 +1,16 @@ use config::Config; use serde::{Serialize,Deserialize}; use crate::errors::LJResult; +use crate::transformer; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Conf { pub laser_id: u8, pub debug: bool, pub redis_url: String, - pub dac: DacFamily + pub dac: DacFamily, + #[serde(default)] + pub transformers: Vec } #[derive(Serialize, Deserialize, Debug, Clone)] @@ -28,6 +31,15 @@ pub struct EtherDreamConf { pub url: String } +#[derive(Serialize, Deserialize, Debug, Clone)] +pub enum TransformConf { + #[serde(rename = "translate")] + Translate(transformer::Translate), + #[serde(rename = "replicate")] + Replicate(transformer::Replicate) +} + + impl Conf { pub fn new(path: &str) -> LJResult { let settings = Config::builder() @@ -37,4 +49,30 @@ impl Conf { let conf : Conf = settings.try_deserialize()?; Ok(conf) } + + pub fn get_transformers(&self) -> Vec> { + let mut v = vec![]; + for t in &self.transformers { + let t : Box = match t { + TransformConf::Translate(t) => Box::new(t.clone()), + TransformConf::Replicate(r) => Box::new(r.clone()) + }; + v.push(t); + } + v + } + + pub fn dump() { + let conf = Conf { laser_id: 0, + debug: true, + redis_url: "redis://127.0.0.1:6379/".to_string(), + dac: DacFamily::Helios(HeliosConf { id: 0 }), + transformers: vec![ + TransformConf::Translate(transformer::Translate::new(2000.0,2000.0)), + TransformConf::Replicate(transformer::Replicate::Until(48)) + ] + }; + let s = toml::to_string(&conf).unwrap(); + println!("{}", s); + } } diff --git a/src/lib.rs b/src/lib.rs index 937f09a..ad51a61 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ -pub mod conf; +/* pub mod redis_ctrl; +pub mod conf; pub mod errors; pub mod device; pub mod point; +*/ diff --git a/src/main.rs b/src/main.rs index 4b8ba46..7debd47 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,14 +14,13 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use redis_ctrl::{RedisCtrl, Order}; use conf::Conf; -use errors::{LJError, LJResult}; +use errors::LJResult; use point::Point; use transformer::{Transformers, Translate, Replicate}; use log::{LevelFilter, info, /* warn, */ error}; use env_logger::Builder; const DEFAULT_CONF_FILE: &str = "settings.toml"; -const CENTER: (f32, f32) = (2000.0, 2000.0); pub fn main() { match run_all() { @@ -43,6 +42,8 @@ fn run_all() -> LJResult<()> { let config = config?; info!("*** Starting up ***"); + info!("{:?}", config); + // Setup Redis Service let mut rs = RedisCtrl::new(&config.redis_url)?; @@ -60,11 +61,7 @@ fn run_all() -> LJResult<()> { //dbg!(tracer); // Setup geometry transformers on points lists - // @todo use the config - let transformers: Vec> = vec![ - Box::new(Translate::new(CENTER.0, CENTER.1)), - Box::new(Replicate::Until(48)), - ]; + let transformers = config.get_transformers(); // Dispatch based on redis requests while running.load(Ordering::SeqCst) { diff --git a/src/transformer/replicate.rs b/src/transformer/replicate.rs index bb56fec..b8a1d71 100644 --- a/src/transformer/replicate.rs +++ b/src/transformer/replicate.rs @@ -1,10 +1,11 @@ use crate::Transformers; use crate::point::Point; +use serde::{Serialize,Deserialize}; /// Replicate #[allow(dead_code)] -#[derive(Debug,Clone,Copy)] +#[derive(Serialize,Deserialize,Debug,Clone,Copy)] pub enum Replicate { Until(usize), Times(usize) diff --git a/src/transformer/translate.rs b/src/transformer/translate.rs index 6b0c029..2e94e2e 100644 --- a/src/transformer/translate.rs +++ b/src/transformer/translate.rs @@ -1,8 +1,10 @@ use crate::Transformers; use crate::point::Point; +use serde::{Serialize,Deserialize}; + /// Translate -#[derive(Debug,Clone,Copy)] +#[derive(Serialize,Deserialize,Debug,Clone,Copy)] pub struct Translate { x: f32, y: f32 From 22d007d938df32d6da54f15f3bc8a34b2c245900 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Wed, 7 Jun 2023 18:25:33 +0200 Subject: [PATCH 07/13] fix warnings and make clippy happy --- src/conf.rs | 7 ++++--- src/device/helios.rs | 10 +++++----- src/device/mod.rs | 2 +- src/main.rs | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/conf.rs b/src/conf.rs index 781bcaa..02a4c15 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -54,14 +54,15 @@ impl Conf { let mut v = vec![]; for t in &self.transformers { let t : Box = match t { - TransformConf::Translate(t) => Box::new(t.clone()), - TransformConf::Replicate(r) => Box::new(r.clone()) + TransformConf::Translate(t) => Box::new(*t), + TransformConf::Replicate(r) => Box::new(*r) }; v.push(t); } v } - + + #[allow(dead_code)] pub fn dump() { let conf = Conf { laser_id: 0, debug: true, diff --git a/src/device/helios.rs b/src/device/helios.rs index e1b8efc..8b0fc88 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -5,10 +5,10 @@ use helios_dac::{NativeHeliosDac, NativeHeliosDacController}; use helios_dac::{ // Coordinate, - Color, + // Color, DeviceStatus, Frame, - Point as HeliosPoint, + // Point as HeliosPoint, }; use crate::conf::HeliosConf; use crate::device::{Device, Status}; @@ -35,11 +35,11 @@ impl HeliosDevice { impl Device for HeliosDevice { fn status(&self) -> Status { - return Status { + Status { active: true, last_traced_at: "now".to_string(), properties: vec!["foo".to_string()], - }; + } } fn draw(&self, @@ -49,7 +49,7 @@ impl Device for HeliosDevice { while let Ok(DeviceStatus::NotReady) = self.dac.status() {} let points: Vec = line.into_iter().map(|p| p.into()).collect(); - let frame = Frame::new(speed, points); + let _frame = Frame::new(speed, points); Ok(()) } diff --git a/src/device/mod.rs b/src/device/mod.rs index 70a3916..9f4455b 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -2,7 +2,7 @@ use crate::point::Point; mod helios; -use crate::conf::{Conf, DacFamily, EtherDreamConf, HeliosConf}; +use crate::conf::{Conf, DacFamily, /*EtherDreamConf, HeliosConf*/}; use crate::device::helios::HeliosDevice; use crate::errors::LJResult; diff --git a/src/main.rs b/src/main.rs index 7debd47..cb05855 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use redis_ctrl::{RedisCtrl, Order}; use conf::Conf; use errors::LJResult; use point::Point; -use transformer::{Transformers, Translate, Replicate}; +use transformer::Transformers; use log::{LevelFilter, info, /* warn, */ error}; use env_logger::Builder; From 9c996b102926fc1c138ddbc9dd94e037dd9567af Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Thu, 8 Jun 2023 15:49:29 +0200 Subject: [PATCH 08/13] fix tests --- src/lib.rs | 3 +-- src/transformer/replicate.rs | 2 +- src/transformer/translate.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ad51a61..b183c49 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ -/* pub mod redis_ctrl; pub mod conf; pub mod errors; pub mod device; pub mod point; -*/ +pub mod transformer; diff --git a/src/transformer/replicate.rs b/src/transformer/replicate.rs index b8a1d71..99258ae 100644 --- a/src/transformer/replicate.rs +++ b/src/transformer/replicate.rs @@ -1,4 +1,4 @@ -use crate::Transformers; +use crate::transformer::Transformers; use crate::point::Point; use serde::{Serialize,Deserialize}; diff --git a/src/transformer/translate.rs b/src/transformer/translate.rs index 2e94e2e..a36f272 100644 --- a/src/transformer/translate.rs +++ b/src/transformer/translate.rs @@ -1,4 +1,4 @@ -use crate::Transformers; +use crate::transformer::Transformers; use crate::point::Point; use serde::{Serialize,Deserialize}; From 4b135ce283e919febd28f3d9174f0d08d514cc72 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 8 Jun 2023 20:18:28 +0200 Subject: [PATCH 09/13] fix: rework device --- src/{device/mod.rs => device.rs} | 2 +- src/device/helios.rs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) rename src/{device/mod.rs => device.rs} (98%) diff --git a/src/device/mod.rs b/src/device.rs similarity index 98% rename from src/device/mod.rs rename to src/device.rs index 70a3916..e231299 100644 --- a/src/device/mod.rs +++ b/src/device.rs @@ -29,7 +29,7 @@ pub struct Status { pub trait Device { fn status( &self ) -> Status; fn draw( - &self, + &mut self, frame: Vec, speed: u32, ) -> LJResult<()> ; diff --git a/src/device/helios.rs b/src/device/helios.rs index a090209..518a45a 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -30,7 +30,8 @@ impl HeliosDevice { }; let dac = device.open()?; Ok(Self { - conf: (*conf).clone(), dac, + conf: (*conf).clone(), + dac, }) } } @@ -44,7 +45,7 @@ impl Device for HeliosDevice { }; } - fn draw(&self, + fn draw(&mut self, line: Vec, speed: u32, ) -> LJResult<()> { @@ -52,6 +53,11 @@ impl Device for HeliosDevice { let points: Vec = line.into_iter().map(|p| p.into()).collect(); let frame = Frame::new(speed, points); + + while let Ok(DeviceStatus::NotReady) = self.dac.status() { + self.dac.write_frame(frame.clone())?; + } + Ok(()) } From 6e97b1c4411ed9f56f5322aa7a3415d01aba0ce4 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 8 Jun 2023 20:21:51 +0200 Subject: [PATCH 10/13] fix: rename settings template --- copyme.Settings.toml => copyme.settings.toml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename copyme.Settings.toml => copyme.settings.toml (100%) diff --git a/copyme.Settings.toml b/copyme.settings.toml similarity index 100% rename from copyme.Settings.toml rename to copyme.settings.toml From 560b3be71b0647e7143112fe445ea2b5b5b041c9 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 8 Jun 2023 20:22:36 +0200 Subject: [PATCH 11/13] fix: rename settings.toml --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0e205d4..de3276d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Configuration file -Settings.* +settings.* # Generated by Cargo # will have compiled files and executables From a791514cbe2aacea80da1c305f7747edd5a713f3 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Thu, 8 Jun 2023 20:34:09 +0200 Subject: [PATCH 12/13] better error message for config issues --- src/conf.rs | 4 ++-- src/errors.rs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/conf.rs b/src/conf.rs index 02a4c15..fe5e762 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -1,6 +1,6 @@ use config::Config; use serde::{Serialize,Deserialize}; -use crate::errors::LJResult; +use crate::errors::{LJError,LJResult}; use crate::transformer; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -46,7 +46,7 @@ impl Conf { .add_source(config::File::with_name(path)) .build()?; - let conf : Conf = settings.try_deserialize()?; + let conf : Conf = settings.try_deserialize().map_err(LJError::Config)?; Ok(conf) } diff --git a/src/errors.rs b/src/errors.rs index 45363e5..ff40f33 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,11 +1,13 @@ use std::error::Error; use std::fmt; use redis::RedisError; +use config::ConfigError; pub type LJResult = Result>; #[derive(Debug)] pub enum LJError { + Config(ConfigError), RedisConnect(RedisError), HeliosDeviceMissing } @@ -15,6 +17,10 @@ impl fmt::Display for LJError { use LJError::*; match self { + Config(err) => { + write!(f, "unable to load config file: {err}") + }, + RedisConnect(err) => { write!(f, "unable to connect to redis server: {err}") }, From d9b96f609080b964d361a3b7007f7ab7cb705827 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Thu, 8 Jun 2023 21:06:33 +0200 Subject: [PATCH 13/13] fix draw loop --- src/device/helios.rs | 9 +++------ src/main.rs | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/device/helios.rs b/src/device/helios.rs index 9e0cd81..f607bb8 100644 --- a/src/device/helios.rs +++ b/src/device/helios.rs @@ -46,15 +46,12 @@ impl Device for HeliosDevice { line: Vec, speed: u32, ) -> LJResult<()> { - while let Ok(DeviceStatus::NotReady) = self.dac.status() {} + while let Ok(DeviceStatus::NotReady) = self.dac.status() { + } let points: Vec = line.into_iter().map(|p| p.into()).collect(); let frame = Frame::new(speed, points); - - while let Ok(DeviceStatus::NotReady) = self.dac.status() { - self.dac.write_frame(frame.clone())?; - } - + self.dac.write_frame(frame.clone())?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index cb05855..e52ef28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -109,6 +109,6 @@ fn get_next_frame( line = transformer.apply(&line); } - info!("Line: {:?}", line); + //info!("Line: {:?}", line); Ok(line) }