From ac08d4d3a479723ad7307d253b3445865f52b8ab Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Sun, 26 Dec 2021 20:26:29 -0500 Subject: [PATCH] changes --- src/util/lights.rs | 4 ++-- src/util/pattern.rs | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/util/lights.rs b/src/util/lights.rs index ac7fd90..d43793d 100644 --- a/src/util/lights.rs +++ b/src/util/lights.rs @@ -1,10 +1,10 @@ use rs_ws281x::RawColor; use rs_ws281x::Controller; use rs_ws281x::WS2811Error; -use std::{thread, time}; +// use std::{thread, time}; pub fn run_lights(controller: &mut Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> { - println!("Value: {:?}", values[0]); + // println!("Value: {:?}", values[0]); //thread::sleep(time::Duration::from_millis(10)); let channels: Vec = controller.channels(); let mut strip = controller.leds_mut(channels[0]); diff --git a/src/util/pattern.rs b/src/util/pattern.rs index 24a5877..a6527cc 100644 --- a/src/util/pattern.rs +++ b/src/util/pattern.rs @@ -6,16 +6,16 @@ use std::{ type ParseError = Box; -trait Pattern { - fn execute(&self, values: &mut [RawColor]); +trait Pattern<'a> { + fn execute(&self, values: &'a mut [RawColor]); fn parse(args: Vec) -> Result; } impl TryFrom> for Box { fn try_from(s: Vec) -> Result { match s[0].as_str() { - "unit" => Unit::parse(s) - "val" => Value::parse(s) + "unit" => Unit::parse(s), + "val" => Value::parse(s), _ => Err("No Match".into()) } } @@ -33,7 +33,8 @@ struct Value { r: Option, g: Option, b: Option -}; +} + impl<'a> Pattern for Value<'a> { fn execute(&self, values: &'a mut [RawColor]) { for i in 0..crate::LED_SIZE { @@ -51,9 +52,9 @@ impl<'a> Pattern for Value<'a> { } } fn parse(args: Vec) -> Result { - let param1 = params[1].parse::(); - let param2 = params[2].parse::(); - let param3 = params[2].parse::(); + let param1 = args[1].parse::(); + let param2 = args[2].parse::(); + let param3 = args[2].parse::(); if param1.is_ok() && param2.is_ok() && param3.is_ok() { Ok(Value{ r: param1.unwrap(), @@ -63,9 +64,9 @@ impl<'a> Pattern for Value<'a> { } else { match param2 { - Ok(i) => match params[1].as_str() { + Ok(i) => match args[1].as_str() { "r" => { - Ok(i) => Ok(Value { + Ok(Value { r: Some(i), g: None, b: None @@ -79,7 +80,7 @@ impl<'a> Pattern for Value<'a> { }) }, "b" => { - Ok(i) => Ok(Value { + Ok(Value { r: None, g: None, b: Some(i) @@ -93,5 +94,6 @@ impl<'a> Pattern for Value<'a> { } pub fn parse_line(v: Vec) -> Result, ParseError> { - + let res: Result, ParseError> = v.try_into(); + res } \ No newline at end of file