From ce86a1cecb0b21f4e934dfb66a979c6cd0c10d91 Mon Sep 17 00:00:00 2001 From: alban Date: Thu, 29 Jun 2023 22:36:00 +0200 Subject: [PATCH] wip: add worldstate --- src/main.rs | 65 ++++++++++++++++++++++++++++++++++++----------- src/redis_ctrl.rs | 13 ++++++++++ src/worldstate.rs | 23 +++++++++++++++++ 3 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 src/worldstate.rs diff --git a/src/main.rs b/src/main.rs index 2cf7953..874ae54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ mod errors; mod point; mod transformer; mod device; +mod worldstate; use device::device_factory; use std::sync::atomic::{AtomicBool, Ordering}; @@ -15,10 +16,11 @@ use std::sync::Arc; use redis_ctrl::{RedisCtrl, Order}; use conf::Conf; use errors::LJResult; -use point::Point; +use point::{Point, Color}; use transformer::Transformers; use log::{LevelFilter, info, /* warn, */ error}; use env_logger::Builder; +use worldstate::WorldState; const DEFAULT_CONF_FILE: &str = "settings.toml"; @@ -31,6 +33,7 @@ pub fn main() { } } + fn run_all() -> LJResult<()> { // Setup configuration file and set up logs let filename = std::env::args().nth(1).unwrap_or_else(|| { @@ -47,6 +50,8 @@ 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(); + // Setup handler for interrupt Signals let running = Arc::new(AtomicBool::new(true)); let r = running.clone(); @@ -61,20 +66,49 @@ fn run_all() -> LJResult<()> { //dbg!(tracer); // Setup geometry transformers on points lists - let transformers = config.get_transformers(); + let transformers = config.get_transformers(); // Dispatch based on redis requests while running.load(Ordering::SeqCst) { - rs.set_status( tracer.status())?; - let order = rs.get_order(config.laser_id)?; - if order != Order::Draw { - info!("Order: {:?}", order); - } + rs.set_status(tracer.status())?; - let frame = get_next_frame(&config, &transformers, - &mut rs, order == Order::Black)?; - // For now, draw all the time - tracer.draw(frame, 2_000)?; + let order = rs.get_order(config.laser_id)?; + // 0 : Draw Normal point list + // 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) + // 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 => { + let frame = get_next_frame( + &config, + &transformers, + &mut rs, + // order == Order::Black, + &world_state + )?; + // For now, draw all the time + tracer.draw(frame, 2_000)?; + } + Order::Edh => { + let world_state.edh = rs.get_edh(), + } + + // Order::ClientKey => rs.client_key(), + // Order::ColorBalance => {}, + _ => { + info!("Order: {:?}", order); + } + } } info!("Exiting, stoping device."); @@ -101,17 +135,18 @@ fn get_next_frame( config: &Conf, transformers: &[Box], rs: &mut RedisCtrl, - _black: bool, + 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(); + .map(|tpl| tpl.into()) + .collect(); for transformer in transformers { - line = transformer.apply(&line); + line = transformer.apply(&line, world_state); } //info!("Line: {:?}", line); Ok(line) } + diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index 448ed43..cbffc7c 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -2,6 +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}; #[repr(u8)] #[derive(Debug, PartialEq)] @@ -96,4 +97,16 @@ impl RedisCtrl { self.set(lack_key, status.lack.to_string())?; Ok(()) } + + pub fn init_world_state( &mut self) -> LJResult{ + WorldState + } + + pub fn get_edh( &mut self ) -> LJResult<()> { + + // Get new EDH + let edh = self.get("/EDH/1"); + EDH( edh ) + + } } diff --git a/src/worldstate.rs b/src/worldstate.rs new file mode 100644 index 0000000..097b19b --- /dev/null +++ b/src/worldstate.rs @@ -0,0 +1,23 @@ + + +pub struct EDH { + pub matrix: Matrix3 +} + +#[derive(Debug, Default )] +impl EDH { + +} + +pub struct WorldState { + pub edh: EDH, + pub resampler: Vec, + pub client_key: u8, + pub intensity: u8, + pub kpps: u32, + pub color: Color +} + +impl WorldState{ + +}