graphics: display: implement dynamic target fps
This commit is contained in:
@@ -46,15 +46,13 @@ pub async fn render(spi: AnySpi<'static>, dma: AnyGdmaChannel<'static>, gpio: An
|
||||
info!("Rendering started! {}ms since boot", Instant::now().as_millis());
|
||||
controls.notify_render_is_running(true);
|
||||
|
||||
// TODO: The prediction engine should be able to scale the display FPS down for power saving sometimes
|
||||
const FPS: u64 = 30;
|
||||
const RENDER_BUDGET: Duration = Duration::from_millis(1000 / FPS);
|
||||
let mut requested_fps= controls.fps() as u64;
|
||||
let mut render_budget = Duration::from_millis(1000 / requested_fps);
|
||||
|
||||
const ANIMATION_TPS: u64 = 120;
|
||||
const ANIMATION_FRAME_TIME: Duration = Duration::from_millis(1000 / ANIMATION_TPS);
|
||||
|
||||
loop {
|
||||
// FIXME: need to put the rendering loop into a deep sleep when the display is off
|
||||
let start = Instant::now();
|
||||
|
||||
output.blank();
|
||||
@@ -70,13 +68,20 @@ pub async fn render(spi: AnySpi<'static>, dma: AnyGdmaChannel<'static>, gpio: An
|
||||
|
||||
let render_duration = Instant::now() - start;
|
||||
|
||||
let next_fps = controls.fps() as u64;
|
||||
if next_fps != requested_fps {
|
||||
requested_fps = next_fps;
|
||||
render_budget = Duration::from_millis(1000 / requested_fps);
|
||||
info!("FPS changed to {requested_fps}");
|
||||
}
|
||||
|
||||
if !controls.is_on() {
|
||||
warn!("Renderer is sleeping zzzz");
|
||||
controls.notify_render_is_running(false);
|
||||
output.blank();
|
||||
output.commit_async().await.expect("Failed to commit low power frame");
|
||||
wdt.disable();
|
||||
controls.wait_until_display_is_on().await;
|
||||
controls.wait_until_display_is_turned_on().await;
|
||||
wdt.feed();
|
||||
wdt.enable();
|
||||
warn!("Renderer is awake !!!!");
|
||||
@@ -84,12 +89,11 @@ pub async fn render(spi: AnySpi<'static>, dma: AnyGdmaChannel<'static>, gpio: An
|
||||
}
|
||||
|
||||
// Apply the FPS cap where we sleep if we are rendering fast enough
|
||||
if render_duration < RENDER_BUDGET {
|
||||
let remaining_budget = RENDER_BUDGET - render_duration;
|
||||
if render_duration < render_budget {
|
||||
let remaining_budget = render_budget - render_duration;
|
||||
Timer::after(remaining_budget).await;
|
||||
} else {
|
||||
// Otherwise, we have a problem
|
||||
// TODO: Automatically scale FPS back when this happens
|
||||
warn!("Render stall! Frame took {}ms", render_duration.as_millis());
|
||||
// Kick the scheduler since it took so long
|
||||
Timer::after_ticks(1).await;
|
||||
|
||||
@@ -94,6 +94,7 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
|
||||
if let Prediction::SetPersonality(personality) = event { match personality {
|
||||
Personality::Active => {
|
||||
// FIXME: These should be a Off/Low/High enum, so the stopping brake looks different from the dayrunning brake.
|
||||
self.display.set_fps(DEFAULT_FPS);
|
||||
warn!("Active personality: Turning on safety lights");
|
||||
TURN_ON_FAST.apply([
|
||||
&mut self.brakelight,
|
||||
@@ -106,6 +107,7 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
|
||||
&mut self.brakelight,
|
||||
&mut self.headlight
|
||||
]).await;
|
||||
self.display.set_fps(LOW_POWER_FPS);
|
||||
},
|
||||
Personality::Sleeping => {
|
||||
warn!("Sleeping personality: Safety UI is going to sleep");
|
||||
@@ -113,6 +115,7 @@ impl<S: Debug + Surface<Uniforms = Uniforms, CoordinateSpace = SegmentSpace, Pix
|
||||
},
|
||||
Personality::Waking => {
|
||||
warn!("Waking personality: Waking up safety UI");
|
||||
self.display.set_fps(DEFAULT_FPS);
|
||||
self.wake().await;
|
||||
},
|
||||
} }
|
||||
|
||||
Reference in New Issue
Block a user