2021-08-06 23:27:41 -04:00
|
|
|
use crate::color::Rgb;
|
2021-08-09 23:13:38 -04:00
|
|
|
use serde::Deserialize;
|
2021-07-31 14:29:21 -04:00
|
|
|
|
2021-08-01 19:38:17 -04:00
|
|
|
pub mod collide;
|
|
|
|
pub mod fade;
|
|
|
|
pub mod moving_pixel;
|
|
|
|
pub mod moving_rainbow;
|
2021-08-09 21:28:42 -04:00
|
|
|
pub mod orb;
|
2021-08-01 19:38:17 -04:00
|
|
|
pub mod solid;
|
|
|
|
pub use collide::Collide;
|
|
|
|
pub use fade::Fade;
|
|
|
|
pub use moving_pixel::MovingPixel;
|
|
|
|
pub use moving_rainbow::MovingRainbow;
|
2021-08-09 21:28:42 -04:00
|
|
|
pub use orb::Orb;
|
2021-08-01 19:38:17 -04:00
|
|
|
pub use solid::Solid;
|
2021-07-31 14:29:21 -04:00
|
|
|
|
2021-08-09 23:13:38 -04:00
|
|
|
#[derive(Deserialize, Debug)]
|
|
|
|
enum PatternParameters {
|
|
|
|
Collide(Rgb, Rgb, Rgb),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum PatternParameters {
|
2021-08-09 23:26:10 -04:00
|
|
|
Collide(Rgb, Rgb, Rgb),
|
2021-08-09 23:13:38 -04:00
|
|
|
Fade(Rgb),
|
|
|
|
MovingPixel(Rgb),
|
|
|
|
MovingRainbow(u8, bool),
|
2021-08-09 23:26:10 -04:00
|
|
|
Orb(Rgb, u8, u8),
|
2021-08-09 23:13:38 -04:00
|
|
|
Solid(Rgb),
|
|
|
|
}
|
|
|
|
|
2021-08-01 19:38:17 -04:00
|
|
|
pub trait Pattern: std::fmt::Debug {
|
2021-08-06 20:32:16 -04:00
|
|
|
fn init(&mut self, num_lights: u16) -> Result<(), ()>;
|
|
|
|
fn step(&mut self) -> Result<bool, ()>;
|
2021-08-06 23:27:41 -04:00
|
|
|
fn get_strip(&self) -> &[Rgb];
|
|
|
|
// fn get_strip_mut(&mut self) -> &[Rgb];
|
2021-07-31 14:29:21 -04:00
|
|
|
}
|
|
|
|
|
2021-08-01 19:38:17 -04:00
|
|
|
// #[cfg(test)]
|
|
|
|
// mod tests {
|
|
|
|
// use super::*;
|
|
|
|
// const NUM_LIGHTS: u16 = 10;
|
2021-08-06 23:27:41 -04:00
|
|
|
// fn test_strip() -> Vec<Rgb> {
|
2021-08-01 19:38:17 -04:00
|
|
|
// vec![color::BLACK; NUM_LIGHTS.into()]
|
|
|
|
// }
|
|
|
|
// #[test]
|
|
|
|
// fn moving_pixel() {
|
2021-08-06 23:27:41 -04:00
|
|
|
// let color = Rgb(123, 152, 89);
|
2021-08-01 19:38:17 -04:00
|
|
|
// let mut pat = MovingPixel::new(color.clone());
|
|
|
|
// let mut strip = test_strip();
|
|
|
|
|
|
|
|
// assert!(pat.init(&mut strip, NUM_LIGHTS).is_ok());
|
|
|
|
// // One is my color
|
|
|
|
// assert_eq!(strip.iter().filter(|c| **c == color).count(), 1);
|
|
|
|
// // The rest are off
|
|
|
|
// assert_eq!(
|
|
|
|
// strip.iter().filter(|c| **c == color::BLACK).count(),
|
|
|
|
// (NUM_LIGHTS - 1).into()
|
|
|
|
// );
|
|
|
|
// pat.step(&mut strip);
|
|
|
|
// // One is my color
|
|
|
|
// assert_eq!(strip.iter().filter(|c| **c == color).count(), 1);
|
|
|
|
// // The rest are off
|
|
|
|
// assert_eq!(
|
|
|
|
// strip.iter().filter(|c| **c == color::BLACK).count(),
|
|
|
|
// (NUM_LIGHTS - 1).into()
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// #[test]
|
|
|
|
// fn solid() {}
|
|
|
|
// #[test]
|
|
|
|
// fn moving_rainbow() {}
|
|
|
|
// #[test]
|
|
|
|
// fn fade() {}
|
|
|
|
// #[test]
|
|
|
|
// fn collide() {}
|
|
|
|
// }
|