move parse out of loop
This commit is contained in:
parent
2016f85fb0
commit
d3bd1fee20
1 changed files with 17 additions and 12 deletions
21
src/main.rs
21
src/main.rs
|
@ -12,6 +12,7 @@ pub const BRIGHTNESS: u8 = 150;
|
||||||
fn main() {
|
fn main() {
|
||||||
let p: RawColor = [0, 0, 0, 0];
|
let p: RawColor = [0, 0, 0, 0];
|
||||||
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
|
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
|
||||||
|
let pattern: Arc<RwLock<Vec<Box<dyn Pattern>>>> = Arc::new(RwLock::new(Vec::new()));
|
||||||
let read = Arc::clone(&lock);
|
let read = Arc::clone(&lock);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut controller: Controller = ControllerBuilder::new()
|
let mut controller: Controller = ControllerBuilder::new()
|
||||||
|
@ -29,19 +30,23 @@ fn main() {
|
||||||
run_lights(&mut controller, &lights).expect("Error running lights controller.");
|
run_lights(&mut controller, &lights).expect("Error running lights controller.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
loop {
|
let mul_string = format_multiline("unit");
|
||||||
let lock_c = Arc::clone(&lock);
|
let res: Result<Vec<Box<dyn Pattern>>, ParseError> = mul_string.iter()
|
||||||
thread::sleep(time::Duration::from_millis(250));
|
|
||||||
let pattern = format_multiline("unit");
|
|
||||||
let res: Result<Vec<Box<dyn Pattern>>, ParseError> = pattern.iter()
|
|
||||||
.map(|x: &Vec<String>| parse_line((*x).clone()))
|
.map(|x: &Vec<String>| parse_line((*x).clone()))
|
||||||
.collect();
|
.collect();
|
||||||
if res.is_ok() {
|
if res.is_ok() {
|
||||||
|
let mut p = pattern.write().unwrap();
|
||||||
|
p = res.unwrap();
|
||||||
|
}
|
||||||
|
loop {
|
||||||
|
thread::sleep(time::Duration::from_millis(250));
|
||||||
|
|
||||||
|
let lock_c = Arc::clone(&lock);
|
||||||
|
let pattern_c = Arc::clone(&pattern);
|
||||||
|
let v: Vec<Box<dyn Pattern>> = pattern_c.read().expect("could not read pattern");
|
||||||
let mut lights = lock_c.write().unwrap();
|
let mut lights = lock_c.write().unwrap();
|
||||||
let v: Vec<Box<dyn Pattern>> = res.unwrap();
|
|
||||||
v.iter().for_each(move |x| {
|
v.iter().for_each(move |x| {
|
||||||
x.execute(&mut lights);
|
x.execute(&mut lights);
|
||||||
})
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue