A personal rust firmware for the Badger 2040 W

Clean up and helper for formatting text

Changed files
+48 -4
src
+2
.env.save
··· 1 + NAME="Bailey Townsend" 2 + DETAILS="Software Dev"
+12 -4
src/badge_display/mod.rs
··· 28 28 use uc8151::{asynch::Uc8151, UpdateRegion}; 29 29 use {defmt_rtt as _, panic_probe as _}; 30 30 31 - use crate::Spi0Bus; 31 + use crate::{env::env_value, helpers::easy_format, Spi0Bus}; 32 32 33 33 //Display state 34 34 pub static CURRENT_IMAGE: AtomicU8 = AtomicU8::new(0); ··· 72 72 .unwrap(); 73 73 74 74 // Create the text box and apply styling options. 75 + let display_text = easy_format::<29>(format_args!( 76 + "{}\n{}", 77 + env_value("NAME"), 78 + env_value("DETAILS") 79 + )); 75 80 76 - let text = "Bailey Townsend\nSoftware Dev"; 77 81 // \nWritten in rust\nRunning on a pico w"; 78 - let name_and_detail_box = 79 - TextBox::with_textbox_style(text, name_and_detail_bounds, character_style, textbox_style); 82 + let name_and_detail_box = TextBox::with_textbox_style( 83 + &display_text, 84 + name_and_detail_bounds, 85 + character_style, 86 + textbox_style, 87 + ); 80 88 81 89 // Draw the text box. 82 90 name_and_detail_box.draw(&mut display).unwrap();
+18
src/env.rs
··· 1 + use heapless::Vec; 2 + 3 + const ENV_DATA: &str = include_str!("../.env"); 4 + 5 + pub fn env_value(key: &str) -> &'static str { 6 + for line in ENV_DATA.lines() { 7 + let parts: Vec<&str, 2> = line.split('=').collect(); 8 + if parts.len() == 2 { 9 + if parts[0].trim() == key { 10 + let mut value = parts[1].trim().chars(); 11 + value.next(); 12 + value.next_back(); 13 + return value.as_str(); 14 + } 15 + } 16 + } 17 + panic!("Key: {:?} not found in .env file. May also need to provide your own .env from a copy of .env.save", key); 18 + }
+14
src/helpers.rs
··· 1 + use core::fmt::Arguments; 2 + use heapless::String; 3 + 4 + /// Makes it easier to format strings in a single line method 5 + pub fn easy_format<const N: usize>(args: Arguments<'_>) -> String<N> { 6 + let mut formatted_string: String<N> = String::<N>::new(); 7 + let result = core::fmt::write(&mut formatted_string, args); 8 + match result { 9 + Ok(_) => formatted_string, 10 + Err(_) => { 11 + panic!("Error formatting the string") 12 + } 13 + } 14 + }
+2
src/main.rs
··· 34 34 35 35 mod badge_display; 36 36 mod cyw43_driver; 37 + mod env; 38 + mod helpers; 37 39 38 40 type Spi0Bus = Mutex<NoopRawMutex, Spi<'static, SPI0, spi::Async>>; 39 41