renderbug/src/main.rs

117 lines
2.9 KiB
Rust
Raw Normal View History

use palette::Hsv;
use rgb::RGB8;
2024-10-20 17:22:27 +02:00
mod power;
mod lib8;
mod render;
mod task;
mod time;
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;
#[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")]
use crate::platform::smart_leds_lib::spi::SPIDisplay;
#[cfg(feature="threads")]
use crate::render::SharedSurface;
#[cfg(not(feature="threads"))]
use crate::render::SimpleSurface;
struct IdleTask<T: Surface> {
frame: u8,
surface: T,
updater: Periodically
}
2024-10-20 17:22:27 +02:00
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<T: Surface> IdleTask<T> {
fn new(surface: T) -> Self {
IdleTask {
frame: 0,
surface: surface,
updater: Periodically::new_every_n_ms(16)
}
}
}
impl<T: Surface> Task for IdleTask<T> {
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();
}
}
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();
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::<SurfaceType>();
#[cfg(feature="embedded-graphics")]
let mut display = PonderjarTarget::new_display::<SurfaceType>();
#[cfg(feature="rmt")]
let mut display = Ws2812Esp32Rmt::new_display::<SurfaceType>();
log::info!("Creating runner");
let mut runner = task::Scheduler::new(vec![
Box::new(animations::IdleTask::new(display.new_surface().unwrap())),
Box::new(animations::TestPattern::new(display.new_surface().unwrap())),
Box::new(display),
]);
log::info!("Ready to rock and roll");
2024-10-20 17:22:27 +02:00
loop {
runner.tick();
2024-10-20 17:22:27 +02:00
}
}