platform: smart_leds: move pixbuf size into type args
This commit is contained in:
parent
d6e6f1c554
commit
10f0eaa75e
@ -12,14 +12,14 @@ use std::io;
|
|||||||
|
|
||||||
use rgb::Rgb;
|
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>,
|
surfaces : SurfacePool<S>,
|
||||||
target: T,
|
target: T,
|
||||||
pixbuf: [T::Color; 255],
|
pixbuf: [T::Color; PIXEL_NUM],
|
||||||
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, const PIXEL_NUM: usize> Debug for SmartLedDisplay<T, S, PIXEL_NUM> {
|
||||||
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.pixbuf.as_milliwatts())
|
.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 {
|
pub fn new(target: T, max_mw: u32) -> Self {
|
||||||
SmartLedDisplay {
|
SmartLedDisplay {
|
||||||
surfaces: SurfacePool::new(),
|
surfaces: SurfacePool::new(),
|
||||||
|
pixbuf: [Rgb::new(0, 0, 0); PIXEL_NUM],
|
||||||
target: target,
|
target: target,
|
||||||
max_mw: max_mw,
|
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 {
|
fn as_milliwatts(&self) -> u32 {
|
||||||
self.pixbuf.as_milliwatts()
|
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
|
where
|
||||||
T: SmartLedsWrite<Color = Rgb<u8>>,
|
T: SmartLedsWrite<Color = Rgb<u8>>,
|
||||||
S: Surface {
|
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) {
|
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) {
|
fn end_frame(&mut self) {
|
||||||
@ -98,7 +99,7 @@ pub mod rmt {
|
|||||||
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
|
const MAX_POWER_MW : u32 = POWER_VOLTS * POWER_MA;
|
||||||
|
|
||||||
let target = Self::new(channel, led_pin).unwrap();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user