Split into multi-menu

This commit is contained in:
2026-08-14 23:31:36 +02:00
parent 6c683e415f
commit 0fb87f2913
4 changed files with 105 additions and 57 deletions
+24 -38
View File
@@ -1,4 +1,4 @@
use crate::navigation::main_menu::{MAX_SELECTED, MainMenu};
use crate::navigation::state::{Menu, NavigationState};
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
use embassy_futures::select::Either6;
@@ -7,21 +7,30 @@ use embassy_time::{Duration, Timer};
const DEBOUNCE_DURATION_MILLIS: u64 = 100;
pub trait Displayable {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Action {
Up,
Down,
Left,
Right,
Ok,
Back,
}
pub trait Navigable {
fn display(
&self,
display: &mut PrimaryLcdDisplay<'static>,
) -> impl core::future::Future<Output = ()> + Send;
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = Menu> + Send;
}
#[embassy_executor::task]
pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'static>) {
let mut state = MainMenu { selected: 0 };
let mut state = NavigationState::default();
state.display(display).await;
log::info!("starting navigation");
loop {
log::info!("await button press");
let selection = select6(
inputs.up.wait_for_low(),
inputs.down.wait_for_low(),
@@ -32,41 +41,18 @@ pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'st
)
.await;
log::info!("button pressed");
let value = match selection {
Either6::First(_) => {
log::info!("up pressed");
if (state.selected - 1) < 0 {
MAX_SELECTED - 1
} else {
state.selected - 1
}
}
Either6::Second(_) => {
log::info!("down pressed");
(state.selected.wrapping_add(1)) % MAX_SELECTED
}
Either6::Third(_) => {
log::info!("left pressed");
continue;
}
Either6::Fourth(_) => {
log::info!("right pressed");
continue;
}
Either6::Fifth(_) => {
log::info!("ok pressed");
continue;
}
Either6::Sixth(_) => {
log::info!("back pressed");
continue;
}
let action = match selection {
Either6::First(_) => Action::Up,
Either6::Second(_) => Action::Down,
Either6::Third(_) => Action::Left,
Either6::Fourth(_) => Action::Right,
Either6::Fifth(_) => Action::Ok,
Either6::Sixth(_) => Action::Back,
};
state.selected = value;
state.display(display).await;
log::info!("Action: {:?}", action);
state.current_screen = state.current_screen.handle_input(action).await;
state.current_screen.display(display).await;
Timer::after(Duration::from_millis(DEBOUNCE_DURATION_MILLIS)).await;
}