From d28c2a1a4c8a3e26aeee3522541bfd1cb7ef79bc Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Fri, 29 Nov 2024 00:14:06 +0100 Subject: [PATCH] render: merge Framed trait into Display --- src/platform/smart_leds_lib.rs | 61 ++++++++-------------------------- src/render.rs | 7 ++-- 2 files changed, 16 insertions(+), 52 deletions(-) diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index 6086f50..189a55d 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -2,7 +2,7 @@ use smart_leds_trait::SmartLedsWrite; use crate::lib8::Rgb8Blend; use crate::lib8::interpolate::Fract8Ops; -use crate::render::{Framed, Surface, Display, Surfaces}; +use crate::render::{Surface, Display, Surfaces}; use crate::buffers::SurfacePool; use crate::power::{brightness_for_mw, AsMilliwatts}; use crate::geometry::*; @@ -87,6 +87,10 @@ impl Display for SmartLedDisplay where T: FastWrite, S: Surface, P: Pixbuf { + fn start_frame(&mut self) { + self.pixbuf.blank(); + } + fn render_frame(&mut self) { let surfaces = self.surfaces.take().unwrap(); for surface in surfaces.iter() { @@ -104,6 +108,14 @@ P: Pixbuf { } 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 { @@ -116,28 +128,10 @@ trait FastWrite { ::IntoIter: Send; } -impl Framed for SmartLedDisplay where -T: FastWrite, -S: Surface, -P: Pixbuf { - - 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")] pub mod rmt { 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 rgb::Rgb; use ws2812_esp32_rmt_driver::LedPixelEsp32Rmt; @@ -148,35 +142,8 @@ pub mod rmt { 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, 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>(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<'_> { type Color = ::Color; type Error = ::Error; diff --git a/src/render.rs b/src/render.rs index 7b03530..5ebb2fe 100644 --- a/src/render.rs +++ b/src/render.rs @@ -27,13 +27,10 @@ pub trait Surface: Default + Clone + Debug { fn set_opacity(&mut self, opacity: u8); } -pub trait Framed { +pub trait Display: Surfaces { fn start_frame(&mut self) {} - fn end_frame(&mut self) {} -} - -pub trait Display: Surfaces + Framed { fn render_frame(&mut self); + fn end_frame(&mut self) {} } #[derive(Debug)]