diff --git a/src/main.rs b/src/main.rs index 282e2d7..176fc87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,3 @@ -use palette::Hsv; - -use rgb::RGB8; - mod power; mod lib8; mod render; @@ -11,72 +7,26 @@ mod geometry; mod platform; mod animations; - -use crate::time::Periodically; -use crate::geometry::{Coordinates, VirtualCoordinates}; -use crate::render::{Shader, Surfaces, Surface}; -use crate::task::Task; use crate::platform::DisplayInit; -use crate::lib8::IntoRgb8; +use crate::render::Surfaces; -#[cfg(feature="rmt")] #[cfg(feature="embedded-graphics")] -use ws2812_esp32_rmt_driver::lib_embedded_graphics::PonderjarTarget; - #[cfg(feature="rmt")] -#[cfg(feature="smart-leds")] -use ws2812_esp32_rmt_driver::lib_smart_leds::Ws2812Esp32Rmt; +use crate::platform::embedded_graphics_lib::PonderjarTarget as DisplayType; -#[cfg(feature="spi")] #[cfg(feature="smart-leds")] -use crate::platform::smart_leds_lib::spi::SPIDisplay; +#[cfg(feature="rmt")] +use ws2812_esp32_rmt_driver::lib_smart_leds::Ws2812Esp32Rmt as DisplayType; + +#[cfg(feature="smart-leds")] +#[cfg(feature="spi")] +use crate::platform::smart_leds_lib::spi::SPIDisplay as DisplayType; #[cfg(feature="threads")] -use crate::render::SharedSurface; +use crate::render::SharedSurface as SurfaceType; #[cfg(not(feature="threads"))] -use crate::render::SimpleSurface; - -struct IdleTask { - frame: u8, - surface: T, - updater: Periodically -} - -struct IdleShader { - frame: u8 -} - -impl Shader for IdleShader { - fn draw(&self, coords: VirtualCoordinates) -> RGB8 { - Hsv::new_srgb(self.frame.wrapping_add(coords.x()).wrapping_add(coords.y()), 255, 255).into_rgb8() - } -} - -impl IdleTask { - fn new(surface: T) -> Self { - IdleTask { - frame: 0, - surface: surface, - updater: Periodically::new_every_n_ms(16) - } - } -} - -impl Task for IdleTask { - fn name(&self) -> &'static str { "Idle" } - - fn tick(&mut self) { - self.updater.run(|| { - self.frame = self.frame.wrapping_add(1); - self.surface.set_shader(Box::new(IdleShader { frame: self.frame })); - }) - } - - fn stop(&mut self) { - self.surface.clear_shader(); - } -} +use crate::render::SimpleSurface as SurfaceType; fn main() { // It is necessary to call this function once. Otherwise some patches to the runtime @@ -88,19 +38,7 @@ fn main() { log::info!("Setting up display"); - #[cfg(feature="threads")] - type SurfaceType = SharedSurface; - #[cfg(not(feature="threads"))] - type SurfaceType = SimpleSurface; - - #[cfg(feature="spi")] - let mut display = SPIDisplay::new_display::(); - - #[cfg(feature="embedded-graphics")] - let mut display = PonderjarTarget::new_display::(); - - #[cfg(feature="rmt")] - let mut display = Ws2812Esp32Rmt::new_display::(); + let mut display = DisplayType::new_display::(); log::info!("Creating runner"); let mut runner = task::Scheduler::new(vec![ diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index 905d48b..2e70197 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -123,6 +123,7 @@ pub mod spi { use crate::render::{Display, Surface}; use crate::task::Task; use crate::platform::smart_leds_lib::SmartLedDisplay; + use crate::DisplayInit; use esp_idf_svc::hal::{ prelude::*,