WIP working on main patterns loop
This commit is contained in:
parent
3996e1b09f
commit
b43490e876
13
spectacle.toml
Normal file
13
spectacle.toml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
[pattern]
|
||||||
|
name = "fade"
|
||||||
|
period = "300"
|
||||||
|
nbr_iterations = "25"
|
||||||
|
initial_color = "
|
||||||
|
|
||||||
|
[pattern]
|
||||||
|
name = "rainbow"
|
||||||
|
period = "100"
|
||||||
|
step = "10"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
mod bluetooth;
|
mod bluetooth;
|
||||||
mod patterns;
|
mod patterns;
|
||||||
|
mod runner;
|
||||||
|
|
||||||
use crate::patterns::{ColorWipe, Fade, PixelColor, Rainbow};
|
use crate::patterns::{ColorWipe, Fade, PixelColor, Rainbow};
|
||||||
use bluer::gatt::remote::Characteristic;
|
use bluer::gatt::remote::Characteristic;
|
||||||
|
@ -68,6 +69,7 @@ async fn main() -> bluer::Result<()> {
|
||||||
infinite: true,
|
infinite: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let mut fade = Fade::<25> {
|
let mut fade = Fade::<25> {
|
||||||
current_iteration: 0,
|
current_iteration: 0,
|
||||||
nbr_iterations: 25,
|
nbr_iterations: 25,
|
||||||
|
@ -89,6 +91,7 @@ async fn main() -> bluer::Result<()> {
|
||||||
step: Some(10),
|
step: Some(10),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
let mut strip = fade.next().unwrap();
|
let mut strip = fade.next().unwrap();
|
||||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||||
println!("starting");
|
println!("starting");
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
pub(crate) enum patterns<const N: usize> {
|
||||||
|
Rainbow(Rainbow<N>),
|
||||||
|
Fade(Fade<N>),
|
||||||
|
ColorWipe(ColorWipe<N>),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct PixelColor {
|
pub struct PixelColor {
|
||||||
pub(crate) red: u8,
|
pub(crate) red: u8,
|
||||||
|
|
31
src/runner.rs
Normal file
31
src/runner.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
use std::time::Duration;
|
||||||
|
use crate::patterns::patterns;
|
||||||
|
use crate::Strip;
|
||||||
|
|
||||||
|
struct Context<const N: usize> {
|
||||||
|
pattern : Box<dyn Iterator<Item = Strip<N>>>,
|
||||||
|
period: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Runner<const N: usize> {
|
||||||
|
list : Vec<Context<N>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<const N: usize> Runner<N> {
|
||||||
|
async fn runner_loop(self, tx: Sender<Strip<N>>) {
|
||||||
|
for mut context in self.list {
|
||||||
|
let mut strip = context.pattern.next().unwrap();
|
||||||
|
let delay = context.period;
|
||||||
|
while tx.send(strip).is_ok() {
|
||||||
|
if let Some(value) = context.pattern.next() {
|
||||||
|
strip = value;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tokio::time::sleep(delay).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user