diff --git a/src/conf.rs b/src/conf.rs index 815211c..7d91cad 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -81,14 +81,16 @@ impl Conf { #[allow(dead_code)] 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 { x: 2000.0, y: 2000.0 } ), - TransformConf::Replicate(transformer::Replicate::Until(48)) - ] + 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 { x: 2000.0, + y: 2000.0 } ), + TransformConf::Replicate(transformer::Replicate::Until(48)) + ] }; let s = toml::to_string(&conf).unwrap(); println!("{}", s); diff --git a/src/main.rs b/src/main.rs index 6a1103b..344a71d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,7 +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); + // Setup handler for interrupt Signals let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); @@ -93,15 +94,18 @@ fn run_all() -> LJResult<()> { &config, &transformers, &mut rs, - // order == Order::Black, &world_state )?; // For now, draw all the time tracer.draw(frame, 2_000)?; - } + }, + Order::Intensity => { + world_state.intensity = rs.get_int("intensity")? + .try_into()?; + }, Order::Edh => { world_state.edh = rs.get_edh()?; - } + }, // Order::ClientKey => rs.client_key(), // Order::ColorBalance => {}, @@ -137,16 +141,19 @@ fn get_next_frame( rs: &mut RedisCtrl, world_state : &WorldState ) -> 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, world_state); - } - - //info!("Line: {:?}", line); - Ok(line) + 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); + } + + //info!("Line: {:?}", line); + Ok(line) } diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index 5f6eea0..4b13d8a 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -3,7 +3,7 @@ use ron::de::from_str; use crate::device::Status; use crate::errors::{LJError, LJResult}; use crate::worldstate::{WorldState,EDH}; -use log::info; +// use log::info; #[repr(u8)] #[derive(Debug, PartialEq)] @@ -62,7 +62,7 @@ impl RedisCtrl { Ok(RedisCtrl { client, connection, laser_id: *laser_id }) } - pub fn get(&mut self, key: &str) -> LJResult { + pub fn get_line(&mut self, key: &str) -> LJResult { let val: String = self.connection.get(key)?; let line: Line = from_str(&val)?; Ok(line) @@ -100,11 +100,11 @@ impl RedisCtrl { } pub fn init_world_state( &mut self) -> LJResult{ - let edh = self.get_edh()?; - info!("EDH: {:?}", edh); - Ok(WorldState { - edh, + client_key: self.connection.get("/clientkey")?, + edh: self.get_edh()?, + kpps: self.get_int("kpps")?.try_into()?, + intensity: self.get_int("intensity")?.try_into()?, ..WorldState::default() }) } @@ -117,4 +117,11 @@ impl RedisCtrl { let edh = EDH::new(edh)?; Ok(edh) } + + pub fn get_int(&mut self, key: &str ) -> LJResult { + // Get new Int + let fmt = format!("/{key}/{}", self.laser_id); + let val : u32 = self.connection.get(fmt)?; + Ok(val) + } } diff --git a/src/worldstate.rs b/src/worldstate.rs index bf5ecc9..c097247 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, //u8, pub intensity: u8, pub kpps: u32, pub color: Color