platform: smart_leds: move pixbuf size into type args

This commit is contained in:
Victoria Fischer 2024-11-16 12:09:38 +01:00
parent d6e6f1c554
commit 10f0eaa75e

View File

@ -12,14 +12,14 @@ use std::io;
use rgb::Rgb;
pub struct SmartLedDisplay<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> {
pub struct SmartLedDisplay<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface, const PIXEL_NUM: usize> {
surfaces : SurfacePool<S>,
target: T,
pixbuf: [T::Color; 255],
pixbuf: [T::Color; PIXEL_NUM],
max_mw: u32
}
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Debug for SmartLedDisplay<T, S> {
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface, const PIXEL_NUM: usize> Debug for SmartLedDisplay<T, S, PIXEL_NUM> {
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
f.debug_struct("SmartLedDisplay")
.field("total_mw", &self.pixbuf.as_milliwatts())
@ -28,24 +28,24 @@ impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Debug for SmartLedDisplay<T
}
}
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> SmartLedDisplay<T, S> {
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface, const PIXEL_NUM: usize> SmartLedDisplay<T, S, PIXEL_NUM> {
pub fn new(target: T, max_mw: u32) -> Self {
SmartLedDisplay {
surfaces: SurfacePool::new(),
pixbuf: [Rgb::new(0, 0, 0); PIXEL_NUM],
target: target,
max_mw: max_mw,
pixbuf: [Rgb::new(0, 0, 0); 255]
}
}
}
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> AsMilliwatts for SmartLedDisplay<T, S> {
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface, const PIXEL_NUM: usize> AsMilliwatts for SmartLedDisplay<T, S, PIXEL_NUM> {
fn as_milliwatts(&self) -> u32 {
self.pixbuf.as_milliwatts()
}
}
impl<T, S> Surfaces<S> for SmartLedDisplay<T, S>
impl<T, S, const PIXEL_NUM: usize> Surfaces<S> for SmartLedDisplay<T, S, PIXEL_NUM>
where
T: SmartLedsWrite<Color = Rgb<u8>>,
S: Surface {
@ -54,9 +54,10 @@ S: Surface {
}
}
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Display<S> for SmartLedDisplay<T, S> {
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface, const PIXEL_NUM: usize> Display<S> for SmartLedDisplay<T, S, PIXEL_NUM> {
fn start_frame(&mut self) {
self.pixbuf.fill(RGB8::new(0, 0, 0));
self.pixbuf.fill(Rgb::new(0, 0, 0));
}
fn end_frame(&mut self) {
@ -98,7 +99,7 @@ pub mod rmt {
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
let target = Self::new(channel, led_pin).unwrap();
return SmartLedDisplay::new(target, MAX_POWER_MW);
return SmartLedDisplay::<Ws2812Esp32Rmt, S, 300>::new(target, MAX_POWER_MW);
}
}
}