2024-10-20 17:23:13 +02:00
|
|
|
use palette::Hsv;
|
2024-10-30 20:48:00 +01:00
|
|
|
|
|
|
|
use rgb::RGB8;
|
2024-10-20 17:22:27 +02:00
|
|
|
|
2024-10-20 17:23:13 +02:00
|
|
|
mod power;
|
|
|
|
mod lib8;
|
2024-10-27 11:19:26 +01:00
|
|
|
mod render;
|
|
|
|
mod task;
|
|
|
|
mod time;
|
2024-10-27 15:14:28 +01:00
|
|
|
mod geometry;
|
2024-10-30 19:52:02 +01:00
|
|
|
mod platform;
|
2024-10-30 21:55:15 +01:00
|
|
|
mod animations;
|
2024-10-30 19:52:02 +01:00
|
|
|
|
2024-10-30 20:48:00 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-10-30 19:52:02 +01:00
|
|
|
#[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;
|
|
|
|
|
|
|
|
#[cfg(feature="spi")]
|
|
|
|
#[cfg(feature="smart-leds")]
|
2024-10-30 20:54:49 +01:00
|
|
|
use crate::platform::smart_leds_lib::spi::SPIDisplay;
|
2024-10-27 11:19:26 +01:00
|
|
|
|
2024-10-30 19:59:19 +01:00
|
|
|
#[cfg(feature="threads")]
|
|
|
|
use crate::render::SharedSurface;
|
|
|
|
|
|
|
|
#[cfg(not(feature="threads"))]
|
|
|
|
use crate::render::SimpleSurface;
|
2024-10-29 01:27:20 +01:00
|
|
|
|
2024-10-28 22:22:03 +01:00
|
|
|
struct IdleTask<T: Surface> {
|
2024-10-27 11:19:26 +01:00
|
|
|
frame: u8,
|
2024-10-28 22:22:03 +01:00
|
|
|
surface: T,
|
2024-10-27 11:19:26 +01:00
|
|
|
updater: Periodically
|
|
|
|
}
|
2024-10-20 17:22:27 +02:00
|
|
|
|
2024-10-27 11:19:26 +01:00
|
|
|
struct IdleShader {
|
|
|
|
frame: u8
|
|
|
|
}
|
|
|
|
|
2024-10-29 11:51:25 +01:00
|
|
|
impl Shader for IdleShader {
|
2024-10-30 20:48:00 +01:00
|
|
|
fn draw(&self, coords: VirtualCoordinates) -> RGB8 {
|
|
|
|
Hsv::new_srgb(self.frame.wrapping_add(coords.x()).wrapping_add(coords.y()), 255, 255).into_rgb8()
|
2024-10-27 11:19:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-28 22:22:03 +01:00
|
|
|
impl<T: Surface> IdleTask<T> {
|
|
|
|
fn new(surface: T) -> Self {
|
2024-10-27 11:19:26 +01:00
|
|
|
IdleTask {
|
|
|
|
frame: 0,
|
2024-10-28 22:22:03 +01:00
|
|
|
surface: surface,
|
2024-10-27 11:19:26 +01:00
|
|
|
updater: Periodically::new_every_n_ms(16)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-29 11:51:25 +01:00
|
|
|
impl<T: Surface> Task for IdleTask<T> {
|
2024-10-27 11:19:26 +01:00
|
|
|
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 }));
|
|
|
|
})
|
|
|
|
}
|
2024-10-27 15:14:28 +01:00
|
|
|
|
|
|
|
fn stop(&mut self) {
|
|
|
|
self.surface.clear_shader();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-20 17:22:27 +02:00
|
|
|
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();
|
|
|
|
|
2024-10-27 11:19:26 +01:00
|
|
|
log::info!("Setting up display");
|
2024-10-30 19:52:02 +01:00
|
|
|
|
2024-10-30 19:59:19 +01:00
|
|
|
#[cfg(feature="threads")]
|
|
|
|
type SurfaceType = SharedSurface;
|
|
|
|
#[cfg(not(feature="threads"))]
|
|
|
|
type SurfaceType = SimpleSurface;
|
|
|
|
|
2024-10-30 19:52:02 +01:00
|
|
|
#[cfg(feature="spi")]
|
2024-10-30 19:59:19 +01:00
|
|
|
let mut display = SPIDisplay::new_display::<SurfaceType>();
|
2024-10-30 19:52:02 +01:00
|
|
|
|
|
|
|
#[cfg(feature="embedded-graphics")]
|
2024-10-30 19:59:19 +01:00
|
|
|
let mut display = PonderjarTarget::new_display::<SurfaceType>();
|
2024-10-30 19:52:02 +01:00
|
|
|
|
|
|
|
#[cfg(feature="rmt")]
|
2024-10-30 19:59:19 +01:00
|
|
|
let mut display = Ws2812Esp32Rmt::new_display::<SurfaceType>();
|
2024-10-27 11:19:26 +01:00
|
|
|
|
|
|
|
log::info!("Creating runner");
|
|
|
|
let mut runner = task::Scheduler::new(vec![
|
2024-10-30 21:55:15 +01:00
|
|
|
Box::new(animations::IdleTask::new(display.new_surface().unwrap())),
|
|
|
|
Box::new(animations::TestPattern::new(display.new_surface().unwrap())),
|
2024-10-27 11:19:26 +01:00
|
|
|
Box::new(display),
|
|
|
|
]);
|
|
|
|
|
|
|
|
log::info!("Ready to rock and roll");
|
2024-10-20 17:22:27 +02:00
|
|
|
loop {
|
2024-10-27 11:19:26 +01:00
|
|
|
runner.tick();
|
2024-10-20 17:22:27 +02:00
|
|
|
}
|
|
|
|
}
|