graphics: display: clean up some of the display hardware status locking code

This commit is contained in:
2025-12-24 09:18:50 +01:00
parent d8ffdab92b
commit da60b6ddf5

View File

@@ -23,7 +23,7 @@ impl<T:SmartLedsWriteAsync> GammaCorrected for BikeOutput<T> where T::Color: Pix
}
}
impl<T: SmartLedsWriteAsync> BikeOutput<T> where T::Color: PixelBlend<Rgb<u8>> + PixelFormat + WithGamma + 'static + Default + Clone + Copy, T::Error: core::fmt::Debug {
impl<T: SmartLedsWriteAsync<Color = Rgb<u8>>> BikeOutput<T> where T::Error: core::fmt::Debug {
pub fn new(target: T, max_mw: u32, controls: DisplayControls) -> Self {
Self {
pixbuf: [Default::default(); NUM_PIXELS],
@@ -164,7 +164,7 @@ static RENDER_IS_RUNNING: Watch<CriticalSectionRawMutex, bool, 7> = Watch::new()
// TODO: Implement something similar for a system-wide sleep mechanism
pub struct DisplayControls {
data: Arc<ControlData>,
render_pause: Arc<Signal<CriticalSectionRawMutex, bool>>,
display_is_on: Arc<Signal<CriticalSectionRawMutex, bool>>,
render_run_receiver: Receiver<'static, CriticalSectionRawMutex, bool, 7>
}
@@ -172,7 +172,7 @@ impl Clone for DisplayControls {
fn clone(&self) -> Self {
Self {
data: Arc::clone(&self.data),
render_pause: Arc::clone(&self.render_pause),
display_is_on: Arc::clone(&self.display_is_on),
render_run_receiver: RENDER_IS_RUNNING.receiver().expect("Could not create enough render running receivers")
}
}
@@ -187,19 +187,19 @@ impl DisplayControls {
self.data.brightness.load(core::sync::atomic::Ordering::Relaxed)
}
// FIXME: its a bit weird we have a pub function for the renderer's privates to wait while hiding render_pause, but directly expose render_is_running for any task to wait on
pub async fn wait_until_display_is_on(&self) {
if let Some(true) = self.render_pause.try_take() {
while self.render_pause.wait().await {}
}
while !self.display_is_on.wait().await { log::info!("wait for display") }
log::trace!("display says on!");
}
pub fn notify_render_is_running(&mut self, value: bool) {
log::trace!("render is running!");
RENDER_IS_RUNNING.sender().send(value);
}
pub async fn wait_until_render_is_running(&mut self) {
while !self.render_run_receiver.get().await {}
while !self.render_run_receiver.changed().await { log::info!("wait for render run") }
log::trace!("render says run!");
}
}
@@ -216,7 +216,8 @@ impl Brightness for DisplayControls {
fn set_on(&mut self, is_on: bool) {
self.data.on.store(is_on, core::sync::atomic::Ordering::Relaxed);
self.render_pause.signal(!is_on);
log::trace!("display is on {is_on}");
self.display_is_on.signal(is_on);
}
}
@@ -225,7 +226,7 @@ impl core::fmt::Debug for DisplayControls {
f.debug_struct("DisplayControls")
.field("on", &self.data.on)
.field("brightness", &self.data.brightness)
.field("render_pause", &self.render_pause.signaled())
.field("render_pause_signaled", &self.display_is_on.signaled())
.finish()
}
}
@@ -234,7 +235,7 @@ impl Default for DisplayControls {
fn default() -> Self {
Self {
data: Default::default(),
render_pause: Default::default(),
display_is_on: Default::default(),
render_run_receiver: RENDER_IS_RUNNING.receiver().unwrap()
}
}