From 10f0eaa75e8af0a219be74b3853ea93687274a53 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sat, 16 Nov 2024 12:09:38 +0100 Subject: [PATCH] platform: smart_leds: move pixbuf size into type args --- src/platform/smart_leds_lib.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index 311b0a6..5760ba4 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -12,14 +12,14 @@ use std::io; use rgb::Rgb; -pub struct SmartLedDisplay>, S: Surface> { +pub struct SmartLedDisplay>, S: Surface, const PIXEL_NUM: usize> { surfaces : SurfacePool, target: T, - pixbuf: [T::Color; 255], + pixbuf: [T::Color; PIXEL_NUM], max_mw: u32 } -impl>, S: Surface> Debug for SmartLedDisplay { +impl>, S: Surface, const PIXEL_NUM: usize> Debug for SmartLedDisplay { 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>, S: Surface> Debug for SmartLedDisplay>, S: Surface> SmartLedDisplay { +impl>, S: Surface, const PIXEL_NUM: usize> SmartLedDisplay { 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>, S: Surface> AsMilliwatts for SmartLedDisplay { +impl>, S: Surface, const PIXEL_NUM: usize> AsMilliwatts for SmartLedDisplay { fn as_milliwatts(&self) -> u32 { self.pixbuf.as_milliwatts() } } -impl Surfaces for SmartLedDisplay +impl Surfaces for SmartLedDisplay where T: SmartLedsWrite>, S: Surface { @@ -54,9 +54,10 @@ S: Surface { } } -impl>, S: Surface> Display for SmartLedDisplay { +impl>, S: Surface, const PIXEL_NUM: usize> Display for SmartLedDisplay { + 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::::new(target, MAX_POWER_MW); } } }