Fix flashing pattern
This commit is contained in:
parent
3aad5f2555
commit
fc3a85140f
@ -25,7 +25,7 @@ pub enum Parameters {
|
|||||||
MovingRainbow(u8, bool),
|
MovingRainbow(u8, bool),
|
||||||
Orb(Rgb, u8, u8),
|
Orb(Rgb, u8, u8),
|
||||||
Solid((Rgb,)),
|
Solid((Rgb,)),
|
||||||
Flashing(Vec<Rgb>, u8),
|
Flashing(Vec<Rgb>, u8, u16),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parameters {
|
impl Parameters {
|
||||||
@ -37,7 +37,7 @@ impl Parameters {
|
|||||||
Self::MovingRainbow(w, f) => Box::new(MovingRainbow::new(w, f)),
|
Self::MovingRainbow(w, f) => Box::new(MovingRainbow::new(w, f)),
|
||||||
Self::Orb(c, x, y) => Box::new(Orb::new(c, x, y)),
|
Self::Orb(c, x, y) => Box::new(Orb::new(c, x, y)),
|
||||||
Self::Solid((c,)) => Box::new(Solid::new(c)),
|
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 {
|
pub struct Flashing {
|
||||||
lights_buf: VecDeque<Rgb>,
|
lights_buf: VecDeque<Rgb>,
|
||||||
width: u8,
|
width: u8,
|
||||||
|
step: u16,
|
||||||
|
tick_rate: u16,
|
||||||
colors: Vec<Rgb>,
|
colors: Vec<Rgb>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Flashing {
|
impl Flashing {
|
||||||
pub fn new(colors: Vec<Rgb>, width: u8) -> Self {
|
pub fn new(colors: Vec<Rgb>, width: u8, tick_rate: u16) -> Self {
|
||||||
Self {
|
Self {
|
||||||
colors,
|
colors,
|
||||||
|
tick_rate,
|
||||||
|
step: 0,
|
||||||
width,
|
width,
|
||||||
lights_buf: VecDeque::new(),
|
lights_buf: VecDeque::new(),
|
||||||
}
|
}
|
||||||
@ -24,17 +28,23 @@ impl Flashing {
|
|||||||
|
|
||||||
impl Pattern for Flashing {
|
impl Pattern for Flashing {
|
||||||
fn step(&mut self) -> Result<bool, ()> {
|
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());
|
self.lights_buf.rotate_right(self.width.into());
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
fn init(&mut self, num_lights: u16) -> Result<(), ()> {
|
fn init(&mut self, num_lights: u16) -> Result<(), ()> {
|
||||||
if num_lights == 0 {
|
if num_lights < 1 {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
let length_factor = num_lights.saturating_mul(u16::from(self.width));
|
let length_factor = num_lights.saturating_mul(u16::from(self.width));
|
||||||
|
|
||||||
let buf_length = color::min_with_factor(num_lights, length_factor)?;
|
let buf_length = color::min_with_factor(num_lights, length_factor)?;
|
||||||
|
|
||||||
|
self.step = 0;
|
||||||
|
|
||||||
self.lights_buf = self
|
self.lights_buf = self
|
||||||
.colors
|
.colors
|
||||||
.iter()
|
.iter()
|
||||||
@ -42,6 +52,7 @@ impl Pattern for Flashing {
|
|||||||
.cycle()
|
.cycle()
|
||||||
.take(buf_length.into())
|
.take(buf_length.into())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn get_strip(&self) -> vec_deque::Iter<Rgb> {
|
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: "Flashing", text: "Flashing", formElements: [
|
||||||
{name: "color", type: "colors", label: "Color", value: []},
|
{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: "width", type: "number", label: "Width", value: "1"},
|
||||||
|
{name: "tick_rate", type: "number", label: "Tick Rate", value: 8},
|
||||||
]},
|
]},
|
||||||
];
|
];
|
||||||
let selectedPattern = possiblePatterns[0];
|
let selectedPattern = possiblePatterns[0];
|
||||||
|
Loading…
Reference in New Issue
Block a user