fix: recognize actual button, not wrong one
This commit was merged in pull request #30.
This commit is contained in:
+48
-37
@@ -1,10 +1,10 @@
|
||||
use alloc::vec;
|
||||
use core::future;
|
||||
|
||||
use crate::card::model::Card;
|
||||
use crate::card::{decoder::split_nfc_hex, mock::*};
|
||||
use crate::display::primary_lcd::PrimaryLcdDisplay;
|
||||
|
||||
use crate::navigation::inputs::ButtonAction;
|
||||
use crate::views::card_view::CardView;
|
||||
use crate::views::journal_view::JournalView;
|
||||
use crate::views::{menu_item, settings_menu::SettingsMenu, view::View};
|
||||
@@ -37,43 +37,54 @@ impl Navigable for MainMenu {
|
||||
}
|
||||
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send {
|
||||
let card_mock1 = Card::try_from(split_nfc_hex(&MOCK_PAYLOAD3).unwrap()).unwrap();
|
||||
let card_mock2 = Card::try_from(split_nfc_hex(&MOCK_PAYLOAD2).unwrap()).unwrap();
|
||||
|
||||
let new_menu = match input {
|
||||
Action::Up => {
|
||||
let new_selected = if (self.selected - 1) < 0 {
|
||||
MAX_SELECTED - 1
|
||||
} else {
|
||||
self.selected - 1
|
||||
async move {
|
||||
let Action::Button(input) = input else {
|
||||
// Skip timer inputs
|
||||
return NewState {
|
||||
view: View::Main(self.clone()),
|
||||
replace_view: true,
|
||||
redraw: false,
|
||||
};
|
||||
View::Main(MainMenu {
|
||||
selected: new_selected,
|
||||
})
|
||||
}
|
||||
Action::Down => {
|
||||
let new_selected = self.selected.wrapping_add(1) % MAX_SELECTED;
|
||||
View::Main(MainMenu {
|
||||
selected: new_selected,
|
||||
})
|
||||
}
|
||||
Action::Ok => match self.selected {
|
||||
0 => View::Scan(crate::views::scan_menu::ScanMenu { progress: 0 }),
|
||||
1 => View::Card(CardView { card: card_mock1 }),
|
||||
2 => View::Journal(JournalView {
|
||||
cards: vec![card_mock1, card_mock2],
|
||||
selected_card: 0,
|
||||
}),
|
||||
3 => View::Settings(SettingsMenu { selected: 0 }),
|
||||
_ => View::Main(self.clone()),
|
||||
},
|
||||
_ => View::Main(self.clone()),
|
||||
};
|
||||
};
|
||||
|
||||
future::ready(NewState {
|
||||
replace_view: matches!(new_menu, View::Main(_)),
|
||||
view: new_menu,
|
||||
redraw: !matches!(input, Action::Timer),
|
||||
})
|
||||
let card_mock1 = Card::try_from(split_nfc_hex(&MOCK_PAYLOAD3).unwrap()).unwrap();
|
||||
let card_mock2 = Card::try_from(split_nfc_hex(&MOCK_PAYLOAD2).unwrap()).unwrap();
|
||||
|
||||
let new_menu = match input {
|
||||
ButtonAction::Up => {
|
||||
let new_selected = if (self.selected - 1) < 0 {
|
||||
MAX_SELECTED - 1
|
||||
} else {
|
||||
self.selected - 1
|
||||
};
|
||||
View::Main(MainMenu {
|
||||
selected: new_selected,
|
||||
})
|
||||
}
|
||||
ButtonAction::Down => {
|
||||
let new_selected = self.selected.wrapping_add(1) % MAX_SELECTED;
|
||||
View::Main(MainMenu {
|
||||
selected: new_selected,
|
||||
})
|
||||
}
|
||||
ButtonAction::Ok => match self.selected {
|
||||
0 => View::Scan(crate::views::scan_menu::ScanMenu { progress: 0 }),
|
||||
1 => View::Card(CardView { card: card_mock1 }),
|
||||
2 => View::Journal(JournalView {
|
||||
cards: vec![card_mock1, card_mock2],
|
||||
selected_card: 0,
|
||||
}),
|
||||
3 => View::Settings(SettingsMenu { selected: 0 }),
|
||||
_ => View::Main(self.clone()),
|
||||
},
|
||||
_ => View::Main(self.clone()),
|
||||
};
|
||||
|
||||
NewState {
|
||||
replace_view: matches!(new_menu, View::Main(_)),
|
||||
view: new_menu,
|
||||
redraw: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use crate::display::primary_lcd::PrimaryLcdDisplay;
|
||||
use crate::navigation::inputs::ButtonAction;
|
||||
use crate::navigation::navigation::CARD_DATA;
|
||||
use crate::navigation::navigation::NewState;
|
||||
|
||||
@@ -96,7 +97,7 @@ impl Navigable for ScanMenu {
|
||||
}
|
||||
} else {
|
||||
let new_progress = match input {
|
||||
Action::Up => self.progress.wrapping_add(5),
|
||||
Action::Button(ButtonAction::Up) => self.progress.wrapping_add(5),
|
||||
_ => self.progress,
|
||||
};
|
||||
NewState {
|
||||
@@ -104,7 +105,7 @@ impl Navigable for ScanMenu {
|
||||
progress: new_progress,
|
||||
}),
|
||||
replace_view: true,
|
||||
redraw: matches!(input, Action::Up | Action::Timer),
|
||||
redraw: matches!(input, Action::Button(ButtonAction::Up) | Action::Timer),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user