This commit is contained in:
jane 2021-12-24 11:39:02 -05:00
parent 51345aee4a
commit c908f21a87
2 changed files with 8 additions and 9 deletions

2
.gitignore vendored
View File

@ -5,3 +5,5 @@ node_modules/
# Added by cargo # Added by cargo
/target /target
rls*.log

View File

@ -1,7 +1,7 @@
pub mod util; pub mod util;
use util::lights::*; use util::lights::*;
use std::sync::RwLock; use std::sync::{Arc, RwLock};
use std::thread; use std::thread;
use candela::Pixel; use candela::Pixel;
@ -9,10 +9,11 @@ use candela::Pixel;
pub const LED_SIZE: usize = 450; pub const LED_SIZE: usize = 450;
fn main() { fn main() {
let mut p: Pixel = [0, 0, 0, 0]; let p: Pixel = [0, 0, 0, 0];
let lock = RwLock::new([p; LED_SIZE]); let lock = Arc::new(RwLock::new([p; LED_SIZE]));
let lock_c = Arc::clone(&lock);
thread::spawn(move || loop { thread::spawn(move || loop {
let lights = lock.read().unwrap(); let lights = lock_c.read().unwrap();
run_lights(&lights); run_lights(&lights);
}); });
let mut x: u8 = 0; let mut x: u8 = 0;
@ -20,11 +21,7 @@ fn main() {
if x == 255 { if x == 255 {
x = 0; x = 0;
} }
let color = Color { let color: Pixel = [x, x, x, 255];
r: x,
g: x,
b: x
};
let mut lights = lock.write().unwrap(); let mut lights = lock.write().unwrap();
lights[0] = color; lights[0] = color;
x += 1; x += 1;