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))
|
.update(screen::ScreenState::DenmWarning(cc))
|
||||||
.inspect_err(log_screen_error);
|
.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;
|
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 {
|
pub struct DisplaySize {
|
||||||
width: u16,
|
width: u16,
|
||||||
height: u16,
|
height: u16,
|
||||||
|
|
@ -25,6 +28,8 @@ where
|
||||||
prev_state: ScreenState,
|
prev_state: ScreenState,
|
||||||
hb_state: bool,
|
hb_state: bool,
|
||||||
gnss_hb_state: bool,
|
gnss_hb_state: bool,
|
||||||
|
#[cfg(feature = "denm")]
|
||||||
|
denm_display_start_time: esp_hal::time::Instant,
|
||||||
|
|
||||||
// assets
|
// assets
|
||||||
#[cfg(feature = "spat")]
|
#[cfg(feature = "spat")]
|
||||||
|
|
@ -135,6 +140,8 @@ where
|
||||||
prev_state: ScreenState::Uninitialized,
|
prev_state: ScreenState::Uninitialized,
|
||||||
hb_state: false,
|
hb_state: false,
|
||||||
gnss_hb_state: false,
|
gnss_hb_state: false,
|
||||||
|
#[cfg(feature = "denm")]
|
||||||
|
denm_display_start_time: esp_hal::time::Instant::EPOCH,
|
||||||
#[cfg(feature = "spat")]
|
#[cfg(feature = "spat")]
|
||||||
bike_image,
|
bike_image,
|
||||||
// #[cfg(feature = "denm")]
|
// #[cfg(feature = "denm")]
|
||||||
|
|
@ -149,6 +156,27 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, state: ScreenState) -> Result<(), D::Error> {
|
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 {
|
if self.prev_state != state {
|
||||||
match &state {
|
match &state {
|
||||||
ScreenState::Uninitialized | ScreenState::Initial => self.draw_slash_screen()?,
|
ScreenState::Uninitialized | ScreenState::Initial => self.draw_slash_screen()?,
|
||||||
|
|
@ -167,6 +195,7 @@ where
|
||||||
ScreenState::Error(msg) => self.draw_message(msg)?,
|
ScreenState::Error(msg) => self.draw_message(msg)?,
|
||||||
#[cfg(feature = "denm")]
|
#[cfg(feature = "denm")]
|
||||||
ScreenState::DenmWarning(cause_code_choice) => {
|
ScreenState::DenmWarning(cause_code_choice) => {
|
||||||
|
self.denm_display_start_time = now;
|
||||||
self.draw_denm_warning(cause_code_choice)?
|
self.draw_denm_warning(cause_code_choice)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue