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)?; | 	let mut tracer = device_factory(&config)?; | ||||||
| 	world_state.grid = tracer.grid(); | 	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
 | 	// Setup geometry transformers on points lists
 | ||||||
| 	let transformers = config.get_transformers(); | 	let transformers = config.get_transformers(); | ||||||
| 
 | 
 | ||||||
| 	// 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)?; | 		let order = rs.get_order(config.laser_id)?; | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 		match order { | 		match order { | ||||||
| 			Order::Draw | Order::Black | Order::Grid => { | 			Order::Draw | Order::Black | Order::Grid => { | ||||||
| 				// 0 : Draw Normal point list
 | 				// 0 : Draw Normal point list
 | ||||||
| @ -110,11 +104,14 @@ fn run_all() -> LJResult<()> { | |||||||
| 			Order::ClientKey => { | 			Order::ClientKey => { | ||||||
| 				world_state.client_key = rs.get_client_key()?; | 				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
 | 				// 9 : poweroff LJ
 | ||||||
| 				info!("Order: {:?}", order); | 				info!("Order: {:?}", order); | ||||||
| 			} | 			} | ||||||
| @ -128,7 +125,6 @@ fn run_all() -> LJResult<()> { | |||||||
| 
 | 
 | ||||||
| fn init_logging(config: &LJResult<Conf>) { | fn init_logging(config: &LJResult<Conf>) { | ||||||
| 	if let Ok(ref config) = config { | 	if let Ok(ref config) = config { | ||||||
| 
 |  | ||||||
| 		let level = if config.debug { | 		let level = if config.debug { | ||||||
| 			LevelFilter::Debug | 			LevelFilter::Debug | ||||||
| 		} else { | 		} else { | ||||||
|  | |||||||
| @ -2,7 +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,EDH}; | use crate::worldstate::{WorldState, EDH}; | ||||||
| // use log::info;
 | // use log::info;
 | ||||||
| 
 | 
 | ||||||
| #[repr(u8)] | #[repr(u8)] | ||||||
| @ -10,7 +10,6 @@ use crate::worldstate::{WorldState,EDH}; | |||||||
| pub enum Order { | pub enum Order { | ||||||
| 	Draw = 0, | 	Draw = 0, | ||||||
| 	Edh, | 	Edh, | ||||||
| 	//homography
 |  | ||||||
| 	Black, | 	Black, | ||||||
| 	Grid, | 	Grid, | ||||||
| 	Resampler, | 	Resampler, | ||||||
| @ -46,6 +45,7 @@ impl TryFrom<u8> for Order { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub type Line = Vec<(f32, f32, u32)>; | pub type Line = Vec<(f32, f32, u32)>; | ||||||
|  | pub type Resampler = Vec<(f32,f32)>; | ||||||
| 
 | 
 | ||||||
| pub struct RedisCtrl { | pub struct RedisCtrl { | ||||||
| 	pub client: Client, | 	pub client: Client, | ||||||
| @ -84,11 +84,6 @@ impl RedisCtrl { | |||||||
| 		Ok(val.try_into()?) | 		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<()> { | 	pub fn set_status(&mut self, status: Status) -> LJResult<()> { | ||||||
| 		let lstt_key = format!("/lstt/{}", self.laser_id); | 		let lstt_key = format!("/lstt/{}", self.laser_id); | ||||||
| 		let cap_key = format!("/cap/{}", self.laser_id); | 		let cap_key = format!("/cap/{}", self.laser_id); | ||||||
| @ -99,34 +94,48 @@ impl RedisCtrl { | |||||||
| 		Ok(()) | 		Ok(()) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pub fn init_world_state( &mut self) -> LJResult<WorldState>{ | 	pub fn init_world_state(&mut self) -> LJResult<WorldState> { | ||||||
| 	    Ok(WorldState { | 		Ok(WorldState { | ||||||
| 		client_key: self.get_client_key().unwrap(), | 			client_key: self.get_client_key().unwrap(), | ||||||
| 		edh: self.get_edh().unwrap(), | 			edh: self.get_edh().unwrap(), | ||||||
| 		kpps: self.get_int("kpps").unwrap().try_into().unwrap(), | 			kpps: self.get_int("kpps").unwrap().try_into().unwrap(), | ||||||
| 		intensity: self.get_int("intensity").unwrap().try_into().unwrap(), | 			intensity: self.get_int("intensity").unwrap().try_into().unwrap(), | ||||||
| 		..WorldState::default() | 			..WorldState::default() | ||||||
| 	    }) | 		}) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pub fn get_edh( &mut self ) -> LJResult<EDH> { | 	pub fn get_edh(&mut self) -> LJResult<EDH> { | ||||||
| 	    // Get new EDH
 | 		// Get new EDH
 | ||||||
| 	    let edh_key = format!("/EDH/{}", self.laser_id); | 		let edh_key = format!("/EDH/{}", self.laser_id); | ||||||
| 	    let edh : String = self.connection.get(edh_key)?; | 		let edh: String = self.connection.get(edh_key)?; | ||||||
| 	    let edh : Vec<Vec<f32>> = from_str(&edh)?; | 		let edh: Vec<Vec<f32>> = from_str(&edh)?; | ||||||
| 	    let edh = EDH::new(edh)?; | 		let edh = EDH::new(edh)?; | ||||||
| 	    Ok(edh) | 		Ok(edh) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pub fn get_client_key( &mut self ) -> LJResult<String> { | 	pub fn get_client_key(&mut self) -> LJResult<String> { | ||||||
| 	    let key : String = self.connection.get("/clientkey")?; | 		let key: String = self.connection.get("/clientkey")?; | ||||||
| 	    Ok(key) | 		Ok(key) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	pub fn get_int(&mut self, key: &str ) -> LJResult<u32> { | 	pub fn get_color_balance(&mut self) -> LJResult<(u8, u8, u8)> { | ||||||
| 	    // Get new Int
 | 		Ok(( | ||||||
| 	    let fmt = format!("/{key}/{}", self.laser_id); | 			self.connection.get("/red")?, | ||||||
| 	    let val : u32 = self.connection.get(fmt)?; | 			self.connection.get("/green")?, | ||||||
| 	    Ok(val) | 			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 nalgebra::base::{Matrix3, Matrix1x3}; | ||||||
| use crate::errors::{LJError, LJResult}; | use crate::errors::{LJError, LJResult}; | ||||||
| use log::debug; | use log::debug; | ||||||
|  | use crate::redis_ctrl::Resampler; | ||||||
| 
 | 
 | ||||||
| #[derive(Debug, Default)] | #[derive(Debug, Default)] | ||||||
| pub struct EDH { | pub struct EDH { | ||||||
| @ -39,7 +40,7 @@ impl EDH { | |||||||
| #[derive(Debug, Default)] | #[derive(Debug, Default)] | ||||||
| pub struct WorldState { | pub struct WorldState { | ||||||
| 	pub edh: EDH, | 	pub edh: EDH, | ||||||
| 	pub resampler: Vec<f32>, | 	pub resampler: Resampler, | ||||||
| 	pub client_key: String, | 	pub client_key: String, | ||||||
| 	pub intensity: u8, | 	pub intensity: u8, | ||||||
| 	pub kpps: u32, | 	pub kpps: u32, | ||||||
| @ -47,6 +48,7 @@ pub struct WorldState { | |||||||
| 	pub draw_black: bool, | 	pub draw_black: bool, | ||||||
| 	pub draw_grid: bool, | 	pub draw_grid: bool, | ||||||
| 	pub grid: Vec<Point>, | 	pub grid: Vec<Point>, | ||||||
|  | 	pub color_balance: Color, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl WorldState {} | impl WorldState {} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user