108 lines
3.4 KiB
Rust
108 lines
3.4 KiB
Rust
use crate::drivers::primary_lcd::PrimaryDisplayError;
|
|
use crate::navigation::navigation::Action;
|
|
use crate::navigation::navigation::Navigable;
|
|
use crate::navigation::navigation::NewState;
|
|
use crate::navigation::outputs::Outputs;
|
|
use crate::peripherals::Peripherals;
|
|
use crate::peripherals::storage::MAGIC_REGION;
|
|
use crate::peripherals::storage::cardstore::COUNT_REGION;
|
|
use crate::views::view::View;
|
|
use alloc::boxed::Box;
|
|
use core::error;
|
|
use embedded_graphics::prelude::Point;
|
|
use embedded_graphics::{
|
|
Drawable,
|
|
mono_font::{MonoTextStyle, ascii::FONT_10X20},
|
|
pixelcolor::Rgb565,
|
|
prelude::*,
|
|
primitives::Rectangle,
|
|
};
|
|
|
|
use alloc::format;
|
|
use embedded_text::{
|
|
TextBox,
|
|
alignment::HorizontalAlignment,
|
|
style::{HeightMode, TextBoxStyleBuilder},
|
|
};
|
|
#[derive(Debug, Clone)]
|
|
pub struct FlashInfoView {}
|
|
|
|
impl Navigable for FlashInfoView {
|
|
fn display(
|
|
&self,
|
|
outputs: &mut Outputs,
|
|
peripherals: &Peripherals,
|
|
) -> impl core::future::Future<Output = Result<(), Box<dyn error::Error>>> + Send {
|
|
async move {
|
|
outputs
|
|
.primary_display
|
|
.clear(Rgb565::BLACK)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
let _style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
|
let mut magic_bytes: [u8; MAGIC_REGION.size] = [0; MAGIC_REGION.size];
|
|
peripherals
|
|
.store
|
|
.lock()
|
|
.await
|
|
.flash_store
|
|
.read(MAGIC_REGION.offset, &mut magic_bytes)
|
|
.await?;
|
|
let mut card_count_bytes: [u8; COUNT_REGION.size] = [0; COUNT_REGION.size];
|
|
peripherals
|
|
.store
|
|
.lock()
|
|
.await
|
|
.flash_store
|
|
.read(COUNT_REGION.offset, &mut card_count_bytes)
|
|
.await?;
|
|
|
|
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
|
let textbox_style = TextBoxStyleBuilder::new()
|
|
.height_mode(HeightMode::FitToText)
|
|
.alignment(HorizontalAlignment::Justified)
|
|
.build();
|
|
|
|
let display_area = outputs.primary_display.bounding_box();
|
|
let bounds = Rectangle::new(Point::new(0, 30), display_area.size);
|
|
|
|
TextBox::with_textbox_style(
|
|
&format!(
|
|
"
|
|
Flash Init Magic: 0x{:x}\n
|
|
Card Count: {}\n
|
|
",
|
|
u32::from_le_bytes(magic_bytes),
|
|
u32::from_le_bytes(card_count_bytes)
|
|
),
|
|
bounds,
|
|
style,
|
|
textbox_style,
|
|
)
|
|
.draw(&mut outputs.primary_display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send {
|
|
async move {
|
|
let new_menu = View::FlashInfo(self.clone());
|
|
match input {
|
|
Action::Button(_) => NewState {
|
|
replace_view: matches!(new_menu, View::FlashInfo(_)),
|
|
view: new_menu,
|
|
redraw: true,
|
|
},
|
|
Action::Timer => {
|
|
// Skip timer inputs
|
|
NewState {
|
|
view: new_menu,
|
|
replace_view: true,
|
|
redraw: false,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|