use std::time::Duration; mod patterns; pub use patterns::*; mod types; pub use types::{DashboardPattern, Pattern, RGB}; pub trait UI { fn update_lights(&self, dashboard_lights: DashboardPattern, lights: Pattern); } pub trait Animation { fn tick(&self, frame: Duration) -> (DashboardPattern, Pattern); } pub struct DefaultAnimation {} impl Animation for DefaultAnimation { fn tick(&self, _: Duration) -> (DashboardPattern, Pattern) { (PRIDE_DASHBOARD, PRIDE) } } #[derive(Clone)] pub enum Event { Brake, BrakeRelease, LeftBlinker, LeftBlinkerRelease, NextPattern, PreviousPattern, RightBlinker, RightBlinkerRelease, } #[derive(Clone)] pub enum State { Pattern(u8), Brake, LeftBlinker, RightBlinker, BrakeLeftBlinker, BrakeRightBlinker, } pub struct App { ui: Box, state: State, current_animation: Box, dashboard_lights: DashboardPattern, lights: Pattern, } impl App { pub fn new(ui: Box) -> Self { Self { ui, state: State::Pattern(0), current_animation: Box::new(DefaultAnimation {}), dashboard_lights: OFF_DASHBOARD, lights: OFF, } } pub fn tick(&mut self, frame: Duration) { let (dashboard, lights) = self.current_animation.tick(frame); self.dashboard_lights = dashboard.clone(); self.lights = lights.clone(); self.ui.update_lights(dashboard, lights); } }