Implemented Scan card menu
This commit was merged in pull request #29.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::display::sprite::render_sprite_onto_ili9341;
|
||||
use crate::navigation::navigation::NewState;
|
||||
use alloc::format;
|
||||
use embedded_graphics::mono_font::MonoTextStyle;
|
||||
use embedded_graphics::mono_font::ascii::FONT_6X10;
|
||||
@@ -99,12 +100,13 @@ impl Navigable for CardView {
|
||||
core::future::ready(())
|
||||
}
|
||||
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||
let new_menu = match input {
|
||||
Action::Ok => View::Card(self.clone()),
|
||||
_ => View::Card(self.clone()),
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send {
|
||||
let new_state = NewState {
|
||||
view: View::Card(self.clone()),
|
||||
replace_view: true,
|
||||
redraw: !matches!(input, Action::Timer),
|
||||
};
|
||||
|
||||
future::ready(new_menu)
|
||||
future::ready(new_state)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,7 @@ use embedded_graphics::prelude::RgbColor;
|
||||
use embedded_graphics_core::draw_target::DrawTarget;
|
||||
|
||||
use crate::{
|
||||
card::model::Card,
|
||||
display::primary_lcd::PrimaryLcdDisplay,
|
||||
navigation::navigation::{Action, Navigable},
|
||||
views::view::View,
|
||||
card::model::Card, display::primary_lcd::PrimaryLcdDisplay, navigation::navigation::{Action, Navigable, NewState}, views::view::View,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -29,12 +26,13 @@ impl Navigable for JournalView {
|
||||
core::future::ready(())
|
||||
}
|
||||
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||
let new_menu = match input {
|
||||
Action::Ok => View::Journal(self.clone()),
|
||||
_ => View::Journal(self.clone()),
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send {
|
||||
let new_state = NewState {
|
||||
view: View::Journal(self.clone()),
|
||||
replace_view: true,
|
||||
redraw: !matches!(input, Action::Timer),
|
||||
};
|
||||
|
||||
future::ready(new_menu)
|
||||
future::ready(new_state)
|
||||
}
|
||||
}
|
||||
|
||||
+16
-10
@@ -9,12 +9,12 @@ use crate::views::card_view::CardView;
|
||||
use crate::views::journal_view::JournalView;
|
||||
use crate::views::{menu_item, settings_menu::SettingsMenu, view::View};
|
||||
|
||||
use crate::navigation::navigation::{Action, Navigable};
|
||||
use crate::navigation::navigation::{Action, Navigable, NewState};
|
||||
use embedded_graphics::pixelcolor::Rgb565;
|
||||
use embedded_graphics::prelude::RgbColor;
|
||||
use embedded_graphics_core::draw_target::DrawTarget;
|
||||
|
||||
pub const MAX_SELECTED: i32 = 3;
|
||||
pub const MAX_SELECTED: i32 = 4;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MainMenu {
|
||||
@@ -28,14 +28,15 @@ impl Navigable for MainMenu {
|
||||
) -> impl core::future::Future<Output = ()> + Send {
|
||||
display.clear(Rgb565::BLACK).unwrap();
|
||||
|
||||
menu_item::show(display, "Last card", 0, self.selected);
|
||||
menu_item::show(display, "Journal", 1, self.selected);
|
||||
menu_item::show(display, "Settings", 2, self.selected);
|
||||
menu_item::show(display, "Scan card", 0, self.selected);
|
||||
menu_item::show(display, "Last card", 1, self.selected);
|
||||
menu_item::show(display, "Journal", 2, self.selected);
|
||||
menu_item::show(display, "Settings", 3, self.selected);
|
||||
|
||||
core::future::ready(())
|
||||
}
|
||||
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||
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();
|
||||
|
||||
@@ -57,17 +58,22 @@ impl Navigable for MainMenu {
|
||||
})
|
||||
}
|
||||
Action::Ok => match self.selected {
|
||||
0 => View::Card(CardView { card: card_mock1 }),
|
||||
1 => View::Journal(JournalView {
|
||||
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,
|
||||
}),
|
||||
2 => View::Settings(SettingsMenu { selected: 0 }),
|
||||
3 => View::Settings(SettingsMenu { selected: 0 }),
|
||||
_ => View::Main(self.clone()),
|
||||
},
|
||||
_ => View::Main(self.clone()),
|
||||
};
|
||||
|
||||
future::ready(new_menu)
|
||||
future::ready(NewState {
|
||||
replace_view: matches!(new_menu, View::Main(_)),
|
||||
view: new_menu,
|
||||
redraw: !matches!(input, Action::Timer),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+24
-9
@@ -1,4 +1,6 @@
|
||||
use crate::display::primary_lcd::PrimaryLcdDisplay;
|
||||
use crate::navigation::navigation::CARD_DATA;
|
||||
use crate::navigation::navigation::NewState;
|
||||
|
||||
use alloc::format;
|
||||
use embedded_graphics::Drawable;
|
||||
@@ -82,16 +84,29 @@ impl Navigable for ScanMenu {
|
||||
core::future::ready(())
|
||||
}
|
||||
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send {
|
||||
async move {
|
||||
let new_progress = match input {
|
||||
Action::Up => self.progress.wrapping_add(5),
|
||||
_ => self.progress,
|
||||
};
|
||||
|
||||
View::Scan(ScanMenu {
|
||||
progress: new_progress,
|
||||
})
|
||||
log::info!("Scan view detected, checking for NFC card data");
|
||||
if let Some(card_data) = CARD_DATA.lock().await.take() {
|
||||
log::info!("NFC Card to be displayed: {:?}", card_data);
|
||||
NewState {
|
||||
view: View::Card(crate::views::card_view::CardView { card: card_data }),
|
||||
replace_view: true,
|
||||
redraw: true,
|
||||
}
|
||||
} else {
|
||||
let new_progress = match input {
|
||||
Action::Up => self.progress.wrapping_add(5),
|
||||
_ => self.progress,
|
||||
};
|
||||
NewState {
|
||||
view: View::Scan(ScanMenu {
|
||||
progress: new_progress,
|
||||
}),
|
||||
replace_view: true,
|
||||
redraw: matches!(input, Action::Up | Action::Timer),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::display::primary_lcd::PrimaryLcdDisplay;
|
||||
|
||||
use crate::navigation::navigation::{Action, Navigable};
|
||||
use crate::navigation::navigation::{Action, Navigable, NewState};
|
||||
use crate::views::{menu_item, view::View};
|
||||
|
||||
use embedded_graphics::pixelcolor::Rgb565;
|
||||
@@ -25,7 +25,13 @@ impl Navigable for SettingsMenu {
|
||||
core::future::ready(())
|
||||
}
|
||||
|
||||
fn handle_input(&self, _input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||
async move { View::Settings(SettingsMenu { selected: 0 }) }
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send {
|
||||
async move {
|
||||
NewState {
|
||||
view: View::Settings(SettingsMenu { selected: 0 }),
|
||||
replace_view: true,
|
||||
redraw: !matches!(input, Action::Timer),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ use crate::views::{
|
||||
settings_menu::SettingsMenu,
|
||||
};
|
||||
|
||||
use crate::navigation::navigation::Navigable;
|
||||
use crate::navigation::navigation::{Navigable, NewState};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum View {
|
||||
@@ -34,7 +34,7 @@ impl Navigable for View {
|
||||
fn handle_input(
|
||||
&self,
|
||||
input: crate::navigation::navigation::Action,
|
||||
) -> impl core::future::Future<Output = Self> + Send {
|
||||
) -> impl core::future::Future<Output = NewState> + Send {
|
||||
async move {
|
||||
match self {
|
||||
View::Main(main_menu) => main_menu.handle_input(input).await,
|
||||
|
||||
Reference in New Issue
Block a user