From f40c6f21d45a4c903b67f1744a69b2f56312067d Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 3 May 2021 09:30:03 +0800 Subject: [PATCH] fix portduino rtc --- src/gps/RTC.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index 5f6a54c5c..bc7e816cb 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -48,14 +48,22 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv) shouldSet = false; if (shouldSet) { - lastSetMsec = now; -#ifndef NO_ESP32 - settimeofday(tv, NULL); - readFromRTC(); -#else + lastSetMsec = now; + + // This delta value works on all platforms timeStartMsec = now; zeroOffsetSecs = tv->tv_sec; + + // If this platform has a setable RTC, set it +#ifndef NO_ESP32 + settimeofday(tv, NULL); #endif + + // nrf52 doesn't have a readable RTC (yet - software not written) +#if defined(PORTDUINO) || !defined(NO_ESP32) + readFromRTC(); +#endif + return true; } else { return false; @@ -84,7 +92,7 @@ bool perhapsSetRTC(RTCQuality q, struct tm &t) uint32_t getTime() { - return ((millis() - timeStartMsec) / 1000) + zeroOffsetSecs; + return (((uint32_t) millis() - timeStartMsec) / 1000) + zeroOffsetSecs; } uint32_t getValidTime(RTCQuality minQuality)