implement back button

This commit is contained in:
2026-08-18 18:53:17 +00:00
parent 9792385af1
commit 8a7456adbd
5 changed files with 55 additions and 30 deletions
+21 -7
View File
@@ -1,5 +1,5 @@
use crate::navigation::scan_menu::ScanMenu;
use crate::navigation::state::{Menu, NavigationState};
use crate::navigation::state::{NavigationState, ScreenItem};
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
use embassy_futures::select::Either6;
@@ -23,15 +23,16 @@ pub trait Navigable {
&self,
display: &mut PrimaryLcdDisplay<'static>,
) -> impl core::future::Future<Output = ()> + Send;
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = Menu> + Send;
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = ScreenItem> + Send;
}
#[embassy_executor::task]
pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'static>) {
let mut state = NavigationState::default();
// state.current_screen = Menu::Scan(ScanMenu { progress: (100 * 30 / 255) as u8 });
log::info!("starting navigation");
let mut state = NavigationState::new();
state.screens.last().unwrap().display(display).await;
loop {
let selection = select6(
inputs.up.wait_for_low(),
@@ -53,8 +54,21 @@ pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'st
};
log::info!("Action: {:?}", action);
state.current_screen = state.current_screen.handle_input(action).await;
state.current_screen.display(display).await;
let screen = match action {
Action::Back => state.back(),
_ => {
state
.screens
.last()
.expect("no screen on stack")
.handle_input(action)
.await
}
};
screen.display(display).await;
state.screens.push(screen);
Timer::after(Duration::from_millis(DEBOUNCE_DURATION_MILLIS)).await;
}