Compare commits
1 commit
12f144b959
...
0a90a2ca5f
Author | SHA1 | Date | |
---|---|---|---|
0a90a2ca5f |
1 changed files with 6 additions and 8 deletions
14
src/main.rs
14
src/main.rs
|
@ -12,8 +12,6 @@ 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 lock_c = Arc::clone(&lock);
|
|
||||||
|
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let mut controller: Controller = ControllerBuilder::new()
|
let mut controller: Controller = ControllerBuilder::new()
|
||||||
.channel(0, ChannelBuilder::new()
|
.channel(0, ChannelBuilder::new()
|
||||||
|
@ -26,23 +24,23 @@ fn main() {
|
||||||
.build()
|
.build()
|
||||||
.expect("Could not construct LED Controller.");
|
.expect("Could not construct LED Controller.");
|
||||||
loop {
|
loop {
|
||||||
let lights = lock_c.read().expect("Could not read array lock.");
|
let lights = lock.read().expect("Could not read array lock.");
|
||||||
run_lights(&mut controller, &lights).expect("Error running lights controller.");
|
run_lights(&mut controller, &lights).expect("Error running lights controller.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
loop {
|
loop {
|
||||||
|
let lock_c = Arc::clone(&lock);
|
||||||
thread::sleep(time::Duration::from_millis(250));
|
thread::sleep(time::Duration::from_millis(250));
|
||||||
let pattern = format_multiline("unit");
|
let pattern = format_multiline("unit");
|
||||||
let res: Result<Vec<Box<dyn Pattern>>, ParseError> = pattern.iter()
|
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 lights = lock_c.write().unwrap();
|
||||||
let v: Vec<Box<dyn Pattern>> = res.unwrap();
|
let v: Vec<Box<dyn Pattern>> = res.unwrap();
|
||||||
for x in 0..v.len() {
|
v.iter().for_each(move |x| {
|
||||||
let mut lights = lock.write().unwrap();
|
x.execute(&mut lights);
|
||||||
v[x].execute(&mut lights);
|
})
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue