wip: add worldstate
This commit is contained in:
parent
9b9e04ad63
commit
ce86a1cecb
55
src/main.rs
55
src/main.rs
@ -8,6 +8,7 @@ mod errors;
|
|||||||
mod point;
|
mod point;
|
||||||
mod transformer;
|
mod transformer;
|
||||||
mod device;
|
mod device;
|
||||||
|
mod worldstate;
|
||||||
|
|
||||||
use device::device_factory;
|
use device::device_factory;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
@ -15,10 +16,11 @@ use std::sync::Arc;
|
|||||||
use redis_ctrl::{RedisCtrl, Order};
|
use redis_ctrl::{RedisCtrl, Order};
|
||||||
use conf::Conf;
|
use conf::Conf;
|
||||||
use errors::LJResult;
|
use errors::LJResult;
|
||||||
use point::Point;
|
use point::{Point, Color};
|
||||||
use transformer::Transformers;
|
use transformer::Transformers;
|
||||||
use log::{LevelFilter, info, /* warn, */ error};
|
use log::{LevelFilter, info, /* warn, */ error};
|
||||||
use env_logger::Builder;
|
use env_logger::Builder;
|
||||||
|
use worldstate::WorldState;
|
||||||
|
|
||||||
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
const DEFAULT_CONF_FILE: &str = "settings.toml";
|
||||||
|
|
||||||
@ -31,6 +33,7 @@ pub fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn run_all() -> LJResult<()> {
|
fn run_all() -> LJResult<()> {
|
||||||
// Setup configuration file and set up logs
|
// Setup configuration file and set up logs
|
||||||
let filename = std::env::args().nth(1).unwrap_or_else(|| {
|
let filename = std::env::args().nth(1).unwrap_or_else(|| {
|
||||||
@ -47,6 +50,8 @@ fn run_all() -> LJResult<()> {
|
|||||||
// Setup Redis Service
|
// Setup Redis Service
|
||||||
let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?;
|
let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?;
|
||||||
|
|
||||||
|
let mut world_state = rs.init_world_state();
|
||||||
|
|
||||||
// Setup handler for interrupt Signals
|
// Setup handler for interrupt Signals
|
||||||
let running = Arc::new(AtomicBool::new(true));
|
let running = Arc::new(AtomicBool::new(true));
|
||||||
let r = running.clone();
|
let r = running.clone();
|
||||||
@ -65,17 +70,46 @@ fn run_all() -> LJResult<()> {
|
|||||||
|
|
||||||
// Dispatch based on redis requests
|
// Dispatch based on redis requests
|
||||||
while running.load(Ordering::SeqCst) {
|
while running.load(Ordering::SeqCst) {
|
||||||
rs.set_status( tracer.status())?;
|
rs.set_status(tracer.status())?;
|
||||||
let order = rs.get_order(config.laser_id)?;
|
|
||||||
if order != Order::Draw {
|
|
||||||
info!("Order: {:?}", order);
|
|
||||||
}
|
|
||||||
|
|
||||||
let frame = get_next_frame(&config, &transformers,
|
let order = rs.get_order(config.laser_id)?;
|
||||||
&mut rs, order == Order::Black)?;
|
// 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
|
// For now, draw all the time
|
||||||
tracer.draw(frame, 2_000)?;
|
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.");
|
info!("Exiting, stoping device.");
|
||||||
tracer.stop()?;
|
tracer.stop()?;
|
||||||
@ -101,7 +135,7 @@ fn get_next_frame(
|
|||||||
config: &Conf,
|
config: &Conf,
|
||||||
transformers: &[Box<dyn Transformers>],
|
transformers: &[Box<dyn Transformers>],
|
||||||
rs: &mut RedisCtrl,
|
rs: &mut RedisCtrl,
|
||||||
_black: bool,
|
world_state : &WorldState
|
||||||
) -> LJResult<Vec<Point>> {
|
) -> LJResult<Vec<Point>> {
|
||||||
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
||||||
let mut line: Vec<Point> = line.into_iter()
|
let mut line: Vec<Point> = line.into_iter()
|
||||||
@ -109,9 +143,10 @@ fn get_next_frame(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for transformer in transformers {
|
for transformer in transformers {
|
||||||
line = transformer.apply(&line);
|
line = transformer.apply(&line, world_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
//info!("Line: {:?}", line);
|
//info!("Line: {:?}", line);
|
||||||
Ok(line)
|
Ok(line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ use redis::{Client, Commands, Connection};
|
|||||||
use ron::de::from_str;
|
use ron::de::from_str;
|
||||||
use crate::device::Status;
|
use crate::device::Status;
|
||||||
use crate::errors::{LJError, LJResult};
|
use crate::errors::{LJError, LJResult};
|
||||||
|
use crate::worldstate::{WorldState};
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -96,4 +97,16 @@ impl RedisCtrl {
|
|||||||
self.set(lack_key, status.lack.to_string())?;
|
self.set(lack_key, status.lack.to_string())?;
|
||||||
Ok(())
|
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
23
src/worldstate.rs
Normal 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{
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user