wip: add worldstate

This commit is contained in:
alban 2023-06-29 22:36:00 +02:00
parent 9b9e04ad63
commit ce86a1cecb
3 changed files with 86 additions and 15 deletions

View File

@ -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<dyn Transformers>],
rs: &mut RedisCtrl,
_black: bool,
world_state : &WorldState
) -> LJResult<Vec<Point>> {
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
let mut line: Vec<Point> = 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)
}

View File

@ -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>{
WorldState
}
pub fn get_edh( &mut self ) -> LJResult<()> {
// Get new EDH
let edh = self.get("/EDH/1");
EDH( edh )
}
}

23
src/worldstate.rs Normal file
View File

@ -0,0 +1,23 @@
pub struct EDH {
pub matrix: Matrix3
}
#[derive(Debug, Default )]
impl EDH {
}
pub struct WorldState {
pub edh: EDH,
pub resampler: Vec<f32>,
pub client_key: u8,
pub intensity: u8,
pub kpps: u32,
pub color: Color
}
impl WorldState{
}