From f1ae01eec0cc396ab6d68a3c84688ca1a9c9afdd Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Tue, 24 Dec 2019 15:44:08 -0500 Subject: [PATCH] Add red & green pattern --- harrogate/Cargo.toml | 1 + harrogate/src/december_24_2019.rs | 68 +++++++++++++++++++++++++++++++ harrogate/src/main.rs | 4 ++ 3 files changed, 73 insertions(+) create mode 100644 harrogate/src/december_24_2019.rs diff --git a/harrogate/Cargo.toml b/harrogate/Cargo.toml index 998c9b7..2fffc55 100644 --- a/harrogate/Cargo.toml +++ b/harrogate/Cargo.toml @@ -15,6 +15,7 @@ replace-default = [] december-01-2019 = ["replace-default"] december-21-2019 = ["replace-default"] +december-24-2019 = ["replace-default"] [dependencies] house = { path = "../house" } diff --git a/harrogate/src/december_24_2019.rs b/harrogate/src/december_24_2019.rs new file mode 100644 index 0000000..f6a3de9 --- /dev/null +++ b/harrogate/src/december_24_2019.rs @@ -0,0 +1,68 @@ +//! ramp gradient of red and green +use super::delay; +use house::Harrogate; +use lights::rgb::{blend_steps, Rgb}; +use lights::{HardwareRgb, Lights}; + +const OFF: Rgb = Rgb(0, 0, 0); +const GREEN: Rgb = Rgb(0, 200, 0); +const RED: Rgb = Rgb(200, 0, 0); + +const SEGMENT_LEN: usize = 35; +const ZOOM: usize = 10; +const ZOOM_SEGMENT_LEN: usize = SEGMENT_LEN * ZOOM; +const OVERLAP: usize = 60; +const RAMP_LEN: usize = ZOOM_SEGMENT_LEN / 4 + OVERLAP; + +const HALF_PORCH: usize = 75; +const FULL_PORCH: usize = 150; + +#[allow(dead_code)] +#[inline(always)] +pub fn run(lights: &mut impl Lights) -> ! { + let mut t = 0; + + loop { + // advance "time" for pattern + t += 1; + if t > ZOOM_SEGMENT_LEN { + t = 0; + } + + let ramp_func = |x, center, color| { + if x < center { + if x < (center - RAMP_LEN) { + OFF + } else { + blend_steps(OFF, color, RAMP_LEN, x - (center - RAMP_LEN)) + } + } else { + if x > (center + RAMP_LEN) { + OFF + } else { + blend_steps(color, OFF, RAMP_LEN, x - center) + } + } + }; + + let half_pattern_func = |i| { + let x = (i * ZOOM) + t; + let x = x % ZOOM_SEGMENT_LEN; + ramp_func(x, 0, RED) + + ramp_func(x, ZOOM_SEGMENT_LEN, RED) + + ramp_func(x, ZOOM_SEGMENT_LEN / 2, GREEN) + }; + let pattern_func = |i| match i { + i if i < HALF_PORCH => half_pattern_func(i), + i => half_pattern_func(FULL_PORCH - i), + }; + + Harrogate { + porch_back: (0..FULL_PORCH).map(|_| pattern_func(HALF_PORCH)), + porch_front: (0..FULL_PORCH).map(pattern_func), + } + .render_to(lights); + + delay(300_000); + } +} diff --git a/harrogate/src/main.rs b/harrogate/src/main.rs index 967ea15..0e7d901 100644 --- a/harrogate/src/main.rs +++ b/harrogate/src/main.rs @@ -7,6 +7,7 @@ pub use lights_hal::delay; mod december_01_2019; mod december_21_2019; +mod december_24_2019; mod door_light; #[entry] @@ -19,6 +20,9 @@ fn main() -> ! { #[cfg(feature = "december-21-2019")] december_21_2019::run(&mut lights); + #[cfg(feature = "december-24-2019")] + december_24_2019::run(&mut lights); + #[cfg(not(feature = "replace-default"))] door_light::run(&mut lights); }