Mainmenu #28
+1
-1
@@ -10,12 +10,12 @@
|
|||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use creaturedex::card::mock::{MOCK_PAYLOAD, MOCK_PAYLOAD2};
|
use creaturedex::card::mock::{MOCK_PAYLOAD, MOCK_PAYLOAD2};
|
||||||
use creaturedex::display::primary_lcd::{PrimaryLcdDisplay, init_primary_lcd};
|
use creaturedex::display::primary_lcd::{PrimaryLcdDisplay, init_primary_lcd};
|
||||||
use creaturedex::display::views::card_view::render_nfc_payload;
|
|
||||||
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
||||||
use creaturedex::navigation::inputs::Inputs;
|
use creaturedex::navigation::inputs::Inputs;
|
||||||
use creaturedex::navigation::navigation;
|
use creaturedex::navigation::navigation;
|
||||||
use creaturedex::navigation::state::NavigationState;
|
use creaturedex::navigation::state::NavigationState;
|
||||||
use creaturedex::network::wifi::setup_wifi;
|
use creaturedex::network::wifi::setup_wifi;
|
||||||
|
use creaturedex::views::card_view::render_nfc_payload;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::Timer;
|
use embassy_time::Timer;
|
||||||
use embedded_graphics::draw_target::DrawTarget;
|
use embedded_graphics::draw_target::DrawTarget;
|
||||||
|
|||||||
@@ -3,4 +3,3 @@ pub mod primary_lcd;
|
|||||||
pub mod secondary_oled;
|
pub mod secondary_oled;
|
||||||
pub mod sprite;
|
pub mod sprite;
|
||||||
pub mod tertiary_lcd;
|
pub mod tertiary_lcd;
|
||||||
pub mod views;
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
pub mod card_view;
|
|
||||||
pub mod menu_view;
|
|
||||||
pub mod status_bar;
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
// Menu view module
|
|
||||||
@@ -8,3 +8,4 @@ pub mod drivers;
|
|||||||
pub mod navigation;
|
pub mod navigation;
|
||||||
pub mod network;
|
pub mod network;
|
||||||
pub mod storage;
|
pub mod storage;
|
||||||
|
pub mod views;
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
pub mod inputs;
|
pub mod inputs;
|
||||||
pub mod main_menu;
|
|
||||||
pub mod menu_item;
|
|
||||||
pub mod navigation;
|
pub mod navigation;
|
||||||
pub mod scan_menu;
|
|
||||||
pub mod settings_menu;
|
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use crate::navigation::scan_menu::ScanMenu;
|
use crate::navigation::state::NavigationState;
|
||||||
use crate::navigation::state::{NavigationState, ScreenItem};
|
use crate::views::view::View;
|
||||||
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
|
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
|
||||||
|
|
||||||
use embassy_futures::select::Either6;
|
use embassy_futures::select::Either6;
|
||||||
@@ -23,7 +23,7 @@ pub trait Navigable {
|
|||||||
&self,
|
&self,
|
||||||
display: &mut PrimaryLcdDisplay<'static>,
|
display: &mut PrimaryLcdDisplay<'static>,
|
||||||
) -> impl core::future::Future<Output = ()> + Send;
|
) -> impl core::future::Future<Output = ()> + Send;
|
||||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = ScreenItem> + Send;
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
|
|||||||
+4
-41
@@ -1,53 +1,16 @@
|
|||||||
use crate::navigation::{
|
use crate::views::{main_menu::MainMenu, view::View};
|
||||||
main_menu::MainMenu, navigation::Navigable, scan_menu::ScanMenu, settings_menu::SettingsMenu,
|
|
||||||
};
|
|
||||||
use alloc::vec;
|
use alloc::vec;
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum ScreenItem {
|
|
||||||
Main(MainMenu),
|
|
||||||
Scan(ScanMenu),
|
|
||||||
Settings(SettingsMenu),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Navigable for ScreenItem {
|
|
||||||
fn display(
|
|
||||||
&self,
|
|
||||||
display: &mut crate::display::primary_lcd::PrimaryLcdDisplay<'static>,
|
|
||||||
) -> impl core::future::Future<Output = ()> + Send {
|
|
||||||
async move {
|
|
||||||
match self {
|
|
||||||
ScreenItem::Main(main_menu) => main_menu.display(display).await,
|
|
||||||
ScreenItem::Scan(scan_menu) => scan_menu.display(display).await,
|
|
||||||
ScreenItem::Settings(settings_menu) => settings_menu.display(display).await,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_input(
|
|
||||||
&self,
|
|
||||||
input: crate::navigation::navigation::Action,
|
|
||||||
) -> impl core::future::Future<Output = Self> + Send {
|
|
||||||
async move {
|
|
||||||
match self {
|
|
||||||
ScreenItem::Main(main_menu) => main_menu.handle_input(input).await,
|
|
||||||
ScreenItem::Scan(scan_menu) => scan_menu.handle_input(input).await,
|
|
||||||
ScreenItem::Settings(settings_menu) => settings_menu.handle_input(input).await,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct NavigationState {
|
pub struct NavigationState {
|
||||||
pub screens: Vec<ScreenItem>,
|
pub screens: Vec<View>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for NavigationState {
|
impl Default for NavigationState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
screens: vec![ScreenItem::Main(MainMenu { selected: 0 })],
|
screens: vec![View::Main(MainMenu { selected: 0 })],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +20,7 @@ impl NavigationState {
|
|||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn back(&mut self) -> ScreenItem {
|
pub fn back(&mut self) -> View {
|
||||||
let screen = self.screens.pop().unwrap();
|
let screen = self.screens.pop().unwrap();
|
||||||
if self.screens.is_empty() {
|
if self.screens.is_empty() {
|
||||||
log::info!("last screen");
|
log::info!("last screen");
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pub mod card_view;
|
||||||
|
pub mod main_menu;
|
||||||
|
pub mod menu_item;
|
||||||
|
pub mod scan_menu;
|
||||||
|
pub mod settings_menu;
|
||||||
|
pub mod status_bar;
|
||||||
|
pub mod view;
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
use core::future;
|
use core::future;
|
||||||
|
|
||||||
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
|
use crate::display::primary_lcd::PrimaryLcdDisplay;
|
||||||
|
|
||||||
use crate::navigation::menu_item;
|
use crate::views::{menu_item, settings_menu::SettingsMenu, view::View};
|
||||||
use crate::navigation::settings_menu::SettingsMenu;
|
|
||||||
|
|
||||||
|
use crate::navigation::navigation::{Action, Navigable};
|
||||||
use embedded_graphics::pixelcolor::Rgb565;
|
use embedded_graphics::pixelcolor::Rgb565;
|
||||||
use embedded_graphics::prelude::RgbColor;
|
use embedded_graphics::prelude::RgbColor;
|
||||||
use embedded_graphics_core::draw_target::DrawTarget;
|
use embedded_graphics_core::draw_target::DrawTarget;
|
||||||
|
|
||||||
use super::state::ScreenItem;
|
|
||||||
|
|
||||||
pub const MAX_SELECTED: i32 = 3;
|
pub const MAX_SELECTED: i32 = 3;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -18,7 +16,7 @@ pub struct MainMenu {
|
|||||||
pub selected: i32,
|
pub selected: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::navigation::Navigable for MainMenu {
|
impl Navigable for MainMenu {
|
||||||
fn display(
|
fn display(
|
||||||
&self,
|
&self,
|
||||||
display: &mut PrimaryLcdDisplay<'static>,
|
display: &mut PrimaryLcdDisplay<'static>,
|
||||||
@@ -32,32 +30,29 @@ impl super::navigation::Navigable for MainMenu {
|
|||||||
core::future::ready(())
|
core::future::ready(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_input(
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||||
&self,
|
|
||||||
input: super::navigation::Action,
|
|
||||||
) -> impl core::future::Future<Output = ScreenItem> + Send {
|
|
||||||
let new_menu = match input {
|
let new_menu = match input {
|
||||||
super::navigation::Action::Up => {
|
Action::Up => {
|
||||||
let new_selected = if (self.selected - 1) < 0 {
|
let new_selected = if (self.selected - 1) < 0 {
|
||||||
MAX_SELECTED - 1
|
MAX_SELECTED - 1
|
||||||
} else {
|
} else {
|
||||||
self.selected - 1
|
self.selected - 1
|
||||||
};
|
};
|
||||||
ScreenItem::Main(MainMenu {
|
View::Main(MainMenu {
|
||||||
selected: new_selected,
|
selected: new_selected,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
super::navigation::Action::Down => {
|
Action::Down => {
|
||||||
let new_selected = self.selected.wrapping_add(1) % MAX_SELECTED;
|
let new_selected = self.selected.wrapping_add(1) % MAX_SELECTED;
|
||||||
ScreenItem::Main(MainMenu {
|
View::Main(MainMenu {
|
||||||
selected: new_selected,
|
selected: new_selected,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
super::navigation::Action::Ok => match self.selected {
|
Action::Ok => match self.selected {
|
||||||
2 => ScreenItem::Settings(SettingsMenu { selected: 0 }),
|
2 => View::Settings(SettingsMenu { selected: 0 }),
|
||||||
_ => ScreenItem::Main(self.clone()),
|
_ => View::Main(self.clone()),
|
||||||
},
|
},
|
||||||
_ => ScreenItem::Main(self.clone()),
|
_ => View::Main(self.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
future::ready(new_menu)
|
future::ready(new_menu)
|
||||||
@@ -21,15 +21,15 @@ use embedded_graphics::text::Text;
|
|||||||
use embedded_graphics::text::TextStyleBuilder;
|
use embedded_graphics::text::TextStyleBuilder;
|
||||||
use embedded_graphics_core::draw_target::DrawTarget;
|
use embedded_graphics_core::draw_target::DrawTarget;
|
||||||
|
|
||||||
use super::navigation::Action;
|
use crate::navigation::navigation::{Action, Navigable};
|
||||||
use super::state::ScreenItem;
|
use crate::views::view::View;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct ScanMenu {
|
pub struct ScanMenu {
|
||||||
pub progress: u8, // 0..255
|
pub progress: u8, // 0..255
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::navigation::Navigable for ScanMenu {
|
impl Navigable for ScanMenu {
|
||||||
fn display(
|
fn display(
|
||||||
&self,
|
&self,
|
||||||
display: &mut PrimaryLcdDisplay<'static>,
|
display: &mut PrimaryLcdDisplay<'static>,
|
||||||
@@ -82,14 +82,14 @@ impl super::navigation::Navigable for ScanMenu {
|
|||||||
core::future::ready(())
|
core::future::ready(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = ScreenItem> + Send {
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||||
async move {
|
async move {
|
||||||
let new_progress = match input {
|
let new_progress = match input {
|
||||||
Action::Up => self.progress.wrapping_add(5),
|
Action::Up => self.progress.wrapping_add(5),
|
||||||
_ => self.progress,
|
_ => self.progress,
|
||||||
};
|
};
|
||||||
|
|
||||||
ScreenItem::Scan(ScanMenu {
|
View::Scan(ScanMenu {
|
||||||
progress: new_progress,
|
progress: new_progress,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
use crate::navigation::menu_item;
|
use crate::display::primary_lcd::PrimaryLcdDisplay;
|
||||||
use crate::navigation::state::ScreenItem;
|
|
||||||
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
|
use crate::navigation::navigation::{Action, Navigable};
|
||||||
|
use crate::views::{menu_item, view::View};
|
||||||
|
|
||||||
use embedded_graphics::pixelcolor::Rgb565;
|
use embedded_graphics::pixelcolor::Rgb565;
|
||||||
use embedded_graphics::prelude::RgbColor;
|
use embedded_graphics::prelude::RgbColor;
|
||||||
@@ -12,7 +13,7 @@ pub struct SettingsMenu {
|
|||||||
pub selected: i32,
|
pub selected: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl super::navigation::Navigable for SettingsMenu {
|
impl Navigable for SettingsMenu {
|
||||||
fn display(
|
fn display(
|
||||||
&self,
|
&self,
|
||||||
display: &mut PrimaryLcdDisplay<'static>,
|
display: &mut PrimaryLcdDisplay<'static>,
|
||||||
@@ -24,10 +25,7 @@ impl super::navigation::Navigable for SettingsMenu {
|
|||||||
core::future::ready(())
|
core::future::ready(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_input(
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
||||||
&self,
|
async move { View::Settings(SettingsMenu { selected: 0 }) }
|
||||||
input: super::navigation::Action,
|
|
||||||
) -> impl core::future::Future<Output = ScreenItem> + Send {
|
|
||||||
async move { ScreenItem::Settings(SettingsMenu { selected: 0 }) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
use crate::views::{main_menu::MainMenu, scan_menu::ScanMenu, settings_menu::SettingsMenu};
|
||||||
|
|
||||||
|
use crate::navigation::navigation::Navigable;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum View {
|
||||||
|
Main(MainMenu),
|
||||||
|
Scan(ScanMenu),
|
||||||
|
Settings(SettingsMenu),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Navigable for View {
|
||||||
|
fn display(
|
||||||
|
&self,
|
||||||
|
display: &mut crate::display::primary_lcd::PrimaryLcdDisplay<'static>,
|
||||||
|
) -> impl core::future::Future<Output = ()> + Send {
|
||||||
|
async move {
|
||||||
|
match self {
|
||||||
|
View::Main(main_menu) => main_menu.display(display).await,
|
||||||
|
View::Scan(scan_menu) => scan_menu.display(display).await,
|
||||||
|
View::Settings(settings_menu) => settings_menu.display(display).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_input(
|
||||||
|
&self,
|
||||||
|
input: crate::navigation::navigation::Action,
|
||||||
|
) -> impl core::future::Future<Output = Self> + Send {
|
||||||
|
async move {
|
||||||
|
match self {
|
||||||
|
View::Main(main_menu) => main_menu.handle_input(input).await,
|
||||||
|
View::Scan(scan_menu) => scan_menu.handle_input(input).await,
|
||||||
|
View::Settings(settings_menu) => settings_menu.handle_input(input).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user