fix RTC and time display

This commit is contained in:
liquidraver committed 2026-06-09 14:46:30 +02:00
1 parent a43f46f942
commit 5564dcbde0
3 files changed
+52 -13

No files matched your search

+11
View File
@@ -9,6 +9,7 @@
*/
#include <time_sync.h>
#include <adapters/gps/ZephyrGPSManager.h>
#include <zephyr/kernel.h>
static enum time_sync_source s_last = TIME_SYNC_NONE;
@@ -22,6 +23,16 @@ void time_sync_report(enum time_sync_source src)
enum time_sync_source time_sync_get_source(void)
{
/* Live GPS hold is authoritative and uses the SAME signal that blocks
* phone time-sync (gps_has_time_sync(), expires 2h after the last fix),
* so the tag can never disagree with that policy: while GPS holds the
* clock the tag is G regardless of the freshness window below. After a
* reboot the flag is reset, so this returns false and we fall through to
* the local/freshness logic (→ L until something re-syncs). */
if (gps_has_time_sync()) {
return TIME_SYNC_GPS;
}
/* Local/manual (CLI) and "never synced" are both just local time. */
if (s_last == TIME_SYNC_NONE || s_last == TIME_SYNC_CLI) {
return TIME_SYNC_CLI;
+21
View File
@@ -25,6 +25,7 @@
#include "ui_task.h"
#include "ui_pages.h"
#include <time_sync.h>
#ifdef CONFIG_ZEPHCORE_UI_BUZZER
#include "buzzer.h"
@@ -909,8 +910,28 @@ void ui_set_battery(uint16_t mv, uint8_t pct)
void ui_set_clock(uint32_t epoch)
{
struct ui_state *s = get_state();
static enum time_sync_source last_src = TIME_SYNC_NONE;
/* 1735689600 = 2025-01-01: the same "time is set" threshold the top-bar
* renderer uses. The clock only becomes visible once epoch crosses it. */
bool was_valid = s->rtc_epoch > 1735689600;
bool now_valid = epoch > 1735689600;
s->rtc_epoch = epoch;
/* Repaint the EPD (which only redraws on demand) when the visible top-bar
* clock/source-tag changes, so the user never has to change pages to see
* an update. Both transitions are picked up on the next housekeeping tick:
* - clock first becomes valid → boot RTC restore / first sync
* - source tag changes → L→A (app), →G (GPS fix), A→L (12h expiry)
* Steady state triggers nothing (epoch valid + source unchanged). */
enum time_sync_source src = time_sync_get_source();
bool source_changed = (src != last_src);
last_src = src;
if (now_valid && (!was_valid || source_changed)) {
schedule_render();
}
}
void ui_add_recent(const char *name, int16_t rssi, uint32_t age_s)