From 511a37e74053b28b8562354f8ecf7c1dbe056e00 Mon Sep 17 00:00:00 2001 From: Marc Planard Date: Sat, 3 Jun 2023 16:20:35 +0200 Subject: [PATCH] start implementing orders --- src/main.rs | 9 ++++++-- src/redis_ctrl.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3e49000..54c6942 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use helios_dac::NativeHeliosDacController; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; -use redis_ctrl::RedisCtrl; +use redis_ctrl::{RedisCtrl,Order}; const CENTER : (u16,u16) = (2000, 2000); @@ -35,7 +35,12 @@ pub fn main() -> Result<(), Box> { let device = devices.into_iter().next().unwrap(); let mut device = device.open()?; - while running.load(Ordering::SeqCst) { + while running.load(Ordering::SeqCst) { + let order = rs.get_order(0)?; + if order != Order::Draw { + println!("{:?}", order); + } + let frame = get_next_frame(1000, &mut rs)?; while let Ok(DeviceStatus::NotReady) = device.status() { diff --git a/src/redis_ctrl.rs b/src/redis_ctrl.rs index bd8cb9b..ff60f80 100644 --- a/src/redis_ctrl.rs +++ b/src/redis_ctrl.rs @@ -5,6 +5,45 @@ use redis::{ }; use ron::de::from_str; +#[repr(u8)] +#[derive(Debug,PartialEq)] +pub enum Order { + Draw = 0, + Edh, //homography + Black, + Grid, + Resampler, + ClientKey, + Intensity, + Kpps, + ColorBalance +} + +impl TryFrom for Order { + type Error = String; + + fn try_from(value: u8) -> Result { + use Order::*; + + if value > 8 { + return Err("order out of range".to_string()); + } + + Ok(match value { + 0 => Draw, + 1 => Edh, + 2 => Black, + 3 => Grid, + 4 => Resampler, + 5 => ClientKey, + 6 => Intensity, + 7 => Kpps, + 8 => ColorBalance, + _ => panic!("Can't be there") + }) + } +} + pub type Line = Vec<(f32,f32,u32)>; pub struct RedisCtrl { @@ -28,5 +67,20 @@ impl RedisCtrl { let line : Line = from_str(&val)?; Ok(line) } + + pub fn get_order( + &mut self, + id: u8 + ) -> Result> { + let path = format!("/order/{id}"); + let val : u8 = self.connection.get(path.clone())?; + + if val == 1 || val >= 4 { + self.connection.set(path, 0)?; + } + + Ok(val.try_into()?) + } + }