more worldstate keys

This commit is contained in:
Marc Planard 2023-07-06 21:52:20 +02:00
parent e5e8ad878b
commit 538f13f539
4 changed files with 46 additions and 30 deletions

View File

@ -81,12 +81,14 @@ impl Conf {
#[allow(dead_code)]
pub fn dump() {
let conf = Conf { laser_id: 0,
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::Translate(transformer::Translate { x: 2000.0,
y: 2000.0 } ),
TransformConf::Replicate(transformer::Replicate::Until(48))
]
};

View File

@ -51,6 +51,7 @@ 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));
@ -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,7 +141,10 @@ fn get_next_frame(
rs: &mut RedisCtrl,
world_state : &WorldState
) -> LJResult<Vec<Point>> {
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
let format_key = format!("{}{}",
world_state.client_key,
config.laser_id);
let line = rs.get_line(&format_key)?;
let mut line: Vec<Point> = line.into_iter()
.map(|tpl| tpl.into())
.collect();

View File

@ -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<Line> {
pub fn get_line(&mut self, key: &str) -> LJResult<Line> {
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<WorldState>{
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<u32> {
// Get new Int
let fmt = format!("/{key}/{}", self.laser_id);
let val : u32 = self.connection.get(fmt)?;
Ok(val)
}
}

View File

@ -40,7 +40,7 @@ impl EDH {
pub struct WorldState {
pub edh: EDH,
pub resampler: Vec<f32>,
pub client_key: u8,
pub client_key: String, //u8,
pub intensity: u8,
pub kpps: u32,
pub color: Color