fix errors
This commit is contained in:
parent
cc18fdd3b4
commit
f9a37e46d1
2 changed files with 13 additions and 11 deletions
18
src/main.rs
18
src/main.rs
|
@ -5,7 +5,7 @@ use std::sync::{Arc, RwLock};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
|
use rs_ws281x::{RawColor, Controller, ControllerBuilder, ChannelBuilder, StripType};
|
||||||
|
|
||||||
pub const LED_SIZE: i32 = 450;
|
pub const LED_SIZE: usize = 450;
|
||||||
pub const BRIGHTNESS: u8 = 255;
|
pub const BRIGHTNESS: u8 = 255;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -13,18 +13,20 @@ fn main() {
|
||||||
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
|
let lock = Arc::new(RwLock::new([p; LED_SIZE]));
|
||||||
let lock_c = Arc::clone(&lock);
|
let lock_c = Arc::clone(&lock);
|
||||||
|
|
||||||
let controller = ControllerBuilder::new()
|
thread::spawn(move || {
|
||||||
.channel(ChannelBuilder::new()
|
let mut controller: Controller = ControllerBuilder::new()
|
||||||
|
.channel(0, ChannelBuilder::new()
|
||||||
.pin(18)
|
.pin(18)
|
||||||
.count(LED_SIZE)
|
.count(i32::try_from(LED_SIZE).unwrap())
|
||||||
.strip_type(StripType::Ws2812)
|
.strip_type(StripType::Ws2812)
|
||||||
.brightness(BRIGHTNESS)
|
.brightness(BRIGHTNESS)
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.build();
|
.build().unwrap();
|
||||||
thread::spawn(move || loop {
|
loop {
|
||||||
let lights = lock_c.read().unwrap();
|
let lights = lock_c.read().unwrap();
|
||||||
run_lights(&controller, &lights);
|
run_lights(&mut controller, &lights);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
let mut x: u8 = 0;
|
let mut x: u8 = 0;
|
||||||
loop {
|
loop {
|
||||||
|
|
|
@ -2,14 +2,14 @@ use rs_ws281x::RawColor;
|
||||||
use rs_ws281x::Controller;
|
use rs_ws281x::Controller;
|
||||||
use rs_ws281x::WS2811Error;
|
use rs_ws281x::WS2811Error;
|
||||||
|
|
||||||
pub fn run_lights(controller: &Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
|
pub fn run_lights(controller: &mut Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
|
||||||
// println!("Value: {:?}", strip[0]);
|
// println!("Value: {:?}", strip[0]);
|
||||||
let channels: Vec<usize> = controller.channels();
|
let channels: Vec<usize> = controller.channels();
|
||||||
let mut strip = controller.leds_mut(channels[0]);
|
let mut strip = controller.leds_mut(channels[0]);
|
||||||
for x in 0..strip.len() {
|
for i in 0..strip.len() {
|
||||||
strip[i] = values[i];
|
strip[i] = values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.render();
|
controller.render();
|
||||||
controller.wait()
|
controller.wait()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue