#![feature(trait_upcasting)] #![allow(arithmetic_overflow)] use esp_idf_svc::hal::prelude::Peripherals; use ws2812_esp32_rmt_driver::lib_embedded_graphics::{LedPixelStrip, Ws2812DrawTarget}; use embedded_graphics::{ prelude::*, }; use palette::Hsv; use palette::convert::IntoColorUnclamped; use std::thread; mod power; mod lib8; mod render; mod task; mod time; use crate::time::Periodically; struct IdleTask { frame: u8, surface: render::Surface, updater: Periodically } struct IdleShader { frame: u8 } impl render::Shader for IdleShader { fn draw(&self, coords: Point) -> lib8::RGB8 { Hsv::new_srgb(self.frame.wrapping_add(coords.x as u8), 255, 255).into_color_unclamped() } } impl IdleTask { fn new(render: &mut dyn render::Display) -> Self { IdleTask { frame: 0, surface: render.new_surface(), updater: Periodically::new_every_n_ms(16) } } } impl task::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 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 esp_idf_svc::sys::link_patches(); // 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 NUM_PIXELS : usize = 300; 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 = Ws2812DrawTarget::>::new(channel, led_pin).unwrap(); let mut display = render::EmbeddedDisplay::new(target, MAX_POWER_MW); log::info!("Creating runner"); let mut runner = task::Scheduler::new(vec![ Box::new(IdleTask::new(&mut display)), Box::new(display), ]); log::info!("Ready to rock and roll"); loop { runner.tick(); } }