WIP FIXUP: Show DENMS for a minimum time
This commit is contained in:
parent
7ec7ebda8a
commit
96cf9aeaa2
2 changed files with 30 additions and 0 deletions
|
|
@ -585,6 +585,7 @@ async fn main(spawner: Spawner) -> ! {
|
|||
.update(screen::ScreenState::DenmWarning(cc))
|
||||
.inspect_err(log_screen_error);
|
||||
}
|
||||
// TODO: cancel screen, if None?
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ use embedded_graphics::{geometry, mono_font, pixelcolor, primitives, text};
|
|||
|
||||
use crate::applogic;
|
||||
|
||||
#[cfg(feature = "denm")]
|
||||
const DENM_MIN_DISPLAY_TIME: esp_hal::time::Duration = esp_hal::time::Duration::from_secs(5);
|
||||
|
||||
pub struct DisplaySize {
|
||||
width: u16,
|
||||
height: u16,
|
||||
|
|
@ -25,6 +28,8 @@ where
|
|||
prev_state: ScreenState,
|
||||
hb_state: bool,
|
||||
gnss_hb_state: bool,
|
||||
#[cfg(feature = "denm")]
|
||||
denm_display_start_time: esp_hal::time::Instant,
|
||||
|
||||
// assets
|
||||
#[cfg(feature = "spat")]
|
||||
|
|
@ -135,6 +140,8 @@ where
|
|||
prev_state: ScreenState::Uninitialized,
|
||||
hb_state: false,
|
||||
gnss_hb_state: false,
|
||||
#[cfg(feature = "denm")]
|
||||
denm_display_start_time: esp_hal::time::Instant::EPOCH,
|
||||
#[cfg(feature = "spat")]
|
||||
bike_image,
|
||||
// #[cfg(feature = "denm")]
|
||||
|
|
@ -149,6 +156,27 @@ where
|
|||
}
|
||||
|
||||
pub fn update(&mut self, state: ScreenState) -> Result<(), D::Error> {
|
||||
#[cfg(feature = "denm")]
|
||||
let now = esp_hal::time::Instant::now();
|
||||
|
||||
#[cfg(feature = "denm")]
|
||||
// when a DENM was shown before, make sure it's shown for a minimum time
|
||||
if let ScreenState::DenmWarning(_) = self.prev_state {
|
||||
use core::ops::Sub;
|
||||
|
||||
// update DENM display, if there are updates
|
||||
if self.prev_state != state
|
||||
&& let ScreenState::DenmWarning(cause_code_choice) = &state
|
||||
{
|
||||
return self.draw_denm_warning(cause_code_choice);
|
||||
}
|
||||
|
||||
// otherwise early return when timer isn't expired yet
|
||||
if now.sub(self.denm_display_start_time) < DENM_MIN_DISPLAY_TIME {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
if self.prev_state != state {
|
||||
match &state {
|
||||
ScreenState::Uninitialized | ScreenState::Initial => self.draw_slash_screen()?,
|
||||
|
|
@ -167,6 +195,7 @@ where
|
|||
ScreenState::Error(msg) => self.draw_message(msg)?,
|
||||
#[cfg(feature = "denm")]
|
||||
ScreenState::DenmWarning(cause_code_choice) => {
|
||||
self.denm_display_start_time = now;
|
||||
self.draw_denm_warning(cause_code_choice)?
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue