@@ -16,9 +16,20 @@ use rp2040_hal::{
1616//use panic_probe as _;
1717use rp2040_panic_usb_boot as _;
1818
19+ #[ derive( PartialEq , Eq ) ]
20+ #[ allow( dead_code) ]
21+ enum SleepMode {
22+ /// Instantly go to sleep ant
23+ Instant ,
24+ /// Fade brightness out and in slowly when sleeping/waking-up
25+ Fading ,
26+ // Display "SLEEP" when sleeping, instead of turning LEDs off
27+ Debug ,
28+ }
29+
1930/// Static configuration whether sleep shohld instantly turn all LEDs on/off or
2031/// slowly fade themm on/off
21- const INSTANT_SLEEP : bool = false ;
32+ const SLEEP_MODE : SleepMode = SleepMode :: Fading ;
2233
2334const MAX_CURRENT : usize = 500 ;
2435
@@ -395,8 +406,7 @@ fn handle_sleep(
395406 // fill_grid_pixels(&state, matrix);
396407
397408 // Slowly decrease brightness
398- if !INSTANT_SLEEP {
399- delay. delay_ms ( 1000 ) ;
409+ if SLEEP_MODE == SleepMode :: Fading {
400410 let mut brightness = state. brightness ;
401411 loop {
402412 delay. delay_ms ( 100 ) ;
@@ -409,7 +419,12 @@ fn handle_sleep(
409419 }
410420
411421 // Turn LED controller off to save power
412- led_enable. set_low ( ) . unwrap ( ) ;
422+ if SLEEP_MODE == SleepMode :: Debug {
423+ state. grid = display_sleep ( ) ;
424+ fill_grid_pixels ( state, matrix) ;
425+ } else {
426+ led_enable. set_low ( ) . unwrap ( ) ;
427+ }
413428
414429 // TODO: Set up SLEEP# pin as interrupt and wfi
415430 //cortex_m::asm::wfi();
@@ -422,11 +437,12 @@ fn handle_sleep(
422437 fill_grid_pixels ( state, matrix) ;
423438
424439 // Power LED controller back on
425- led_enable. set_high ( ) . unwrap ( ) ;
440+ if SLEEP_MODE != SleepMode :: Debug {
441+ led_enable. set_high ( ) . unwrap ( ) ;
442+ }
426443
427444 // Slowly increase brightness
428- if !INSTANT_SLEEP {
429- delay. delay_ms ( 1000 ) ;
445+ if SLEEP_MODE == SleepMode :: Fading {
430446 let mut brightness = 0 ;
431447 loop {
432448 delay. delay_ms ( 100 ) ;
0 commit comments