tasks: more Fract8 update

This commit is contained in:
2026-02-28 16:54:44 +01:00
parent 935f30d968
commit 22d1b4d077
3 changed files with 22 additions and 21 deletions

View File

@@ -31,13 +31,13 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
.rect(Rectangle::new_from_coordinates(0, 0, 255, 0)) .rect(Rectangle::new_from_coordinates(0, 0, 255, 0))
.shader(Headlight::default()) .shader(Headlight::default())
.visible(false) .visible(false)
.opacity(0) .opacity(Fract8::MIN)
.finish().unwrap().into(), .finish().unwrap().into(),
brakelight: SurfaceBuilder::build(surfaces) brakelight: SurfaceBuilder::build(surfaces)
.rect(Brakelight::rectangle()) .rect(Brakelight::rectangle())
.shader(Brakelight::default()) .shader(Brakelight::default())
.visible(false) .visible(false)
.opacity(0) .opacity(Fract8::MIN)
.finish().unwrap().into(), .finish().unwrap().into(),
display display
}; };
@@ -66,22 +66,22 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
info!("Turning on display"); info!("Turning on display");
// Turn on the display hardware // Turn on the display hardware
self.display.set_brightness(0); self.display.set_brightness(Fract8::MIN);
self.display.set_on(true); self.display.set_on(true);
// Wait for the renderer to start running again // Wait for the renderer to start running again
// FIXME: This deadlocks :( // FIXME: This deadlocks :(
//self.display.render_is_running.wait().await; //self.display.render_is_running.wait().await;
let fade_in = Animation::default().duration(Duration::from_secs(3)).from(0).to(255); let fade_in = Animation::default().duration(Duration::from_secs(3)).from(Fract8::MIN).to(Fract8::MAX);
trace!("Fading in brightness with overlay={:?}", self.overlay); trace!("Fading in brightness with overlay={:?}", self.overlay);
self.overlay.set_opacity(255); self.overlay.set_opacity(Fract8::MAX);
self.overlay.set_visible(true); self.overlay.set_visible(true);
fade_in.apply(&mut AnimDisplay(&mut self.display)).await; fade_in.apply(&mut AnimDisplay(&mut self.display)).await;
warn!("Turning on safety lights"); warn!("Turning on safety lights");
self.headlight.set_opacity(0); self.headlight.set_opacity(Fract8::MIN);
self.headlight.set_visible(true); self.headlight.set_visible(true);
self.brakelight.set_opacity(0); self.brakelight.set_opacity(Fract8::MIN);
self.brakelight.set_visible(true); self.brakelight.set_visible(true);
embassy_futures::join::join( embassy_futures::join::join(
fade_in.apply(&mut self.headlight), fade_in.apply(&mut self.headlight),
@@ -123,8 +123,8 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
} }
} }
const TURN_ON: Animation = Animation::new().duration(Duration::from_secs(1)).from(0).to(255); const TURN_ON: Animation<Fract8> = Animation::new().duration(Duration::from_secs(1)).from(Fract8::MIN).to(Fract8::MAX);
const TURN_OFF: Animation = Animation::new().duration(Duration::from_secs(1)).from(255).to(0); const TURN_OFF: Animation<Fract8> = Animation::new().duration(Duration::from_secs(1)).from(Fract8::MAX).to(Fract8::MIN);
#[embassy_executor::task] #[embassy_executor::task]
pub async fn safety_ui_main(mut events: DynSubscriber<'static, Prediction>, mut ui: SafetyUi<<UiSurfacePool as Surfaces<SegmentSpace>>::Surface>) { pub async fn safety_ui_main(mut events: DynSubscriber<'static, Prediction>, mut ui: SafetyUi<<UiSurfacePool as Surfaces<SegmentSpace>>::Surface>) {

View File

@@ -3,6 +3,7 @@ use embassy_time::{Duration, Timer};
use embedded_storage::ReadStorage; use embedded_storage::ReadStorage;
use esp_bootloader_esp_idf::partitions::PartitionTable; use esp_bootloader_esp_idf::partitions::PartitionTable;
use esp_storage::FlashStorage; use esp_storage::FlashStorage;
use figments::liber8tion::interpolate::Fract8;
use nalgebra::{Vector2, Vector3}; use nalgebra::{Vector2, Vector3};
use log::*; use log::*;
use rmp::decode::ValueReadError; use rmp::decode::ValueReadError;
@@ -176,7 +177,7 @@ pub async fn simulation_task(mut reader: SimDataReader<SharedFlash<FlashStorage>
let pct = (idx as f32) / (reader.event_count as f32); let pct = (idx as f32) / (reader.event_count as f32);
idx_breaker.set((pct * 255.0) as u8); idx_breaker.set((pct * 255.0) as u8);
if let Some(pct) = idx_breaker.read_tripped() { if let Some(pct) = idx_breaker.read_tripped() {
events.send(Measurement::SimulationProgress(reader.srcid(), reader.runtime, pct)).await; events.send(Measurement::SimulationProgress(reader.srcid(), reader.runtime, Fract8::from_raw(pct))).await;
} }
idx += 1; idx += 1;
}, },

View File

@@ -54,10 +54,10 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
} }
pub async fn flash_notification_color(&mut self, color: Rgb<u8>) { pub async fn flash_notification_color(&mut self, color: Rgb<u8>) {
let fade_in = Animation::default().from(0).to(255).duration(Duration::from_millis(30)); let fade_in = Animation::default().from(Fract8::MIN).to(Fract8::MAX).duration(Duration::from_millis(30));
let pulse_out = Animation::default().from(255).to(60).duration(Duration::from_millis(100)); let pulse_out = Animation::default().from(Fract8::MAX).to(Fract8::from_raw(60)).duration(Duration::from_millis(100));
let pulse_in = Animation::default().from(0).to(255).duration(Duration::from_millis(100)); let pulse_in = Animation::default().from(Fract8::MIN).to(Fract8::MAX).duration(Duration::from_millis(100));
let fade_out = Animation::default().from(255).to(0).duration(Duration::from_secs(2)); let fade_out = Animation::default().from(Fract8::MAX).to(Fract8::MIN).duration(Duration::from_secs(2));
info!("Flashing notification {color}"); info!("Flashing notification {color}");
self.notification.set_visible(true); self.notification.set_visible(true);
@@ -95,10 +95,10 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
info!("Activating scene {next_scene:?}"); info!("Activating scene {next_scene:?}");
match next_scene { match next_scene {
Scene::Ready => { Scene::Ready => {
let tail = Animation::default().duration(Duration::from_millis(300)).to(96); let tail = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(96));
let panels = Animation::default().duration(Duration::from_millis(300)).to(128); let panels = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(128));
let bg = Animation::default().duration(Duration::from_millis(300)).to(32); let bg = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(32));
let motion = Animation::default().duration(Duration::from_secs(1)).to(0); let motion = Animation::default().duration(Duration::from_secs(1)).to(Fract8::MIN);
embassy_futures::join::join4( embassy_futures::join::join4(
tail.apply(&mut self.tail), tail.apply(&mut self.tail),
panels.apply(&mut self.panels), panels.apply(&mut self.panels),
@@ -110,8 +110,8 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
Scene::Idle => { Scene::Idle => {
// FIXME: The safety UI task should handle setting the display brightness to 50% here // FIXME: The safety UI task should handle setting the display brightness to 50% here
self.background.set_shader(Thinking::default()); self.background.set_shader(Thinking::default());
let fg_fade = Animation::default().duration(Duration::from_millis(300)).to(0); let fg_fade = Animation::default().duration(Duration::from_millis(300)).to(Fract8::MIN);
let bg_fade = Animation::default().duration(Duration::from_millis(300)).to(128); let bg_fade = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(128));
// FIXME: The scenes shouldn't be touching the brake/headlights at all here. In fact, they should be dealt with in a whole separate task from the main UI, maybe running on the motion prediction executor // FIXME: The scenes shouldn't be touching the brake/headlights at all here. In fact, they should be dealt with in a whole separate task from the main UI, maybe running on the motion prediction executor
embassy_futures::join::join4( embassy_futures::join::join4(
@@ -180,7 +180,7 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
self.as_slice().set_rect(rect); self.as_slice().set_rect(rect);
} }
fn set_opacity(&mut self, opacity: u8) { fn set_opacity(&mut self, opacity: Fract8) {
self.as_slice().set_opacity(opacity); self.as_slice().set_opacity(opacity);
} }