renderbug: first implementation of virtual coordinate based rendering
This commit is contained in:
41
src/main.rs
41
src/main.rs
@@ -1,7 +1,7 @@
|
||||
#![feature(trait_upcasting)]
|
||||
#![allow(arithmetic_overflow)]
|
||||
use esp_idf_svc::hal::prelude::Peripherals;
|
||||
use ws2812_esp32_rmt_driver::lib_embedded_graphics::{LedPixelStrip, Ws2812DrawTarget};
|
||||
use ws2812_esp32_rmt_driver::lib_embedded_graphics::{LedPixelStrip, LedPixelShape, LedPixelMatrix, Ws2812DrawTarget};
|
||||
use embedded_graphics::{
|
||||
prelude::*,
|
||||
};
|
||||
@@ -14,8 +14,12 @@ mod lib8;
|
||||
mod render;
|
||||
mod task;
|
||||
mod time;
|
||||
mod geometry;
|
||||
mod embedded_graphics_lib;
|
||||
|
||||
use crate::time::Periodically;
|
||||
use crate::geometry::{Coordinates, VirtualCoordinates};
|
||||
use crate::embedded_graphics_lib::EmbeddedDisplay;
|
||||
|
||||
struct IdleTask {
|
||||
frame: u8,
|
||||
@@ -28,8 +32,8 @@ struct IdleShader {
|
||||
}
|
||||
|
||||
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()
|
||||
fn draw(&self, coords: VirtualCoordinates) -> lib8::RGB8 {
|
||||
Hsv::new_srgb(self.frame.wrapping_add(coords.x()).wrapping_add(coords.y()), 255, 255).into_color_unclamped()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +56,30 @@ impl task::Task for IdleTask {
|
||||
self.surface.set_shader(Box::new(IdleShader { frame: self.frame }));
|
||||
})
|
||||
}
|
||||
|
||||
fn stop(&mut self) {
|
||||
self.surface.clear_shader();
|
||||
}
|
||||
}
|
||||
|
||||
struct PonderjarMatrix {}
|
||||
|
||||
impl LedPixelShape for PonderjarMatrix {
|
||||
fn size() -> Size {
|
||||
Size::new(17, 17)
|
||||
}
|
||||
|
||||
fn pixel_index(point: Point) -> Option<usize> {
|
||||
if (0..Self::size().width as i32).contains(&point.x) && (0..Self::size().height as i32).contains(&point.y) {
|
||||
if point.y % 2 == 0 {
|
||||
Some((point.y as u32 * Self::size().width as u32 + point.x as u32).try_into().unwrap())
|
||||
} else {
|
||||
Some((point.y as u32 * Self::size().width as u32 - point.x as u32).try_into().unwrap())
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -68,14 +96,15 @@ fn main() {
|
||||
let led_pin = peripherals.pins.gpio14;
|
||||
let channel = peripherals.rmt.channel0;
|
||||
|
||||
const NUM_PIXELS : usize = 300;
|
||||
const NUM_PIXELS : usize = 255;
|
||||
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::<LedPixelStrip<NUM_PIXELS>>::new(channel, led_pin).unwrap();
|
||||
let mut display = render::EmbeddedDisplay::new(target, MAX_POWER_MW);
|
||||
let mut target = Ws2812DrawTarget::<PonderjarMatrix>::new(channel, led_pin).unwrap();
|
||||
target.set_brightness(0);
|
||||
let mut display = EmbeddedDisplay::new(target, MAX_POWER_MW);
|
||||
|
||||
log::info!("Creating runner");
|
||||
let mut runner = task::Scheduler::new(vec![
|
||||
|
Reference in New Issue
Block a user