render: merge Framed trait into Display
This commit is contained in:
parent
2f9b99c2b0
commit
d28c2a1a4c
@ -2,7 +2,7 @@ use smart_leds_trait::SmartLedsWrite;
|
|||||||
|
|
||||||
use crate::lib8::Rgb8Blend;
|
use crate::lib8::Rgb8Blend;
|
||||||
use crate::lib8::interpolate::Fract8Ops;
|
use crate::lib8::interpolate::Fract8Ops;
|
||||||
use crate::render::{Framed, Surface, Display, Surfaces};
|
use crate::render::{Surface, Display, Surfaces};
|
||||||
use crate::buffers::SurfacePool;
|
use crate::buffers::SurfacePool;
|
||||||
use crate::power::{brightness_for_mw, AsMilliwatts};
|
use crate::power::{brightness_for_mw, AsMilliwatts};
|
||||||
use crate::geometry::*;
|
use crate::geometry::*;
|
||||||
@ -87,6 +87,10 @@ impl<T, S, P> Display<S> for SmartLedDisplay<T, S, P> where
|
|||||||
T: FastWrite,
|
T: FastWrite,
|
||||||
S: Surface,
|
S: Surface,
|
||||||
P: Pixbuf<Pixel = T::Color> {
|
P: Pixbuf<Pixel = T::Color> {
|
||||||
|
fn start_frame(&mut self) {
|
||||||
|
self.pixbuf.blank();
|
||||||
|
}
|
||||||
|
|
||||||
fn render_frame(&mut self) {
|
fn render_frame(&mut self) {
|
||||||
let surfaces = self.surfaces.take().unwrap();
|
let surfaces = self.surfaces.take().unwrap();
|
||||||
for surface in surfaces.iter() {
|
for surface in surfaces.iter() {
|
||||||
@ -104,6 +108,14 @@ P: Pixbuf<Pixel = T::Color> {
|
|||||||
}
|
}
|
||||||
self.surfaces = Some(surfaces);
|
self.surfaces = Some(surfaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn end_frame(&mut self) {
|
||||||
|
let b = brightness_for_mw(self.pixbuf.as_milliwatts(), 255, self.max_mw);
|
||||||
|
if let Err(_) = self.target.fast_write(self.pixbuf.iter_with_brightness(b)) {
|
||||||
|
panic!("Could not write frame!");
|
||||||
|
}
|
||||||
|
self.frame += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait FastWrite {
|
trait FastWrite {
|
||||||
@ -116,28 +128,10 @@ trait FastWrite {
|
|||||||
<T as IntoIterator>::IntoIter: Send;
|
<T as IntoIterator>::IntoIter: Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, S, P> Framed for SmartLedDisplay<T, S, P> where
|
|
||||||
T: FastWrite,
|
|
||||||
S: Surface,
|
|
||||||
P: Pixbuf<Pixel = T::Color> {
|
|
||||||
|
|
||||||
fn start_frame(&mut self) {
|
|
||||||
self.pixbuf.blank();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn end_frame(&mut self) {
|
|
||||||
let b = brightness_for_mw(self.pixbuf.as_milliwatts(), 255, self.max_mw);
|
|
||||||
if let Err(_) = self.target.fast_write(self.pixbuf.iter_with_brightness(b)) {
|
|
||||||
panic!("Could not write frame!");
|
|
||||||
}
|
|
||||||
self.frame += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature="rmt")]
|
#[cfg(feature="rmt")]
|
||||||
pub mod rmt {
|
pub mod rmt {
|
||||||
use esp_idf_svc::hal::prelude::Peripherals;
|
use esp_idf_svc::hal::prelude::Peripherals;
|
||||||
use ws2812_esp32_rmt_driver::driver::color::{LedPixelColor, LedPixelColorGrb24};
|
use ws2812_esp32_rmt_driver::driver::color::LedPixelColorGrb24;
|
||||||
use smart_leds::SmartLedsWrite;
|
use smart_leds::SmartLedsWrite;
|
||||||
use rgb::Rgb;
|
use rgb::Rgb;
|
||||||
use ws2812_esp32_rmt_driver::LedPixelEsp32Rmt;
|
use ws2812_esp32_rmt_driver::LedPixelEsp32Rmt;
|
||||||
@ -148,35 +142,8 @@ pub mod rmt {
|
|||||||
|
|
||||||
use super::{Pixbuf, FastWrite, SmartLedDisplay};
|
use super::{Pixbuf, FastWrite, SmartLedDisplay};
|
||||||
|
|
||||||
use crate::lib8::Rgb8Blend;
|
|
||||||
use crate::lib8::interpolate::{Fract8, Fract8Ops};
|
|
||||||
use crate::power::AsMilliwatts;
|
|
||||||
|
|
||||||
pub type FastWs2812Esp32Rmt<'a> = LedPixelEsp32Rmt<'a, Rgb<u8>, LedPixelColorGrb24>;
|
pub type FastWs2812Esp32Rmt<'a> = LedPixelEsp32Rmt<'a, Rgb<u8>, LedPixelColorGrb24>;
|
||||||
|
|
||||||
impl Fract8Ops for LedPixelColorGrb24 {
|
|
||||||
fn blend8(self, _other: Self, _scale: Fract8) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn scale8(self, _scale: Fract8) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsMilliwatts for LedPixelColorGrb24 {
|
|
||||||
fn as_milliwatts(&self) -> u32 {
|
|
||||||
Rgb::new(self.r(), self.g(), self.b()).as_milliwatts()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Rgb8Blend for LedPixelColorGrb24 {
|
|
||||||
fn saturating_add<T: Into<Self>>(self, b: T) -> Self where Self: Sized {
|
|
||||||
let s = b.into();
|
|
||||||
LedPixelColorGrb24::new_with_rgb(s.r(), s.g(), s.b())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FastWrite for FastWs2812Esp32Rmt<'_> {
|
impl FastWrite for FastWs2812Esp32Rmt<'_> {
|
||||||
type Color = <Self as SmartLedsWrite>::Color;
|
type Color = <Self as SmartLedsWrite>::Color;
|
||||||
type Error = <Self as SmartLedsWrite>::Error;
|
type Error = <Self as SmartLedsWrite>::Error;
|
||||||
|
@ -27,13 +27,10 @@ pub trait Surface: Default + Clone + Debug {
|
|||||||
fn set_opacity(&mut self, opacity: u8);
|
fn set_opacity(&mut self, opacity: u8);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Framed {
|
pub trait Display<T: Surface>: Surfaces<T> {
|
||||||
fn start_frame(&mut self) {}
|
fn start_frame(&mut self) {}
|
||||||
fn end_frame(&mut self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait Display<T: Surface>: Surfaces<T> + Framed {
|
|
||||||
fn render_frame(&mut self);
|
fn render_frame(&mut self);
|
||||||
|
fn end_frame(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user