From 48dee090d3ad9389b00c82a00f4d1b182ee6ae92 Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Wed, 29 Dec 2021 23:10:47 -0500 Subject: [PATCH] fix rand --- src/util/lights.rs | 2 +- src/util/pattern.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/lights.rs b/src/util/lights.rs index 754f3fc..5a8682d 100644 --- a/src/util/lights.rs +++ b/src/util/lights.rs @@ -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 = controller.channels(); let strip = controller.leds_mut(channels[0]); diff --git a/src/util/pattern.rs b/src/util/pattern.rs index b060938..636ca90 100644 --- a/src/util/pattern.rs +++ b/src/util/pattern.rs @@ -133,22 +133,26 @@ impl Pattern for Random { fn execute(&self, values: &mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>, _ticks: u64) { use rand::prelude::*; let mut rng = rand::thread_rng(); - for x in 0..values.len() { - let mut color = (*values)[x]; + for i in 0..values.len() { + let mut color = (*values)[i]; let min = self.min; let max = self.max; if self.r { let y: f64 = rng.gen(); color[2] = (y * (max - min) as f64) as u8 + min; + //println!("r {} {}", y, color[2]); } if self.g { let y: f64 = rng.gen(); color[1] = (y * (max - min) as f64) as u8 + min; + //println!("g {} {}", y, color[1]); } if self.b { let y: f64 = rng.gen(); color[0] = (y * (max - min) as f64) as u8 + min; + //println!("b {} {}", y, color[0]); } + (*values)[i] = color; } } fn parse(args: Vec) -> Result { @@ -172,7 +176,7 @@ impl Pattern for Random { } } }; - for x in 1..end { + for x in 0..end+1 { match args[x].as_str() { "r" => {r = true;}, "g" => {g = true;}, @@ -180,6 +184,7 @@ impl Pattern for Random { _ => {} } } + //println!("{} {} {}", r,g,b); Ok(Random { r: r, g: g,