From 894d4b955c7d60b24cb9188b3a7cb7f68f42dc73 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 27 Jan 2016 20:33:54 -0800 Subject: [PATCH] Unclever first attempt at display sleep. --- firmware/application/event_m0.cpp | 26 ++++++++++++++------------ firmware/application/event_m0.hpp | 8 ++++++++ firmware/application/main.cpp | 5 +++++ firmware/application/ui_navigation.cpp | 7 +++++++ firmware/application/ui_navigation.hpp | 5 +++++ firmware/common/message.hpp | 9 +++++++++ 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 6e889771..df694bb5 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -98,21 +98,23 @@ void EventDispatcher::dispatch(const eventmask_t events) { if( events & EVT_MASK_RTC_TICK ) { handle_rtc_tick(); } + + if( !display_sleep ) { + if( events & EVT_MASK_LCD_FRAME_SYNC ) { + handle_lcd_frame_sync(); + } - if( events & EVT_MASK_LCD_FRAME_SYNC ) { - handle_lcd_frame_sync(); - } + if( events & EVT_MASK_SWITCHES ) { + handle_switches(); + } - if( events & EVT_MASK_SWITCHES ) { - handle_switches(); - } + if( events & EVT_MASK_ENCODER ) { + handle_encoder(); + } - if( events & EVT_MASK_ENCODER ) { - handle_encoder(); - } - - if( events & EVT_MASK_TOUCH ) { - handle_touch(); + if( events & EVT_MASK_TOUCH ) { + handle_touch(); + } } } diff --git a/firmware/application/event_m0.hpp b/firmware/application/event_m0.hpp index 1409ceb7..38eea566 100644 --- a/firmware/application/event_m0.hpp +++ b/firmware/application/event_m0.hpp @@ -27,6 +27,8 @@ #include "ui_widget.hpp" #include "ui_painter.hpp" +#include "portapack.hpp" + #include "message.hpp" #include "touch.hpp" @@ -53,6 +55,11 @@ public: void run(); void request_stop(); + void set_display_sleep(bool new_value) { + portapack::io.lcd_backlight(false); + display_sleep = new_value; + }; + static inline void events_flag(const eventmask_t events) { if( thread_event_loop ) { chEvtSignal(thread_event_loop, events); @@ -80,6 +87,7 @@ private: uint32_t encoder_last = 0; bool is_running = true; bool sd_card_present = false; + bool display_sleep = false; eventmask_t wait(); void dispatch(const eventmask_t events); diff --git a/firmware/application/main.cpp b/firmware/application/main.cpp index d9900426..a3674ab7 100755 --- a/firmware/application/main.cpp +++ b/firmware/application/main.cpp @@ -81,6 +81,11 @@ int main(void) { event_dispatcher.request_stop(); } ); + EventDispatcher::message_map().register_handler(Message::ID::DisplaySleep, + [&event_dispatcher](const Message* const) { + event_dispatcher.set_display_sleep(true); + } + ); m4_init(portapack::spi_flash::baseband, portapack::memory::map::m4_code); diff --git a/firmware/application/ui_navigation.cpp b/firmware/application/ui_navigation.cpp index e2c76b6c..6a21d215 100644 --- a/firmware/application/ui_navigation.cpp +++ b/firmware/application/ui_navigation.cpp @@ -22,6 +22,7 @@ #include "ui_navigation.hpp" #include "portapack.hpp" +#include "event_m0.hpp" #include "receiver_model.hpp" #include "ui_setup.hpp" @@ -42,6 +43,7 @@ SystemStatusView::SystemStatusView() { add_children({ { &button_back, &title, + &button_sleep, &sd_card_status_view, } }); sd_card_status_view.set_parent_rect({ 28 * 8, 0 * 16, 2 * 8, 1 * 16 }); @@ -51,6 +53,11 @@ SystemStatusView::SystemStatusView() { this->on_back(); } }; + + button_sleep.on_select = [this](Button&) { + DisplaySleepMessage message; + EventDispatcher::message_map().send(&message); + }; } void SystemStatusView::set_back_visible(bool new_value) { diff --git a/firmware/application/ui_navigation.hpp b/firmware/application/ui_navigation.hpp index 5dab355b..a0c0ce04 100644 --- a/firmware/application/ui_navigation.hpp +++ b/firmware/application/ui_navigation.hpp @@ -59,6 +59,11 @@ private: default_title, }; + Button button_sleep { + { 25 * 8, 0, 2 * 8, 1 * 16 }, + "ZZ", + }; + SDCardStatusView sd_card_status_view; }; diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index 66eebbc5..5c823938 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -58,6 +58,7 @@ public: AMConfigure = 13, ChannelSpectrumConfig = 14, SpectrumStreamingConfig = 15, + DisplaySleep = 16, MAX }; @@ -165,6 +166,14 @@ struct AudioStatistics { } }; +class DisplaySleepMessage : public Message { +public: + constexpr DisplaySleepMessage( + ) : Message { ID::DisplaySleep } + { + } +}; + class AudioStatisticsMessage : public Message { public: constexpr AudioStatisticsMessage(