A personal rust firmware for the Badger 2040 W

Decent enough?

Changed files
+17 -13
src
badge_display
+14 -11
src/badge_display/mod.rs
··· 37 37 //Display state 38 38 pub static SCREEN_TO_SHOW: blocking_mutex::Mutex<CriticalSectionRawMutex, RefCell<Screen>> = 39 39 blocking_mutex::Mutex::new(RefCell::new(Screen::Badge)); 40 + pub static FORCE_SCREEN_REFRESH: AtomicBool = AtomicBool::new(true); 40 41 pub static DISPLAY_CHANGED: AtomicBool = AtomicBool::new(false); 41 42 pub static CURRENT_IMAGE: AtomicU8 = AtomicU8::new(0); 42 43 pub static CHANGE_IMAGE: AtomicBool = AtomicBool::new(true); ··· 91 92 env_value("DETAILS") 92 93 )); 93 94 94 - // \nWritten in rust\nRunning on a pico w"; 95 95 let name_and_detail_box = TextBox::with_textbox_style( 96 96 &display_text, 97 97 name_and_detail_bounds, ··· 99 99 textbox_style, 100 100 ); 101 101 102 - // Draw the text box. 103 - name_and_detail_box.draw(&mut display).unwrap(); 104 - 105 102 // let _ = display.update().await; 106 103 107 104 //Each cycle is half a second 108 105 let cycle: Duration = Duration::from_millis(500); 109 106 110 - let mut first_run = true; 111 107 //New start every 120 cycles or 60 seconds 112 108 let cycles_to_clear_at: i32 = 120; 113 109 let mut cycles_since_last_clear = 0; 114 110 let mut current_screen = Screen::Badge; 115 111 loop { 112 + let mut force_screen_refresh = 113 + FORCE_SCREEN_REFRESH.load(core::sync::atomic::Ordering::Relaxed); 116 114 //Timed based display events 117 115 if DISPLAY_CHANGED.load(core::sync::atomic::Ordering::Relaxed) { 118 116 let clear_rectangle = Rectangle::new(Point::new(0, 0), Size::new(WIDTH, HEIGHT)); ··· 122 120 .unwrap(); 123 121 let _ = display.update().await; 124 122 DISPLAY_CHANGED.store(false, core::sync::atomic::Ordering::Relaxed); 125 - first_run = true; 123 + force_screen_refresh = true; 126 124 } 127 125 128 126 SCREEN_TO_SHOW.lock(|x| current_screen = *x.borrow()); 129 127 info!("Current Screen: {:?}", current_screen); 130 128 if current_screen == Screen::Badge { 129 + if force_screen_refresh { 130 + // Draw the text box. 131 + name_and_detail_box.draw(&mut display).unwrap(); 132 + } 133 + 131 134 //Updates the top bar 132 135 //Runs every 60 cycles/30 seconds and first run 133 - if cycles_since_last_clear % 60 == 0 || first_run { 136 + if cycles_since_last_clear % 60 == 0 || force_screen_refresh { 134 137 let count = WIFI_COUNT.load(core::sync::atomic::Ordering::Relaxed); 135 138 let temp = TEMP.load(core::sync::atomic::Ordering::Relaxed); 136 139 let humidity = HUMIDITY.load(core::sync::atomic::Ordering::Relaxed); ··· 165 168 } 166 169 167 170 //Runs every 120 cycles/60 seconds and first run 168 - if cycles_since_last_clear == 0 || first_run { 171 + if cycles_since_last_clear == 0 || force_screen_refresh { 169 172 let mut time_text: String<8> = String::<8>::new(); 170 173 171 174 let time_box_rectangle_location = Point::new(0, 96); ··· 212 215 213 216 //Manually triggered display events 214 217 215 - if CHANGE_IMAGE.load(core::sync::atomic::Ordering::Relaxed) || first_run { 218 + if CHANGE_IMAGE.load(core::sync::atomic::Ordering::Relaxed) || force_screen_refresh { 216 219 let current_image = get_current_image(); 217 220 let tga: Bmp<BinaryColor> = Bmp::from_slice(&current_image.image()).unwrap(); 218 221 let image = Image::new(&tga, current_image.image_location()); ··· 232 235 CHANGE_IMAGE.store(false, core::sync::atomic::Ordering::Relaxed); 233 236 } 234 237 } else { 235 - if cycles_since_last_clear % 60 == 0 || first_run { 238 + if cycles_since_last_clear % 60 == 0 || force_screen_refresh { 236 239 let top_bounds = Rectangle::new(Point::new(0, 0), Size::new(WIDTH, 24)); 237 240 top_bounds 238 241 .into_styled( ··· 268 271 if cycles_since_last_clear >= cycles_to_clear_at { 269 272 cycles_since_last_clear = 0; 270 273 } 271 - first_run = false; 274 + FORCE_SCREEN_REFRESH.store(false, core::sync::atomic::Ordering::Relaxed); 272 275 // info!("Display Cycle: {}", cycles_since_last_clear); 273 276 Timer::after(cycle).await; 274 277 }
+3 -2
src/main.rs
··· 6 6 #![no_main] 7 7 use badge_display::display_image::DisplayImage; 8 8 use badge_display::{ 9 - run_the_display, Screen, CHANGE_IMAGE, CURRENT_IMAGE, DISPLAY_CHANGED, RTC_TIME_STRING, 10 - SCREEN_TO_SHOW, WIFI_COUNT, 9 + run_the_display, Screen, CHANGE_IMAGE, CURRENT_IMAGE, DISPLAY_CHANGED, FORCE_SCREEN_REFRESH, 10 + RTC_TIME_STRING, SCREEN_TO_SHOW, WIFI_COUNT, 11 11 }; 12 12 use core::fmt::Write; 13 13 use core::str::from_utf8; ··· 319 319 save.wifi_counted = 0; 320 320 save.bssid.clear(); 321 321 WIFI_COUNT.store(0, core::sync::atomic::Ordering::Relaxed); 322 + FORCE_SCREEN_REFRESH.store(true, core::sync::atomic::Ordering::Relaxed); 322 323 Timer::after(Duration::from_millis(500)).await; 323 324 current_cycle += 500; 324 325 continue;