main menu: wrap around correctly
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user