feat: more dispatch actions and cosmetic
This commit is contained in:
parent
8e10e0d82e
commit
4719dcc430
18
src/main.rs
18
src/main.rs
@ -65,19 +65,13 @@ fn run_all() -> LJResult<()> {
|
||||
let mut tracer = device_factory(&config)?;
|
||||
world_state.grid = tracer.grid();
|
||||
|
||||
// can't work, but we can add + Debug to Device to make it work...
|
||||
//dbg!(tracer);
|
||||
|
||||
// Setup geometry transformers on points lists
|
||||
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)?;
|
||||
|
||||
|
||||
match order {
|
||||
Order::Draw | Order::Black | Order::Grid => {
|
||||
// 0 : Draw Normal point list
|
||||
@ -110,11 +104,14 @@ fn run_all() -> LJResult<()> {
|
||||
Order::ClientKey => {
|
||||
world_state.client_key = rs.get_client_key()?;
|
||||
}
|
||||
// Order::ColorBalance => {},
|
||||
Order::ColorBalance => {
|
||||
let (r, g, b) = rs.get_color_balance()?;
|
||||
world_state.color_balance = Color { r, g, b };
|
||||
}
|
||||
Order::Resampler => {
|
||||
world_state.resampler = rs.get_resampler()?;
|
||||
}
|
||||
_ => {
|
||||
// 4 : Resampler Change (longs and shorts lsteps)
|
||||
// 5 : Client Key Change = reread redis key /clientkey
|
||||
// 8 : color balance change = reread redis keys /red /green /blue
|
||||
// 9 : poweroff LJ
|
||||
info!("Order: {:?}", order);
|
||||
}
|
||||
@ -128,7 +125,6 @@ fn run_all() -> LJResult<()> {
|
||||
|
||||
fn init_logging(config: &LJResult<Conf>) {
|
||||
if let Ok(ref config) = config {
|
||||
|
||||
let level = if config.debug {
|
||||
LevelFilter::Debug
|
||||
} else {
|
||||
|
@ -2,7 +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,EDH};
|
||||
use crate::worldstate::{WorldState, EDH};
|
||||
// use log::info;
|
||||
|
||||
#[repr(u8)]
|
||||
@ -10,7 +10,6 @@ use crate::worldstate::{WorldState,EDH};
|
||||
pub enum Order {
|
||||
Draw = 0,
|
||||
Edh,
|
||||
//homography
|
||||
Black,
|
||||
Grid,
|
||||
Resampler,
|
||||
@ -46,6 +45,7 @@ impl TryFrom<u8> for Order {
|
||||
}
|
||||
|
||||
pub type Line = Vec<(f32, f32, u32)>;
|
||||
pub type Resampler = Vec<(f32,f32)>;
|
||||
|
||||
pub struct RedisCtrl {
|
||||
pub client: Client,
|
||||
@ -84,11 +84,6 @@ impl RedisCtrl {
|
||||
Ok(val.try_into()?)
|
||||
}
|
||||
|
||||
/**
|
||||
/lstt/lasernumber etherdream last_status.playback_state (0: idle 1: prepare 2: playing)
|
||||
/cap/lasernumber number of empty points sent to fill etherdream buffer (up to 1799)
|
||||
/lack/lasernumber "a": ACK "F": Full "I": invalid. 64 or 35 for no connection.
|
||||
**/
|
||||
pub fn set_status(&mut self, status: Status) -> LJResult<()> {
|
||||
let lstt_key = format!("/lstt/{}", self.laser_id);
|
||||
let cap_key = format!("/cap/{}", self.laser_id);
|
||||
@ -99,34 +94,48 @@ impl RedisCtrl {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn init_world_state( &mut self) -> LJResult<WorldState>{
|
||||
Ok(WorldState {
|
||||
client_key: self.get_client_key().unwrap(),
|
||||
edh: self.get_edh().unwrap(),
|
||||
kpps: self.get_int("kpps").unwrap().try_into().unwrap(),
|
||||
intensity: self.get_int("intensity").unwrap().try_into().unwrap(),
|
||||
..WorldState::default()
|
||||
})
|
||||
pub fn init_world_state(&mut self) -> LJResult<WorldState> {
|
||||
Ok(WorldState {
|
||||
client_key: self.get_client_key().unwrap(),
|
||||
edh: self.get_edh().unwrap(),
|
||||
kpps: self.get_int("kpps").unwrap().try_into().unwrap(),
|
||||
intensity: self.get_int("intensity").unwrap().try_into().unwrap(),
|
||||
..WorldState::default()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_edh( &mut self ) -> LJResult<EDH> {
|
||||
// Get new EDH
|
||||
let edh_key = format!("/EDH/{}", self.laser_id);
|
||||
let edh : String = self.connection.get(edh_key)?;
|
||||
let edh : Vec<Vec<f32>> = from_str(&edh)?;
|
||||
let edh = EDH::new(edh)?;
|
||||
Ok(edh)
|
||||
pub fn get_edh(&mut self) -> LJResult<EDH> {
|
||||
// Get new EDH
|
||||
let edh_key = format!("/EDH/{}", self.laser_id);
|
||||
let edh: String = self.connection.get(edh_key)?;
|
||||
let edh: Vec<Vec<f32>> = from_str(&edh)?;
|
||||
let edh = EDH::new(edh)?;
|
||||
Ok(edh)
|
||||
}
|
||||
|
||||
pub fn get_client_key( &mut self ) -> LJResult<String> {
|
||||
let key : String = self.connection.get("/clientkey")?;
|
||||
Ok(key)
|
||||
pub fn get_client_key(&mut self) -> LJResult<String> {
|
||||
let key: String = self.connection.get("/clientkey")?;
|
||||
Ok(key)
|
||||
}
|
||||
|
||||
pub fn get_int(&mut self, key: &str ) -> LJResult<u32> {
|
||||
// Get new Int
|
||||
let fmt = format!("/{key}/{}", self.laser_id);
|
||||
let val : u32 = self.connection.get(fmt)?;
|
||||
Ok(val)
|
||||
pub fn get_color_balance(&mut self) -> LJResult<(u8, u8, u8)> {
|
||||
Ok((
|
||||
self.connection.get("/red")?,
|
||||
self.connection.get("/green")?,
|
||||
self.connection.get("/blue")?,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn get_resampler(&mut self ) -> LJResult<Resampler> {
|
||||
let val: String = self.connection.get(format!("/resampler/{}", self.laser_id))?;
|
||||
let resampler : Resampler = from_str(&val)?;
|
||||
Ok(resampler)
|
||||
}
|
||||
|
||||
pub fn get_int(&mut self, key: &str) -> LJResult<u32> {
|
||||
// Get new Int
|
||||
let fmt = format!("/{key}/{}", self.laser_id);
|
||||
let val: u32 = self.connection.get(fmt)?;
|
||||
Ok(val)
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ use crate::point::{Point, Color};
|
||||
use nalgebra::base::{Matrix3, Matrix1x3};
|
||||
use crate::errors::{LJError, LJResult};
|
||||
use log::debug;
|
||||
use crate::redis_ctrl::Resampler;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct EDH {
|
||||
@ -39,7 +40,7 @@ impl EDH {
|
||||
#[derive(Debug, Default)]
|
||||
pub struct WorldState {
|
||||
pub edh: EDH,
|
||||
pub resampler: Vec<f32>,
|
||||
pub resampler: Resampler,
|
||||
pub client_key: String,
|
||||
pub intensity: u8,
|
||||
pub kpps: u32,
|
||||
@ -47,6 +48,7 @@ pub struct WorldState {
|
||||
pub draw_black: bool,
|
||||
pub draw_grid: bool,
|
||||
pub grid: Vec<Point>,
|
||||
pub color_balance: Color,
|
||||
}
|
||||
|
||||
impl WorldState {}
|
||||
|
Loading…
Reference in New Issue
Block a user