From 7fb3888b939b073bc5fba2dd1a1711edc507271d Mon Sep 17 00:00:00 2001 From: 3djc Date: Mon, 29 Jul 2024 12:13:47 +0200 Subject: [PATCH] feat(bw): do not show time on main view when RTC not set (#5342) --- radio/src/gui/128x64/view_main.cpp | 4 ++-- radio/src/gui/212x64/view_main.cpp | 2 +- radio/src/rtc.cpp | 13 +++++++++++++ radio/src/rtc.h | 1 + 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/radio/src/gui/128x64/view_main.cpp b/radio/src/gui/128x64/view_main.cpp index fccd54322..c82e868ec 100644 --- a/radio/src/gui/128x64/view_main.cpp +++ b/radio/src/gui/128x64/view_main.cpp @@ -674,13 +674,13 @@ void menuMainView(event_t event) lcdDrawText(15 * FW, 0, "BIND", 0); } #if defined(RTCLOCK) - else if (view_base != VIEW_CHAN_MONITOR) { + else if (view_base != VIEW_CHAN_MONITOR && rtcIsValid()) { drawRtcTime(CLOCK_X, CLOCK_Y, LEFT|TIMEBLINK); } #endif #else #if defined(RTCLOCK) - if (view_base != VIEW_CHAN_MONITOR) { + if (view_base != VIEW_CHAN_MONITOR && rtcIsValid()) { drawRtcTime(CLOCK_X, CLOCK_Y, LEFT|TIMEBLINK); } #endif diff --git a/radio/src/gui/212x64/view_main.cpp b/radio/src/gui/212x64/view_main.cpp index dc70467eb..c6dfadc35 100644 --- a/radio/src/gui/212x64/view_main.cpp +++ b/radio/src/gui/212x64/view_main.cpp @@ -335,7 +335,7 @@ void displayTopBar() LCD_ICON(BAR_VOLUME_X, BAR_Y, ICON_SPEAKER3); /* RTC time */ - drawRtcTime(BAR_TIME_X, BAR_Y+1, LEFT|TIMEBLINK); + if (rtcIsValid()) drawRtcTime(BAR_TIME_X, BAR_Y+1, LEFT|TIMEBLINK); /* The background */ lcdDrawFilledRect(BAR_X, BAR_Y, BAR_W, BAR_H, SOLID, FILL_WHITE|GREY(12)|ROUND); diff --git a/radio/src/rtc.cpp b/radio/src/rtc.cpp index 52f44518f..806e9ce6f 100644 --- a/radio/src/rtc.cpp +++ b/radio/src/rtc.cpp @@ -493,3 +493,16 @@ uint8_t rtcAdjust(uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t } return 0; } + +bool rtcIsValid() +{ + struct gtm t; + gettime(&t); + + // If year is 2000, rtc circuit aren't working + // No RTC battery or other issue + if (t.tm_year <= 100) + return false; + + return true; +} diff --git a/radio/src/rtc.h b/radio/src/rtc.h index 2c3b1a3e6..471a08ded 100644 --- a/radio/src/rtc.h +++ b/radio/src/rtc.h @@ -50,6 +50,7 @@ struct gtm extern gtime_t g_rtcTime; extern uint8_t g_ms100; // global to allow time set function to reset to zero +bool rtcIsValid(); void rtcInit(); void rtcSetTime(const struct gtm * tm); gtime_t gmktime (struct gtm *tm);