From da60b6ddf5c79bcfb88aac115fe4b9685de3053d Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Wed, 24 Dec 2025 09:18:50 +0100 Subject: [PATCH] graphics: display: clean up some of the display hardware status locking code --- src/graphics/display.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/graphics/display.rs b/src/graphics/display.rs index 22a3002..010d8f0 100644 --- a/src/graphics/display.rs +++ b/src/graphics/display.rs @@ -23,7 +23,7 @@ impl GammaCorrected for BikeOutput where T::Color: Pix } } -impl BikeOutput where T::Color: PixelBlend> + PixelFormat + WithGamma + 'static + Default + Clone + Copy, T::Error: core::fmt::Debug { +impl>> BikeOutput 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 = Watch::new() // TODO: Implement something similar for a system-wide sleep mechanism pub struct DisplayControls { data: Arc, - render_pause: Arc>, + display_is_on: Arc>, 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() } }