display: make DisplayControls cloneable in a multi-thread context

This commit is contained in:
2025-10-17 14:38:49 +02:00
parent d957615d4e
commit eb9f949e4e
5 changed files with 130 additions and 82 deletions

View File

@@ -7,14 +7,13 @@ use figments_render::output::{GammaCorrected, OutputAsync};
use log::{info, warn};
use rgb::Rgba;
use nalgebra::ComplexField;
use alloc::sync::Arc;
use crate::{display::{BikeOutput, SegmentSpace, Uniforms}, events::DisplayControls};
use crate::display::{BikeOutput, DisplayControls, SegmentSpace, Uniforms};
//TODO: Import the bike surfaces from renderbug-prime, somehow make those surfaces into tasks
#[embassy_executor::task]
pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'static>, surfaces: BufferedSurfacePool<Uniforms, SegmentSpace, Rgba<u8>>, controls: Arc<DisplayControls>, mut wdt: Wdt<esp_hal::peripherals::TIMG0<'static>>) {
pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'static>, surfaces: BufferedSurfacePool<Uniforms, SegmentSpace, Rgba<u8>>, safety_surfaces: BufferedSurfacePool<Uniforms, SegmentSpace, Rgba<u8>>, mut controls: DisplayControls, mut wdt: Wdt<esp_hal::peripherals::TIMG0<'static>>) {
let frequency: Rate = Rate::from_mhz(80);
let rmt = Rmt::new(rmt, frequency)
.expect("Failed to initialize RMT").into_async();
@@ -45,7 +44,7 @@ pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'stati
//output.set_gamma(GammaCurve::new(2.1));
info!("Rendering started! {}ms since boot", Instant::now().as_millis());
controls.render_is_running.signal(true);
controls.notify_render_is_running(true);
const FPS: u64 = 80;
const RENDER_BUDGET: Duration = Duration::from_millis(1000 / FPS);
@@ -57,6 +56,8 @@ pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'stati
output.blank();
surfaces.render_to(&mut output, &uniforms);
// TODO: We should split up the safety layers so they always have full power
safety_surfaces.render_to(&mut output, &uniforms);
// Finally, write out the rendered frame
output.commit_async().await.expect("Failed to commit frame");
@@ -65,14 +66,14 @@ pub async fn render(rmt: esp_hal::peripherals::RMT<'static>, gpio: AnyPin<'stati
if !controls.is_on() {
warn!("Renderer is sleeping zzzz");
//controls.render_is_running.signal(false);
controls.notify_render_is_running(false);
output.blank();
wdt.disable();
controls.wait_for_on().await;
controls.wait_until_display_is_on().await;
wdt.feed();
wdt.enable();
warn!("Renderer is awake !!!!");
//controls.render_is_running.signal(true);
controls.notify_render_is_running(true);
}
if render_duration < RENDER_BUDGET {