diff --git a/src/main.rs b/src/main.rs index 656567b..ff86ab9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,8 @@ mod embedded_graphics_lib; use crate::time::Periodically; use crate::geometry::{Coordinates, VirtualCoordinates}; use crate::embedded_graphics_lib::EmbeddedDisplay; -use crate::render::{Surfaces, Surface, SimpleSurface}; +use crate::render::{Surfaces, Surface, SimpleSurface, Display}; +use crate::task::Task; struct IdleTask { frame: u8, @@ -84,6 +85,25 @@ impl LedPixelShape for PonderjarMatrix { type PonderjarTarget<'a> = Ws2812DrawTarget<'a, PonderjarMatrix>; +trait DisplayInit { + fn new_display() -> impl Display + Task; +} + +impl DisplayInit for Ws2812DrawTarget<'_, Shape> { + fn new_display() -> impl Display + Task { + let peripherals = Peripherals::take().unwrap(); + let led_pin = peripherals.pins.gpio14; + let channel = peripherals.rmt.channel0; + + const POWER_VOLTS : u32 = 5; + const POWER_MA : u32 = 500; + const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA; + + let target = Self::new(channel, led_pin).unwrap(); + return EmbeddedDisplay::::new(target, MAX_POWER_MW); + } +} + fn main() { // It is necessary to call this function once. Otherwise some patches to the runtime // implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71 @@ -92,19 +112,8 @@ fn main() { // Bind the log crate to the ESP Logging facilities esp_idf_svc::log::EspLogger::initialize_default(); - log::info!("Hello, world!"); - - let peripherals = Peripherals::take().unwrap(); - let led_pin = peripherals.pins.gpio14; - let channel = peripherals.rmt.channel0; - - const POWER_VOLTS : u32 = 5; - const POWER_MA : u32 = 500; - const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA; - log::info!("Setting up display"); - let target = PonderjarTarget::new(channel, led_pin).unwrap(); - let mut display = EmbeddedDisplay::::new(target, MAX_POWER_MW); + let mut display = PonderjarTarget::new_display::(); log::info!("Creating runner"); let mut runner = task::Scheduler::new(vec![