From 24f0a336e634f87826e38332bea0d245b92e545e Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Sat, 16 Nov 2024 12:06:00 +0100 Subject: [PATCH] platform: smart_leds: no need to keep total_mw around when we can calculate on the fly --- src/platform/smart_leds_lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/platform/smart_leds_lib.rs b/src/platform/smart_leds_lib.rs index 51573a6..08472dc 100644 --- a/src/platform/smart_leds_lib.rs +++ b/src/platform/smart_leds_lib.rs @@ -16,14 +16,13 @@ pub struct SmartLedDisplay>, S: Surface> { surfaces : SurfacePool, target: T, pixbuf: [T::Color; 255], - total_mw: u32, max_mw: u32 } impl>, S: Surface> Debug for SmartLedDisplay { fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { f.debug_struct("SmartLedDisplay") - .field("total_mw", &self.total_mw) + .field("total_mw", &self.pixbuf.as_milliwatts()) .field("surfaces", &self.surfaces) .finish() } @@ -35,7 +34,6 @@ impl>, S: Surface> SmartLedDisplay { surfaces: SurfacePool::new(), target: target, max_mw: max_mw, - total_mw: 0, pixbuf: [Rgb::new(0, 0, 0); 255] } } @@ -43,7 +41,7 @@ impl>, S: Surface> SmartLedDisplay { impl>, S: Surface> AsMilliwatts for SmartLedDisplay { fn as_milliwatts(&self) -> u32 { - self.total_mw + self.pixbuf.as_milliwatts() } } @@ -58,11 +56,10 @@ S: Surface { impl>, S: Surface> Display for SmartLedDisplay { fn start_frame(&mut self) { - self.total_mw = 0; } fn end_frame(&mut self) { - let b = brightness_for_mw(self.total_mw, 255, self.max_mw); + let b = brightness_for_mw(self.pixbuf.as_milliwatts(), 255, self.max_mw); let _ = self.target.write(brightness(self.pixbuf.iter().cloned(), b)); } @@ -75,7 +72,6 @@ impl>, S: Surface> Display for SmartLedDisp pixel = pixel.saturating_add(shader.draw(&virt_coords)); }) } - self.total_mw += pixel.as_milliwatts(); self.pixbuf[x] = Rgb::new(pixel.r, pixel.g, pixel.b); }; }