First stab at a december display

This commit is contained in:
Tangent Wantwight 2019-11-23 18:55:21 -05:00
parent d53b000bb3
commit 5d8dd68d47
4 changed files with 71 additions and 1 deletions

View file

@ -13,6 +13,8 @@ debug = true
replace-default = [] replace-default = []
december-2019 = ["replace-default"]
[dependencies] [dependencies]
house = { path = "../house" } house = { path = "../house" }
itsybitsy_m0 = "0.5" itsybitsy_m0 = "0.5"

View file

@ -0,0 +1,63 @@
use super::delay;
use house::Harrogate;
use lights::rgb::{blend, blend_steps, linear_gradient, Rgb};
use lights::{HardwareRgb, Lights};
const OFF: Rgb = Rgb(0, 0, 0);
const CYAN: Rgb = Rgb(0, 128, 200);
const BLUE: Rgb = Rgb(0, 0, 200);
const PURPLE: Rgb = Rgb(128, 0, 128);
const WHITE: Rgb = Rgb(255, 255, 255);
const PULSE_LEN: usize = 50;
const SEGMENT_LEN: usize = 20;
const ZOOM: usize = 10;
const ZOOM_SEGMENT_LEN: usize = SEGMENT_LEN * ZOOM + ZOOM;
const HALF_PORCH: usize = 75;
const FULL_PORCH: usize = 150;
#[allow(dead_code)]
#[inline(always)]
pub fn run(lights: &mut impl Lights<Pixel = HardwareRgb>) -> ! {
let mut color_pulse = linear_gradient(CYAN, BLUE, PULSE_LEN)
.chain(linear_gradient(BLUE, PURPLE, PULSE_LEN))
.chain(linear_gradient(PURPLE, CYAN, PULSE_LEN))
.cycle();
let mut t = 0;
loop {
// advance "time" for pattern
t += 1;
if t > ZOOM_SEGMENT_LEN {
t = 0;
}
let color = color_pulse.next().unwrap_or(Rgb(255, 0, 0));
let half_pattern_func = |i| {
let x = (i * ZOOM) + t;
let x = x % ZOOM_SEGMENT_LEN;
match x {
x if x > SEGMENT_LEN * ZOOM => {
blend_steps(WHITE, OFF, ZOOM, x - SEGMENT_LEN * ZOOM)
}
x => blend_steps(OFF, WHITE, SEGMENT_LEN * ZOOM, x),
}
};
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),
porch_front: (0..FULL_PORCH)
.map(pattern_func)
.map(|b| blend(color, WHITE, b)),
}
.render_to(lights);
delay(48_000_000);
}
}

View file

@ -12,7 +12,8 @@ const ON: Rgb = Rgb(255, 255, 255);
* 85 OFF + 65 door = 150 dots * 85 OFF + 65 door = 150 dots
*/ */
#[inline(always)] #[allow(dead_code)]
#[inline(always)]
pub fn run(lights: &mut impl Lights<Pixel = HardwareRgb>) -> ! { pub fn run(lights: &mut impl Lights<Pixel = HardwareRgb>) -> ! {
let door_highlight = linear_gradient(OFF, ON, 20) let door_highlight = linear_gradient(OFF, ON, 20)
.chain(repeat(ON).take(25)) .chain(repeat(ON).take(25))

View file

@ -5,12 +5,16 @@ use lights_hal::{boot, entry};
pub use lights_hal::delay; pub use lights_hal::delay;
mod december_2019;
mod door_light; mod door_light;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let mut lights = boot(); let mut lights = boot();
#[cfg(feature = "december-2019")]
december_2019::run(&mut lights);
#[cfg(not(feature = "replace-default"))] #[cfg(not(feature = "replace-default"))]
door_light::run(&mut lights); door_light::run(&mut lights);
} }