main menu: wrap around correctly

This commit is contained in:
2026-08-14 21:18:08 +00:00
parent d3ac95a9bd
commit 6c683e415f
2 changed files with 21 additions and 10 deletions
+10 -2
View File
@@ -8,13 +8,17 @@ use embassy_time::{Duration, Timer};
const DEBOUNCE_DURATION_MILLIS: u64 = 100;
pub trait Displayable {
fn display(&self, display: &mut PrimaryLcdDisplay<'static>) -> impl core::future::Future<Output = ()> + Send;
fn display(
&self,
display: &mut PrimaryLcdDisplay<'static>,
) -> impl core::future::Future<Output = ()> + Send;
}
#[embassy_executor::task]
pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'static>) {
let mut state = MainMenu { selected: 0 };
state.display(display).await;
log::info!("starting navigation");
loop {
log::info!("await button press");
@@ -32,7 +36,11 @@ pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'st
let value = match selection {
Either6::First(_) => {
log::info!("up pressed");
(state.selected.wrapping_sub(1)) % MAX_SELECTED
if (state.selected - 1) < 0 {
MAX_SELECTED - 1
} else {
state.selected - 1
}
}
Either6::Second(_) => {
log::info!("down pressed");