pub struct Wls15RunModeView<'a> {
pub animation: &'a mut u8,
pub color1: &'a mut u8,
pub color1_intensity: &'a mut u8,
pub speed: &'a mut u8,
pub pulse_pattern: &'a mut u8,
pub color2: &'a mut u8,
pub color2_intensity: &'a mut u8,
pub scroll_bounce_style: &'a mut u8,
pub percent_width_color1: &'a mut u8,
pub direction: &'a mut u8,
}
#[macro_export]
macro_rules! wls15_run_mode_view {
($gm:expr, $prefix:ident) => {
$crate::paste::paste! {
$crate::banner::wls15_view::Wls15RunModeView {
animation: &mut $gm.[<$prefix _output_byte_0>],
color1: &mut $gm.[<$prefix _output_byte_1>],
color1_intensity: &mut $gm.[<$prefix _output_byte_2>],
speed: &mut $gm.[<$prefix _output_byte_3>],
pulse_pattern: &mut $gm.[<$prefix _output_byte_4>],
color2: &mut $gm.[<$prefix _output_byte_5>],
color2_intensity: &mut $gm.[<$prefix _output_byte_6>],
scroll_bounce_style: &mut $gm.[<$prefix _output_byte_7>],
percent_width_color1: &mut $gm.[<$prefix _output_byte_8>],
direction: &mut $gm.[<$prefix _output_byte_9>],
}
}
};
}
#[cfg(test)]
mod tests {
use super::*;
use crate::banner::wls15::{Wls15RunMode, Animation, Color, ColorIntensity, Speed};
#[derive(Default)]
pub(crate) struct TestPdo {
pub bytes: [u8; 10],
}
impl TestPdo {
pub(crate) fn view(&mut self) -> Wls15RunModeView<'_> {
let [b0, b1, b2, b3, b4, b5, b6, b7, b8, b9] = &mut self.bytes;
Wls15RunModeView {
animation: b0,
color1: b1,
color1_intensity: b2,
speed: b3,
pulse_pattern: b4,
color2: b5,
color2_intensity: b6,
scroll_bounce_style: b7,
percent_width_color1: b8,
direction: b9,
}
}
}
#[test]
fn apply_maps_fields_to_correct_bytes() {
let mut light = Wls15RunMode::new();
light.alert(Color::Red, ColorIntensity::High, Speed::Medium);
let mut pdo = TestPdo::default();
{
let mut view = pdo.view();
light.apply(&mut view);
}
assert_eq!(pdo.bytes[0], Animation::CenterScroll as u8); assert_eq!(pdo.bytes[1], Color::Red as u8); assert_eq!(pdo.bytes[2], ColorIntensity::High as u8); assert_eq!(pdo.bytes[3], Speed::Medium as u8); assert_eq!(pdo.bytes[6], ColorIntensity::Off as u8); }
#[test]
fn apply_off_zeroes_animation() {
let mut light = Wls15RunMode::new();
light.steady(Color::Blue, ColorIntensity::High);
light.off();
let mut pdo = TestPdo::default();
{
let mut view = pdo.view();
light.apply(&mut view);
}
assert_eq!(pdo.bytes[0], Animation::Off as u8);
}
#[derive(Default)]
struct FakeGm {
light_output_byte_0: u8,
light_output_byte_1: u8,
light_output_byte_2: u8,
light_output_byte_3: u8,
light_output_byte_4: u8,
light_output_byte_5: u8,
light_output_byte_6: u8,
light_output_byte_7: u8,
light_output_byte_8: u8,
light_output_byte_9: u8,
}
#[test]
fn macro_builds_view_and_writes_through() {
let mut gm = FakeGm::default();
let mut light = Wls15RunMode::new();
light.flash(Color::Green, ColorIntensity::High, Speed::Fast);
{
let mut view = crate::wls15_run_mode_view!(gm, light);
light.apply(&mut view);
}
assert_eq!(gm.light_output_byte_0, Animation::Flash as u8);
assert_eq!(gm.light_output_byte_1, Color::Green as u8);
assert_eq!(gm.light_output_byte_2, ColorIntensity::High as u8);
assert_eq!(gm.light_output_byte_3, Speed::Fast as u8);
}
#[test]
fn knight_rider_lands_in_run_mode_bytes() {
let mut light = Wls15RunMode::new();
light.knight_rider(Color::Red);
let mut pdo = TestPdo::default();
{
let mut view = pdo.view();
light.apply(&mut view);
}
assert_eq!(pdo.bytes[0], Animation::Bounce as u8); assert_eq!(pdo.bytes[1], Color::Red as u8); assert_eq!(pdo.bytes[5], Color::WarmWhite as u8); assert_eq!(pdo.bytes[7], crate::banner::wls15::ScrollStyle::Tail as u8); assert_eq!(pdo.bytes[8], 40); }
}