display views: return error instead of unwrapping

This commit was merged in pull request #49.
This commit is contained in:
2026-08-29 21:09:09 +00:00
parent ef10eec216
commit 153acffb86
9 changed files with 114 additions and 40 deletions
+49 -8
View File
@@ -1,21 +1,30 @@
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::mono_font::MonoTextStyle;
use embedded_graphics::mono_font::ascii::FONT_10X20;
use embedded_graphics::pixelcolor::Rgb565;
use embedded_graphics::prelude::DrawTarget;
use embedded_graphics::prelude::RgbColor;
use embedded_graphics::text::Text;
use embedded_graphics::prelude::Point;
use embedded_graphics::{
Drawable,
mono_font::{MonoTextStyle, ascii::FONT_10X20},
pixelcolor::Rgb565,
prelude::*,
primitives::Rectangle,
text::Text,
};
use alloc::format;
use embedded_text::{
TextBox,
alignment::HorizontalAlignment,
style::{HeightMode, TextBoxStyleBuilder},
};
#[derive(Debug, Clone)]
pub struct FlashInfoView {}
@@ -35,7 +44,39 @@ impl Navigable for FlashInfoView {
.flash_store
.read(MAGIC_REGION.offset, &mut magic_bytes)
.await?;
Text::new("Flash Initialized: {:?}", Point::new(40, 40), style);
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::Center)
.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(())
}
}