From 083263e19e1c72225dfb3c00863222be63b725c5 Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Sat, 28 Dec 2024 19:05:58 +0100 Subject: [PATCH] Successfully render custom menu --- Cargo.toml | 2 ++ src/main.rs | 81 ++++------------------------------------------------- 2 files changed, 8 insertions(+), 75 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d6ca532..3294fe8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,5 +35,7 @@ embedded-graphics = "0.8.1" ili9341 = "0.6.0" display-interface-spi = "0.5.0" +gui = { path="../gui/" } + [profile.release] debug = 2 diff --git a/src/main.rs b/src/main.rs index 9e7eec9..8db1388 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use embedded_graphics::{ }, text::{Alignment, Text}, }; +use gui::*; // Setup interrupts bind_interrupts!(struct Irqs { @@ -49,79 +50,6 @@ async fn blink(pin: AnyPin, blink_delay: Duration) -> ! { } } -/// Create a function to run the demo -/// -/// # Arguments -/// This function takes in a variable of a generic type `D`. -/// With the restriction that the generic type `D` implements -/// `DrawTarget`, aka that it is a display. -/// -/// I've also said it needs to use a certain colormode, because -/// that is the color mode I use in the demo. -/// -/// While this may seem a little clunky this function now accepts _any_ -/// display as long as it uses the standard 565 colormode. -/// -/// # Returns -/// The function returns a `Result` containing either an empty tuple -/// or the error type associated with the generic type `D`. -fn display_demo(display: &mut D) -> Result<(), D::Error> -where - D: DrawTarget, -{ - display.clear(Rgb565::CSS_DARK_OLIVE_GREEN)?; - - // Create styles used by the drawing operations. - let thin_stroke = PrimitiveStyle::with_stroke(Rgb565::WHITE, 1); - let thick_stroke = PrimitiveStyle::with_stroke(Rgb565::WHITE, 3); - let border_stroke = PrimitiveStyleBuilder::new() - .stroke_color(Rgb565::WHITE) - .stroke_width(3) - .stroke_alignment(StrokeAlignment::Inside) - .build(); - let fill = PrimitiveStyle::with_fill(Rgb565::WHITE); - let character_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE); - - let yoffset = 10; - - // Draw a 3px wide outline around the display. - display - .bounding_box() - .into_styled(border_stroke) - .draw(display)?; - - // Draw a triangle. - Triangle::new( - Point::new(16, 16 + yoffset), - Point::new(16 + 16, 16 + yoffset), - Point::new(16 + 8, yoffset), - ) - .into_styled(thin_stroke) - .draw(display)?; - - // Draw a filled square - Rectangle::new(Point::new(52, yoffset), Size::new(16, 16)) - .into_styled(fill) - .draw(display)?; - - // Draw a circle with a 3px wide stroke. - Circle::new(Point::new(88, yoffset), 17) - .into_styled(thick_stroke) - .draw(display)?; - - // Draw centered text. - let text = "embedded-graphics"; - Text::with_alignment( - text, - display.bounding_box().center() + Point::new(0, 15), - character_style, - Alignment::Center, - ) - .draw(display)?; - - Ok(()) -} - #[embassy_executor::main] async fn main(spawner: Spawner) { // Initialize the nRF @@ -177,7 +105,7 @@ async fn main(spawner: Spawner) { //////////////////////// // Some options for the display - let display_orientation = ili9341::Orientation::Landscape; + let display_orientation = ili9341::Orientation::PortraitFlipped; let display_size = ili9341::DisplaySize240x320; // Create the display @@ -190,9 +118,12 @@ async fn main(spawner: Spawner) { ) .unwrap(); + // Create the GUI + let mut gui = Gui::new(display); + gui.draw().unwrap(); + // Now loop, re-running the demo every second loop { - display_demo(&mut display).expect("Failed to run display demo"); Timer::after_secs(1).await; } }