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,14 +81,16 @@ impl Conf {
#[allow(dead_code)] #[allow(dead_code)]
pub fn dump() { pub fn dump() {
let conf = Conf { laser_id: 0, let conf = Conf {
debug: true, laser_id: 0,
redis_url: "redis://127.0.0.1:6379/".to_string(), debug: true,
dac: DacFamily::Helios(HeliosConf { id: 0 }), redis_url: "redis://127.0.0.1:6379/".to_string(),
transformers: vec![ dac: DacFamily::Helios(HeliosConf { id: 0 }),
TransformConf::Translate(transformer::Translate { x: 2000.0, y: 2000.0 } ), transformers: vec![
TransformConf::Replicate(transformer::Replicate::Until(48)) TransformConf::Translate(transformer::Translate { x: 2000.0,
] y: 2000.0 } ),
TransformConf::Replicate(transformer::Replicate::Until(48))
]
}; };
let s = toml::to_string(&conf).unwrap(); let s = toml::to_string(&conf).unwrap();
println!("{}", s); println!("{}", s);

View File

@ -51,7 +51,8 @@ fn run_all() -> LJResult<()> {
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()?; let mut world_state = rs.init_world_state()?;
info!("WorldState: {:?}", 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();
@ -93,15 +94,18 @@ fn run_all() -> LJResult<()> {
&config, &config,
&transformers, &transformers,
&mut rs, &mut rs,
// order == Order::Black,
&world_state &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::Intensity => {
world_state.intensity = rs.get_int("intensity")?
.try_into()?;
},
Order::Edh => { Order::Edh => {
world_state.edh = rs.get_edh()?; world_state.edh = rs.get_edh()?;
} },
// Order::ClientKey => rs.client_key(), // Order::ClientKey => rs.client_key(),
// Order::ColorBalance => {}, // Order::ColorBalance => {},
@ -137,16 +141,19 @@ fn get_next_frame(
rs: &mut RedisCtrl, rs: &mut RedisCtrl,
world_state : &WorldState world_state : &WorldState
) -> LJResult<Vec<Point>> { ) -> LJResult<Vec<Point>> {
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?; let format_key = format!("{}{}",
let mut line: Vec<Point> = line.into_iter() world_state.client_key,
.map(|tpl| tpl.into()) config.laser_id);
.collect(); let line = rs.get_line(&format_key)?;
let mut line: Vec<Point> = line.into_iter()
for transformer in transformers { .map(|tpl| tpl.into())
line = transformer.apply(&line, world_state); .collect();
}
for transformer in transformers {
//info!("Line: {:?}", line); line = transformer.apply(&line, world_state);
Ok(line) }
//info!("Line: {:?}", line);
Ok(line)
} }

View File

@ -3,7 +3,7 @@ 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,EDH}; use crate::worldstate::{WorldState,EDH};
use log::info; // use log::info;
#[repr(u8)] #[repr(u8)]
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -62,7 +62,7 @@ impl RedisCtrl {
Ok(RedisCtrl { client, connection, laser_id: *laser_id }) 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 val: String = self.connection.get(key)?;
let line: Line = from_str(&val)?; let line: Line = from_str(&val)?;
Ok(line) Ok(line)
@ -100,11 +100,11 @@ impl RedisCtrl {
} }
pub fn init_world_state( &mut self) -> LJResult<WorldState>{ pub fn init_world_state( &mut self) -> LJResult<WorldState>{
let edh = self.get_edh()?;
info!("EDH: {:?}", edh);
Ok(WorldState { 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() ..WorldState::default()
}) })
} }
@ -117,4 +117,11 @@ impl RedisCtrl {
let edh = EDH::new(edh)?; let edh = EDH::new(edh)?;
Ok(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 struct WorldState {
pub edh: EDH, pub edh: EDH,
pub resampler: Vec<f32>, pub resampler: Vec<f32>,
pub client_key: u8, pub client_key: String, //u8,
pub intensity: u8, pub intensity: u8,
pub kpps: u32, pub kpps: u32,
pub color: Color pub color: Color