more worldstate keys
This commit is contained in:
		
							parent
							
								
									e5e8ad878b
								
							
						
					
					
						commit
						538f13f539
					
				
							
								
								
									
										18
									
								
								src/conf.rs
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/conf.rs
									
									
									
									
									
								
							| @ -81,14 +81,16 @@ impl Conf { | ||||
| 
 | ||||
|     #[allow(dead_code)] | ||||
|     pub fn dump() { | ||||
| 	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::Replicate(transformer::Replicate::Until(48)) | ||||
| 			  ] | ||||
| 	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::Replicate(transformer::Replicate::Until(48)) | ||||
| 	    ] | ||||
| 	}; | ||||
| 	let s = toml::to_string(&conf).unwrap(); | ||||
| 	println!("{}", s); | ||||
|  | ||||
							
								
								
									
										37
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								src/main.rs
									
									
									
									
									
								
							| @ -51,7 +51,8 @@ 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)); | ||||
| 	let r = running.clone(); | ||||
| @ -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,16 +141,19 @@ fn get_next_frame( | ||||
| 	rs: &mut RedisCtrl, | ||||
| 	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(); | ||||
| 
 | ||||
| 	for transformer in transformers { | ||||
| 		line = transformer.apply(&line, world_state); | ||||
| 	} | ||||
| 
 | ||||
| 	//info!("Line: {:?}", line);
 | ||||
| 	Ok(line) | ||||
|     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(); | ||||
|     
 | ||||
|     for transformer in transformers { | ||||
| 	line = transformer.apply(&line, world_state); | ||||
|     } | ||||
|     
 | ||||
|     //info!("Line: {:?}", line);
 | ||||
|     Ok(line) | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -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) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user