add ticks
This commit is contained in:
parent
85cef5d474
commit
712140fc8d
3 changed files with 7 additions and 5 deletions
|
@ -40,6 +40,7 @@ fn main() {
|
|||
});
|
||||
|
||||
//pattern management
|
||||
let mut ticks = 0;
|
||||
loop {
|
||||
thread::sleep(time::Duration::from_millis(LOOP_WAIT));
|
||||
let c_lock = Arc::clone(&lock);
|
||||
|
@ -48,7 +49,8 @@ fn main() {
|
|||
for p in *data {
|
||||
//let c_lock = Arc::clone(&lock);
|
||||
//let mut lights = c_lock.write().unwrap();
|
||||
p.execute(&mut lights);
|
||||
p.execute(&mut lights, ticks);
|
||||
}
|
||||
ticks++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use rs_ws281x::WS2811Error;
|
|||
// use std::{thread, time};
|
||||
|
||||
pub fn run_lights(controller: &mut Controller, values: &[RawColor; crate::LED_SIZE]) -> Result<(), WS2811Error> {
|
||||
println!("Value: {:?}", values[0]);
|
||||
// println!("Value: {:?}", values[0]);
|
||||
//thread::sleep(time::Duration::from_millis(10));
|
||||
let channels: Vec<usize> = controller.channels();
|
||||
let strip = controller.leds_mut(channels[0]);
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::sync::RwLockWriteGuard;
|
|||
pub type ParseError = Box<dyn std::error::Error>;
|
||||
|
||||
pub trait Pattern: Send {
|
||||
fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>);
|
||||
fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>, ticks: u64);
|
||||
fn parse(args: Vec<String>) -> Result<Self, ParseError> where Self: Sized;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ impl TryFrom<Vec<String>> for Box<dyn Pattern> {
|
|||
|
||||
struct Unit;
|
||||
impl Pattern for Unit {
|
||||
fn execute(&self, _values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {}
|
||||
fn execute(&self, _values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>, ticks: u64) {}
|
||||
fn parse(_args: Vec<String>) -> Result<Self, ParseError> {
|
||||
Ok(Unit {})
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ struct Value {
|
|||
}
|
||||
|
||||
impl Pattern for Value {
|
||||
fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {
|
||||
fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>, ticks: u64) {
|
||||
for i in 0..crate::LED_SIZE {
|
||||
let mut color: RawColor = (*values)[i];
|
||||
if self.r.is_some() {
|
||||
|
|
Loading…
Reference in a new issue