A personal rust firmware for the Badger 2040 W
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

sleep and wake up were just not cutting the mustard

+47 -46
+47 -46
src/main.rs
··· 1 1 #![no_std] 2 2 #![no_main] 3 3 4 - use crate::pcf85063a::Control; 4 + use crate::pcf85063a::{Control, Error}; 5 5 use badge_display::display_image::DisplayImage; 6 6 use badge_display::{ 7 7 CHANGE_IMAGE, CURRENT_IMAGE, DISPLAY_CHANGED, FORCE_SCREEN_REFRESH, RECENT_WIFI_NETWORKS, ··· 14 14 use cyw43_pio::{DEFAULT_CLOCK_DIVIDER, PioSpi}; 15 15 use defmt::info; 16 16 use defmt::*; 17 + use embassy_embedded_hal::shared_bus::I2cDeviceError; 17 18 use embassy_embedded_hal::shared_bus::blocking::i2c::I2cDevice; 18 19 use embassy_executor::Spawner; 19 20 use embassy_net::StackResources; ··· 142 143 _ = rtc_device.clear_alarm_flag(); 143 144 } 144 145 146 + // //RTC alarm stuff 147 + // let mut go_to_sleep = false; 148 + // let mut reset_cycles_till_sleep = 0; 149 + // //Like 15ish mins?? 150 + // let sleep_after_cycles = 2; 151 + // 152 + // if rtc_alarm.is_high() { 153 + // //sleep happened 154 + // go_to_sleep = true; 155 + // info!("Alarm went off"); 156 + // _ = rtc_device.disable_all_alarms(); 157 + // _ = rtc_device.clear_alarm_flag(); 158 + // } else { 159 + // info!("Alarm was clear") 160 + // } 161 + 145 162 let spi = Spi::new( 146 163 p.SPI0, 147 164 clk, ··· 174 191 seed, 175 192 ); 176 193 177 - //If the watch dog isn't fed in 60 seconds reboot to help with hang up 194 + //If the watch dog isn't fed in 8 seconds reboot to help with hang up 178 195 watchdog.start(Duration::from_secs(8)); 179 196 180 197 spawner.must_spawn(net_task(runner)); ··· 347 364 //Turn off led to signify that the badge is ready 348 365 // user_led.set_low(); 349 366 350 - //RTC alarm stuff 351 - let mut go_to_sleep = false; 352 - let mut reset_cycles_till_sleep = 0; 353 - //Like 15ish mins?? 354 - let sleep_after_cycles = 4; 355 - 356 - if rtc_alarm.is_high() { 357 - //sleep happened 358 - go_to_sleep = true; 359 - info!("Alarm went off"); 360 - _ = rtc_device.disable_all_alarms(); 361 - _ = rtc_device.clear_alarm_flag(); 362 - } else { 363 - info!("Alarm was clear") 364 - } 365 - 366 367 loop { 367 368 //Keep feeding the dog 368 369 watchdog.feed(); ··· 370 371 //Change Image Button 371 372 if btn_c.is_high() { 372 373 info!("Button C pressed"); 373 - reset_cycles_till_sleep = 0; 374 + // reset_cycles_till_sleep = 0; 374 375 let current_image = CURRENT_IMAGE.load(core::sync::atomic::Ordering::Relaxed); 375 376 let new_image = DisplayImage::from_u8(current_image).unwrap().next(); 376 377 CURRENT_IMAGE.store(new_image.as_u8(), core::sync::atomic::Ordering::Relaxed); ··· 382 383 if btn_a.is_high() { 383 384 println!("{:?}", current_cycle); 384 385 info!("Button A pressed"); 385 - reset_cycles_till_sleep = 0; 386 + // reset_cycles_till_sleep = 0; 386 387 user_led.toggle(); 387 388 Timer::after(Duration::from_millis(500)).await; 388 389 continue; ··· 390 391 391 392 if btn_down.is_high() { 392 393 info!("Button Down pressed"); 393 - reset_cycles_till_sleep = 0; 394 + // reset_cycles_till_sleep = 0; 394 395 SCREEN_TO_SHOW.lock(|screen| { 395 396 screen.replace(Screen::WifiList); 396 397 }); ··· 401 402 402 403 if btn_up.is_high() { 403 404 info!("Button Up pressed"); 404 - reset_cycles_till_sleep = 0; 405 + // reset_cycles_till_sleep = 0; 405 406 SCREEN_TO_SHOW.lock(|screen| { 406 407 screen.replace(Screen::Badge); 407 408 }); ··· 412 413 413 414 if btn_b.is_high() { 414 415 info!("Button B pressed"); 415 - reset_cycles_till_sleep = 0; 416 + // reset_cycles_till_sleep = 0; 416 417 SCREEN_TO_SHOW.lock(|screen| { 417 418 if *screen.borrow() == Screen::Badge { 418 419 //IF on badge screen and b pressed reset wifi count ··· 472 473 473 474 if time_to_scan { 474 475 info!("Scanning for wifi networks"); 475 - reset_cycles_till_sleep += 1; 476 + // reset_cycles_till_sleep += 1; 476 477 time_to_scan = false; 477 478 let mut scanner = control.scan(Default::default()).await; 478 479 while let Some(bss) = scanner.next().await { ··· 487 488 time_to_scan = true; 488 489 } 489 490 490 - if reset_cycles_till_sleep >= sleep_after_cycles { 491 - info!("Going to sleep"); 492 - reset_cycles_till_sleep = 0; 493 - go_to_sleep = true; 494 - } 495 - 496 - if go_to_sleep { 497 - info!("going to sleep"); 498 - //SO i need to wait for 25 seconds to make sure the display updates fully...But i need to keep feeding the dog atleast every 8 seconds 499 - for _ in 0..25 { 500 - watchdog.feed(); 501 - Timer::after(Duration::from_secs(1)).await; 502 - } 503 - //Set the rtc and sleep for 15 minutes 504 - //goes to sleep for 15 mins 505 - _ = rtc_device.disable_all_alarms(); 506 - _ = rtc_device.clear_alarm_flag(); 507 - _ = rtc_device.set_alarm_minutes(15); 508 - _ = rtc_device.control_alarm_minutes(Control::On); 509 - _ = rtc_device.control_alarm_interrupt(Control::On); 510 - power.set_low(); 511 - } 491 + // if reset_cycles_till_sleep >= sleep_after_cycles { 492 + // info!("Going to sleep"); 493 + // reset_cycles_till_sleep = 0; 494 + // go_to_sleep = true; 495 + // } 496 + // 497 + // if go_to_sleep { 498 + // info!("going to sleep"); 499 + // //SO i need to wait for 25 seconds to make sure the display updates fully...But i need to keep feeding the dog atleast every 8 seconds 500 + // for _ in 0..25 { 501 + // //watchdog.feed(); 502 + // Timer::after(Duration::from_secs(1)).await; 503 + // } 504 + // //Set the rtc and sleep for 15 minutes 505 + // //goes to sleep for 15 mins 506 + // _ = rtc_device.disable_all_alarms(); 507 + // _ = rtc_device.clear_alarm_flag(); 508 + // _ = rtc_device.set_alarm_minutes(5); 509 + // _ = rtc_device.control_alarm_minutes(Control::On); 510 + // _ = rtc_device.control_alarm_interrupt(Control::On); 511 + // power.set_low(); 512 + // } 512 513 513 514 current_cycle += 1; 514 515 Timer::after(cycle).await;