events: implement a first attempt at an eventing system
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use smart_leds_trait::SmartLedsWrite;
|
||||
|
||||
use crate::buffers::Pixbuf;
|
||||
use crate::events::Variant;
|
||||
use crate::render::{HardwarePixel, Output, PixelView, Sample};
|
||||
use crate::power::brightness_for_mw;
|
||||
use crate::geometry::*;
|
||||
@@ -18,7 +19,8 @@ pub struct StrideOutput<P: Pixbuf, T: FastWrite> {
|
||||
pixbuf: P,
|
||||
stride_map: StrideMapping,
|
||||
target: T,
|
||||
max_mw: u32
|
||||
max_mw: u32,
|
||||
brightness: u8
|
||||
}
|
||||
|
||||
impl<P: Pixbuf, T: FastWrite> StrideOutput<P, T> {
|
||||
@@ -28,7 +30,8 @@ impl<P: Pixbuf, T: FastWrite> StrideOutput<P, T> {
|
||||
pixbuf,
|
||||
stride_map,
|
||||
target,
|
||||
max_mw
|
||||
max_mw,
|
||||
brightness: 255
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,11 +49,18 @@ impl<P: Pixbuf<Pixel=T::Color>, T: FastWrite> Output for StrideOutput<P, T> {
|
||||
}
|
||||
|
||||
fn commit(&mut self) {
|
||||
let b = brightness_for_mw(self.pixbuf.as_milliwatts(), 255, self.max_mw);
|
||||
let b = brightness_for_mw(self.pixbuf.as_milliwatts(), self.brightness, self.max_mw);
|
||||
if self.target.fast_write(self.pixbuf.iter_with_brightness(b)).is_err() {
|
||||
panic!("Could not write frame!");
|
||||
};
|
||||
}
|
||||
|
||||
fn on_event(&mut self, event: &crate::events::Event) {
|
||||
match event {
|
||||
crate::events::Event::PropertyChange("output.brightness", new_brightness) => self.brightness = new_brightness.clone().into(),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FastWrite: Send {
|
||||
|
Reference in New Issue
Block a user