WIP working on main patterns loop

This commit is contained in:
Tobias Ollive 2022-02-23 19:48:38 +01:00
parent 3996e1b09f
commit b43490e876
4 changed files with 53 additions and 0 deletions

13
spectacle.toml Normal file
View File

@ -0,0 +1,13 @@
[pattern]
name = "fade"
period = "300"
nbr_iterations = "25"
initial_color = "
[pattern]
name = "rainbow"
period = "100"
step = "10"

View File

@ -1,5 +1,6 @@
mod bluetooth;
mod patterns;
mod runner;
use crate::patterns::{ColorWipe, Fade, PixelColor, Rainbow};
use bluer::gatt::remote::Characteristic;
@ -68,6 +69,7 @@ async fn main() -> bluer::Result<()> {
infinite: true,
};
let mut fade = Fade::<25> {
current_iteration: 0,
nbr_iterations: 25,
@ -89,6 +91,7 @@ async fn main() -> bluer::Result<()> {
step: Some(10),
};
let mut strip = fade.next().unwrap();
tokio::time::sleep(Duration::from_secs(5)).await;
println!("starting");

View File

@ -1,5 +1,11 @@
use std::fmt;
pub(crate) enum patterns<const N: usize> {
Rainbow(Rainbow<N>),
Fade(Fade<N>),
ColorWipe(ColorWipe<N>),
}
#[derive(Clone, Copy, Debug, Default)]
pub struct PixelColor {
pub(crate) red: u8,

31
src/runner.rs Normal file
View 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;
}
}
}
}