platform: smart_leds: no need to keep total_mw around when we can calculate on the fly
This commit is contained in:
parent
3517428d54
commit
24f0a336e6
@ -16,14 +16,13 @@ pub struct SmartLedDisplay<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> {
|
|||||||
surfaces : SurfacePool<S>,
|
surfaces : SurfacePool<S>,
|
||||||
target: T,
|
target: T,
|
||||||
pixbuf: [T::Color; 255],
|
pixbuf: [T::Color; 255],
|
||||||
total_mw: u32,
|
|
||||||
max_mw: u32
|
max_mw: u32
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Debug for SmartLedDisplay<T, S> {
|
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Debug for SmartLedDisplay<T, S> {
|
||||||
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
||||||
f.debug_struct("SmartLedDisplay")
|
f.debug_struct("SmartLedDisplay")
|
||||||
.field("total_mw", &self.total_mw)
|
.field("total_mw", &self.pixbuf.as_milliwatts())
|
||||||
.field("surfaces", &self.surfaces)
|
.field("surfaces", &self.surfaces)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
@ -35,7 +34,6 @@ impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> SmartLedDisplay<T, S> {
|
|||||||
surfaces: SurfacePool::new(),
|
surfaces: SurfacePool::new(),
|
||||||
target: target,
|
target: target,
|
||||||
max_mw: max_mw,
|
max_mw: max_mw,
|
||||||
total_mw: 0,
|
|
||||||
pixbuf: [Rgb::new(0, 0, 0); 255]
|
pixbuf: [Rgb::new(0, 0, 0); 255]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -43,7 +41,7 @@ impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> SmartLedDisplay<T, S> {
|
|||||||
|
|
||||||
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> AsMilliwatts for SmartLedDisplay<T, S> {
|
impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> AsMilliwatts for SmartLedDisplay<T, S> {
|
||||||
fn as_milliwatts(&self) -> u32 {
|
fn as_milliwatts(&self) -> u32 {
|
||||||
self.total_mw
|
self.pixbuf.as_milliwatts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,11 +56,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> Display<S> for SmartLedDisplay<T, S> {
|
||||||
fn start_frame(&mut self) {
|
fn start_frame(&mut self) {
|
||||||
self.total_mw = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn end_frame(&mut self) {
|
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));
|
let _ = self.target.write(brightness(self.pixbuf.iter().cloned(), b));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +72,6 @@ impl<T: SmartLedsWrite<Color = Rgb<u8>>, S: Surface> Display<S> for SmartLedDisp
|
|||||||
pixel = pixel.saturating_add(shader.draw(&virt_coords));
|
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);
|
self.pixbuf[x] = Rgb::new(pixel.r, pixel.g, pixel.b);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user