diff --git a/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp b/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp index b935adb4564..6f22793b348 100644 --- a/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp +++ b/radio/src/gui/colorlcd/layouts/layout_factory_impl.cpp @@ -53,21 +53,6 @@ void Layout::paint(BitmapBuffer * dc) } #endif -void Layout::checkEvents() -{ - LayoutBase::checkEvents(); - adjustLayout(); - -// uint32_t now = RTOS_GET_MS(); -// if (now - lastRefresh >= LAYOUT_REFRESH) { -// lastRefresh = now; -// invalidate(); -// #if defined(DEBUG_WINDOWS) -// TRACE_WINDOWS("# %s refresh: %s", factory->getId(), getWindowDebugString().c_str()); -// #endif -// } -} - void Layout::setTrimsVisible(bool visible) { decoration->setTrimsVisible(visible); diff --git a/radio/src/gui/colorlcd/layouts/layout_factory_impl.h b/radio/src/gui/colorlcd/layouts/layout_factory_impl.h index b2e043c5972..3b9b2c75e88 100644 --- a/radio/src/gui/colorlcd/layouts/layout_factory_impl.h +++ b/radio/src/gui/colorlcd/layouts/layout_factory_impl.h @@ -79,8 +79,6 @@ class Layout: public LayoutBase { return factory; } - - void checkEvents() override; bool hasTopbar() const { return getOptionValue(LAYOUT_OPTION_TOPBAR)->boolValue; diff --git a/radio/src/gui/colorlcd/layouts/topbar_impl.cpp b/radio/src/gui/colorlcd/layouts/topbar_impl.cpp index 474855672b9..82a8ba5c180 100644 --- a/radio/src/gui/colorlcd/layouts/topbar_impl.cpp +++ b/radio/src/gui/colorlcd/layouts/topbar_impl.cpp @@ -88,7 +88,7 @@ void TopBar::checkEvents() uint32_t now = RTOS_GET_MS(); if (now - lastRefresh >= TOPBAR_REFRESH) { lastRefresh = now; - invalidate(); + TopBarBase::checkEvents(); } } diff --git a/radio/src/gui/colorlcd/widgets/radio_info.cpp b/radio/src/gui/colorlcd/widgets/radio_info.cpp index c2e4f9a2c2e..8a0faee85c7 100644 --- a/radio/src/gui/colorlcd/widgets/radio_info.cpp +++ b/radio/src/gui/colorlcd/widgets/radio_info.cpp @@ -23,6 +23,8 @@ #include "widgets_container_impl.h" #include "theme.h" +constexpr uint32_t WIDGET_REFRESH = 1000 / 10; // 10 Hz + #define W_AUDIO_X 0 #define W_USB_X 32 #define W_LOG_X 32 @@ -84,14 +86,34 @@ STATIC_LZ4_BITMAP(LBM_TOPMENU_TXBATT); STATIC_LZ4_BITMAP(LBM_TOPMENU_TXBATT_CHARGING); STATIC_LZ4_BITMAP(LBM_TOPMENU_ANTENNA); -class RadioInfoWidget: public Widget +class TopBarWidget : public Widget { - protected: + public: + TopBarWidget(const WidgetFactory* factory, Window* parent, + const rect_t& rect, Widget::PersistentData* persistentData) : + Widget(factory, parent, rect, persistentData) + { + } + + void checkEvents() override + { + Widget::checkEvents(); + uint32_t now = RTOS_GET_MS(); + if (now - lastRefresh >= WIDGET_REFRESH) { + lastRefresh = now; + invalidate(); + } + } + + uint32_t lastRefresh = 0; +}; +class RadioInfoWidget: public TopBarWidget +{ public: RadioInfoWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect, Widget::PersistentData* persistentData) : - Widget(factory, parent, rect, persistentData) + TopBarWidget(factory, parent, rect, persistentData) { } @@ -159,14 +181,6 @@ class RadioInfoWidget: public Widget dc->drawSolidFilledRect(W_AUDIO_X + 2 + 4 * i, 27, 2, 8, i >= bars ? COLOR_THEME_PRIMARY3 : COLOR_THEME_PRIMARY2); } } - - void checkEvents() override - { - Widget::checkEvents(); - invalidate(); - } - - static const ZoneOption options[]; }; BaseWidgetFactory RadioInfoWidget("Radio Info", nullptr, "Radio Info"); @@ -178,14 +192,12 @@ BaseWidgetFactory RadioInfoWidget("Radio Info", nullptr, "Radio #define DT_OFFSET 1 #endif -class DateTimeWidget: public Widget +class DateTimeWidget: public TopBarWidget { - protected: - public: DateTimeWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect, Widget::PersistentData* persistentData) : - Widget(factory, parent, rect, persistentData) + TopBarWidget(factory, parent, rect, persistentData) { } @@ -199,9 +211,17 @@ class DateTimeWidget: public Widget void checkEvents() override { Widget::checkEvents(); - invalidate(); + // Only update if minute value has changed + struct gtm t; + gettime(&t); + if (t.tm_min != lastMinute) { + lastMinute = t.tm_min; + invalidate(); + } } + int8_t lastMinute = 0; + static const ZoneOption options[]; }; @@ -220,14 +240,12 @@ static const uint8_t _LBM_TOPMENU_GPS[] = { STATIC_LZ4_BITMAP(LBM_TOPMENU_GPS); -class InternalGPSWidget: public Widget +class InternalGPSWidget: public TopBarWidget { - protected: - public: InternalGPSWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect, Widget::PersistentData* persistentData) : - Widget(factory, parent, rect, persistentData) + TopBarWidget(factory, parent, rect, persistentData) { } @@ -244,14 +262,6 @@ class InternalGPSWidget: public Widget (gpsData.fix) ? COLOR_THEME_PRIMARY2 : COLOR_THEME_PRIMARY3); } } - - void checkEvents() override - { - Widget::checkEvents(); - invalidate(); - } - - static const ZoneOption options[]; }; BaseWidgetFactory InternalGPSWidget("Internal GPS", nullptr, "Internal GPS"); diff --git a/radio/src/gui/colorlcd/widgets/widgets_container_impl.h b/radio/src/gui/colorlcd/widgets/widgets_container_impl.h index 238b715ad98..6b9afab1cf8 100644 --- a/radio/src/gui/colorlcd/widgets/widgets_container_impl.h +++ b/radio/src/gui/colorlcd/widgets/widgets_container_impl.h @@ -115,6 +115,7 @@ class WidgetsContainerImpl : public WidgetsContainer inline void setOptionValue(unsigned int index, const ZoneOptionValue& value) { persistentData->options[index].value = value; + adjustLayout(); } unsigned int getZonesCount() const override = 0;