From b43490e8764b052d1d9164a7bf23c2f322cd5b93 Mon Sep 17 00:00:00 2001 From: Tobias Ollive Date: Wed, 23 Feb 2022 19:48:38 +0100 Subject: [PATCH] WIP working on main patterns loop --- spectacle.toml | 13 +++++++++++++ src/main.rs | 3 +++ src/patterns.rs | 6 ++++++ src/runner.rs | 31 +++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 spectacle.toml create mode 100644 src/runner.rs diff --git a/spectacle.toml b/spectacle.toml new file mode 100644 index 0000000..50d51ad --- /dev/null +++ b/spectacle.toml @@ -0,0 +1,13 @@ + +[pattern] +name = "fade" +period = "300" +nbr_iterations = "25" +initial_color = " + +[pattern] +name = "rainbow" +period = "100" +step = "10" + + diff --git a/src/main.rs b/src/main.rs index f5c2d44..335fed8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); diff --git a/src/patterns.rs b/src/patterns.rs index 8392fae..40e9c8d 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -1,5 +1,11 @@ use std::fmt; +pub(crate) enum patterns { + Rainbow(Rainbow), + Fade(Fade), + ColorWipe(ColorWipe), +} + #[derive(Clone, Copy, Debug, Default)] pub struct PixelColor { pub(crate) red: u8, diff --git a/src/runner.rs b/src/runner.rs new file mode 100644 index 0000000..f88ad11 --- /dev/null +++ b/src/runner.rs @@ -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 { + pattern : Box>>, + period: Duration, +} + +struct Runner { + list : Vec>, +} + +impl Runner { + async fn runner_loop(self, tx: Sender>) { + 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; + } + } + } +}