thank you slice

This commit is contained in:
jane 2021-12-28 17:25:59 -05:00
parent b03eae4f0e
commit e94d186001

View file

@ -12,7 +12,7 @@ pub const BRIGHTNESS: u8 = 150;
fn main() {
let p: RawColor = [0, 0, 0, 0];
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
let pattern: Arc<RwLock<Vec<Box<dyn Pattern>>>> = Arc::new(RwLock::new(Vec::new()));
let mut pattern: Vec<Box<dyn Pattern>> = Vec::new();
let read = Arc::clone(&lock);
thread::spawn(move || {
let mut controller: Controller = ControllerBuilder::new()
@ -35,17 +35,14 @@ fn main() {
.map(|x: &Vec<String>| parse_line((*x).clone()))
.collect();
if res.is_ok() {
let mut p = pattern.write().unwrap();
*p = res.unwrap();
pattern = res.unwrap();
}
let lock_c = Arc::clone(&lock);
let mut lights = lock_c.write().unwrap();
loop {
thread::sleep(time::Duration::from_millis(250));
let pattern_c = Arc::clone(&pattern);
let v = pattern_c.read().expect("could not read pattern");
(*v).iter().for_each(move |x: &Box<dyn Pattern>| {
x.execute(&mut lights);
});
for p in &pattern {
let c_lock = Arc::clone(&lock);
let mut lights = c_lock.write().unwrap();
p.execute(&mut lights);
}
}
}