Fix flashing pattern
This commit is contained in:
parent
3aad5f2555
commit
fc3a85140f
@ -25,7 +25,7 @@ pub enum Parameters {
|
||||
MovingRainbow(u8, bool),
|
||||
Orb(Rgb, u8, u8),
|
||||
Solid((Rgb,)),
|
||||
Flashing(Vec<Rgb>, u8),
|
||||
Flashing(Vec<Rgb>, u8, u16),
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
@ -37,7 +37,7 @@ impl Parameters {
|
||||
Self::MovingRainbow(w, f) => Box::new(MovingRainbow::new(w, f)),
|
||||
Self::Orb(c, x, y) => Box::new(Orb::new(c, x, y)),
|
||||
Self::Solid((c,)) => Box::new(Solid::new(c)),
|
||||
Self::Flashing(cs, w) => Box::new(Flashing::new(cs, w)),
|
||||
Self::Flashing(cs, w, r) => Box::new(Flashing::new(cs, w, r)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,17 @@ use std::{
|
||||
pub struct Flashing {
|
||||
lights_buf: VecDeque<Rgb>,
|
||||
width: u8,
|
||||
step: u16,
|
||||
tick_rate: u16,
|
||||
colors: Vec<Rgb>,
|
||||
}
|
||||
|
||||
impl Flashing {
|
||||
pub fn new(colors: Vec<Rgb>, width: u8) -> Self {
|
||||
pub fn new(colors: Vec<Rgb>, width: u8, tick_rate: u16) -> Self {
|
||||
Self {
|
||||
colors,
|
||||
tick_rate,
|
||||
step: 0,
|
||||
width,
|
||||
lights_buf: VecDeque::new(),
|
||||
}
|
||||
@ -24,17 +28,23 @@ impl Flashing {
|
||||
|
||||
impl Pattern for Flashing {
|
||||
fn step(&mut self) -> Result<bool, ()> {
|
||||
self.step = self.step.wrapping_add(1).rem_euclid(self.tick_rate);
|
||||
if self.step != 0 {
|
||||
return Ok(false);
|
||||
}
|
||||
self.lights_buf.rotate_right(self.width.into());
|
||||
Ok(true)
|
||||
}
|
||||
fn init(&mut self, num_lights: u16) -> Result<(), ()> {
|
||||
if num_lights == 0 {
|
||||
if num_lights < 1 {
|
||||
return Err(());
|
||||
}
|
||||
let length_factor = num_lights.saturating_mul(u16::from(self.width));
|
||||
|
||||
let buf_length = color::min_with_factor(num_lights, length_factor)?;
|
||||
|
||||
self.step = 0;
|
||||
|
||||
self.lights_buf = self
|
||||
.colors
|
||||
.iter()
|
||||
@ -42,6 +52,7 @@ impl Pattern for Flashing {
|
||||
.cycle()
|
||||
.take(buf_length.into())
|
||||
.collect();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
fn get_strip(&self) -> vec_deque::Iter<Rgb> {
|
||||
|
1345
web/package-lock.json
generated
1345
web/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -28,12 +28,8 @@
|
||||
]},
|
||||
{name: "Flashing", text: "Flashing", formElements: [
|
||||
{name: "color", type: "colors", label: "Color", value: []},
|
||||
// {name: "color", type: "color", label: "Color1", value: "#000000"},
|
||||
// {name: "color", type: "color", label: "Color2", value: "#000000"},
|
||||
// {name: "color", type: "color", label: "Color3", value: "#000000"},
|
||||
// {name: "color", type: "color", label: "Color4", value: "#000000"},
|
||||
// {name: "color", type: "color", label: "Color5", value: "#000000"},
|
||||
{name: "width", type: "number", label: "Width", value: "1"},
|
||||
{name: "tick_rate", type: "number", label: "Tick Rate", value: 8},
|
||||
]},
|
||||
];
|
||||
let selectedPattern = possiblePatterns[0];
|
||||
|
Loading…
Reference in New Issue
Block a user