diff --git a/src/main.rs b/src/main.rs index b7841ad..439f1cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,12 +8,14 @@ use std::{thread, time}; pub const LED_SIZE: usize = 450; //450 pub const BRIGHTNESS: u8 = 150; +pub const LOOP_WAIT: u64 = 250; fn main() { let p: RawColor = [0, 0, 0, 0]; let lock = Arc::new(RwLock::new([p; LED_SIZE])); let mut pattern: Vec> = Vec::new(); let read = Arc::clone(&lock); + /// light management thread::spawn(move || { let mut controller: Controller = ControllerBuilder::new() .channel(0, ChannelBuilder::new() @@ -30,6 +32,8 @@ fn main() { run_lights(&mut controller, &lights).expect("Error running lights controller."); } }); + + /// pattern parsing let mul_string = format_multiline("unit"); let res: Result>, ParseError> = mul_string.iter() .map(|x: &Vec| parse_line((*x).clone())) @@ -37,8 +41,10 @@ fn main() { if res.is_ok() { pattern = res.unwrap(); } + + /// pattern management loop { - thread::sleep(time::Duration::from_millis(250)); + thread::sleep(time::Duration::from_millis(LOOP_WAIT)); for p in &pattern { let c_lock = Arc::clone(&lock); let mut lights = c_lock.write().unwrap(); diff --git a/src/util/pattern.rs b/src/util/pattern.rs index ce732f1..fe24ecb 100644 --- a/src/util/pattern.rs +++ b/src/util/pattern.rs @@ -7,12 +7,12 @@ use std::sync::RwLockWriteGuard; pub type ParseError = Box; -pub trait Pattern<'a> { - fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>); +pub trait Pattern { + fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>); fn parse(args: Vec) -> Result where Self: Sized; } -impl<'a> TryFrom> for Box> { +impl TryFrom> for Box { type Error = ParseError; fn try_from(s: Vec) -> Result { match s[0].as_str() { @@ -24,8 +24,8 @@ impl<'a> TryFrom> for Box> { } struct Unit; -impl<'a> Pattern<'a> for Unit { - fn execute(&self, _values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {} +impl Pattern for Unit { + fn execute(&self, _values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {} fn parse(_args: Vec) -> Result { Ok(Unit {}) } @@ -37,8 +37,8 @@ struct Value { b: Option } -impl<'a> Pattern<'a> for Value { - fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) { +impl Pattern for Value { + fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) { for i in 0..crate::LED_SIZE { let mut color: RawColor = (*values)[i]; if self.r.is_some() { @@ -96,7 +96,7 @@ impl<'a> Pattern<'a> for Value { } } -pub fn parse_line<'a>(v: Vec) -> Result>, ParseError> { +pub fn parse_line(v: Vec) -> Result, ParseError> { v.try_into() }