diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index df694bb5..dc557397 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -86,6 +86,19 @@ void EventDispatcher::request_stop() { is_running = false; } +void EventDispatcher::set_display_sleep(const bool sleep) { + // TODO: Distribute display sleep message more broadly, shut down data generation + // on baseband side, since all that data is being discarded during sleep. + if( sleep ) { + portapack::io.lcd_backlight(false); + portapack::display.sleep(); + } else { + portapack::display.wake(); + portapack::io.lcd_backlight(true); + } + display_sleep = sleep; +}; + eventmask_t EventDispatcher::wait() { return chEvtWaitAny(ALL_EVENTS); } @@ -99,15 +112,15 @@ void EventDispatcher::dispatch(const eventmask_t events) { handle_rtc_tick(); } + if( events & EVT_MASK_SWITCHES ) { + handle_switches(); + } + if( !display_sleep ) { if( events & EVT_MASK_LCD_FRAME_SYNC ) { handle_lcd_frame_sync(); } - if( events & EVT_MASK_SWITCHES ) { - handle_switches(); - } - if( events & EVT_MASK_ENCODER ) { handle_encoder(); } @@ -181,6 +194,15 @@ void EventDispatcher::handle_lcd_frame_sync() { void EventDispatcher::handle_switches() { const auto switches_state = get_switches_state(); + + if( display_sleep ) { + // Swallow event, wake up display. + if( switches_state.any() ) { + set_display_sleep(false); + } + return; + } + for(size_t i=0; i