implement error view which displays all error on the display
This commit was merged in pull request #48.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
use crate::alloc::string::ToString;
|
||||
use crate::card::model::Card;
|
||||
use crate::navigation::inputs::ButtonAction;
|
||||
use crate::navigation::inputs::Inputs;
|
||||
use crate::navigation::outputs::Outputs;
|
||||
use crate::navigation::state::NavigationState;
|
||||
use crate::peripherals::Peripherals;
|
||||
use crate::views::error_view::ErrorView;
|
||||
use crate::views::view::View;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::String;
|
||||
use core::error;
|
||||
|
||||
use embassy_futures::select::{Either, select};
|
||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||
@@ -32,21 +37,45 @@ pub trait Navigable {
|
||||
&self,
|
||||
outputs: &mut Outputs,
|
||||
peripherals: &Peripherals,
|
||||
) -> impl core::future::Future<Output = ()> + Send;
|
||||
) -> impl core::future::Future<Output = Result<(), Box<dyn error::Error>>> + Send;
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send;
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
pub async fn run(mut inputs: Inputs, mut outputs: Outputs, peripherals: &'static Peripherals) {
|
||||
async fn display_error(
|
||||
error: String,
|
||||
state: &mut NavigationState,
|
||||
outputs: &mut Outputs,
|
||||
peripherals: &Peripherals,
|
||||
) -> () {
|
||||
let error_view = ErrorView {
|
||||
error: error.to_string(),
|
||||
};
|
||||
state.screens.push(View::Error(error_view));
|
||||
state
|
||||
.screens
|
||||
.last()
|
||||
// Unwrap: we just pushed the state
|
||||
.unwrap()
|
||||
.display(outputs, peripherals)
|
||||
.await
|
||||
// Unwrap: display will panic on error in error view
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
log::info!("starting navigation");
|
||||
|
||||
let mut state = NavigationState::new();
|
||||
state
|
||||
if let Err(error) = state
|
||||
.screens
|
||||
.last()
|
||||
.unwrap()
|
||||
.display(&mut outputs, peripherals)
|
||||
.await;
|
||||
.await
|
||||
{
|
||||
display_error(error.to_string(), &mut state, &mut outputs, &peripherals).await;
|
||||
};
|
||||
|
||||
loop {
|
||||
let selection = select(
|
||||
@@ -92,12 +121,15 @@ pub async fn run(mut inputs: Inputs, mut outputs: Outputs, peripherals: &'static
|
||||
state.screens.push(new_state.view);
|
||||
|
||||
if action != Action::Timer || new_state.redraw {
|
||||
state
|
||||
if let Err(error) = state
|
||||
.screens
|
||||
.last()
|
||||
.unwrap()
|
||||
.display(&mut outputs, peripherals)
|
||||
.await;
|
||||
.await
|
||||
{
|
||||
display_error(error.to_string(), &mut state, &mut outputs, &peripherals).await;
|
||||
}
|
||||
}
|
||||
|
||||
Timer::after(Duration::from_millis(DEBOUNCE_DURATION_MILLIS)).await;
|
||||
|
||||
Reference in New Issue
Block a user