Experimental code to allow timer resyncing after NTP resync
Some checks are pending
Compile / Compile (push) Has started running
Some checks are pending
Compile / Compile (push) Has started running
This commit is contained in:
parent
3ada2fb9a9
commit
5367843ac1
3 changed files with 33 additions and 12 deletions
|
@ -269,6 +269,7 @@ void WatchFace::MenuNTPSyncSelected()
|
||||||
ConnectWiFi();
|
ConnectWiFi();
|
||||||
SyncNTPTime();
|
SyncNTPTime();
|
||||||
DisconnectWiFi();
|
DisconnectWiFi();
|
||||||
|
m_RTC.Resync();
|
||||||
|
|
||||||
if (m_inMenu) {
|
if (m_inMenu) {
|
||||||
m_inMenu = false;
|
m_inMenu = false;
|
||||||
|
|
|
@ -13,10 +13,6 @@ WatchyRTC::WatchyRTC()
|
||||||
|
|
||||||
void WatchyRTC::Init()
|
void WatchyRTC::Init()
|
||||||
{
|
{
|
||||||
tmElements_t tm;
|
|
||||||
Get(tm, 0);
|
|
||||||
rtc_pcf.initClock();
|
|
||||||
Set(tm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WatchyRTC::Get(tmElements_t & tm, int offsetInSeconds)
|
void WatchyRTC::Get(tmElements_t & tm, int offsetInSeconds)
|
||||||
|
@ -43,14 +39,7 @@ void WatchyRTC::Set(tmElements_t tm)
|
||||||
void WatchyRTC::SetTimer()
|
void WatchyRTC::SetTimer()
|
||||||
{
|
{
|
||||||
if (!m_timerSet) {
|
if (!m_timerSet) {
|
||||||
rtc_pcf.getDateTime();
|
Resync();
|
||||||
// Sleep just long enough to get to a multiple of the update interval, makes updates happen on exact turn of the minute
|
|
||||||
int seconds = UPDATE_INTERVAL - (rtc_pcf.getSecond() % UPDATE_INTERVAL);
|
|
||||||
|
|
||||||
// Non repeating
|
|
||||||
rtc_pcf.setTimer(seconds, TMR_1Hz, false);
|
|
||||||
m_timerSet = true;
|
|
||||||
m_initialTimer = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,10 +122,40 @@ bool WatchyRTC::CheckWakeup()
|
||||||
interval = UPDATE_INTERVAL;
|
interval = UPDATE_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timer doesn't work reliably unless it's cleared first
|
||||||
|
rtc_pcf.clearTimer();
|
||||||
rtc_pcf.setTimer(interval, frequency, true);
|
rtc_pcf.setTimer(interval, frequency, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WatchyRTC::Resync()
|
||||||
|
{
|
||||||
|
rtc_pcf.getDateTime();
|
||||||
|
// Sleep just long enough to get to a multiple of the update interval, makes updates happen on exact turn of the minute
|
||||||
|
int seconds = UPDATE_INTERVAL - (rtc_pcf.getSecond() % UPDATE_INTERVAL);
|
||||||
|
|
||||||
|
if (seconds < 0) {
|
||||||
|
seconds = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timer doesn't work reliably unless it's cleared first
|
||||||
|
rtc_pcf.clearTimer();
|
||||||
|
|
||||||
|
if (seconds == 0) {
|
||||||
|
// If there's no time to wait, just call CheckWakeup() immediately and it'll set the repeating timer
|
||||||
|
m_timerSet = true;
|
||||||
|
m_initialTimer = true;
|
||||||
|
CheckWakeup();
|
||||||
|
} else {
|
||||||
|
rtc_pcf.setTimer(seconds, TMR_1Hz, false);
|
||||||
|
|
||||||
|
m_timerSet = true;
|
||||||
|
m_initialTimer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
seconds = 0;
|
||||||
}
|
}
|
|
@ -20,6 +20,7 @@ public:
|
||||||
void Set(tmElements_t tm);
|
void Set(tmElements_t tm);
|
||||||
void SetTimer();
|
void SetTimer();
|
||||||
bool CheckWakeup(); // Checks to really wake up or not, also resets the timer after the initial sleep
|
bool CheckWakeup(); // Checks to really wake up or not, also resets the timer after the initial sleep
|
||||||
|
void Resync(); // Resync the timer cycle, both initially and after RTC resync
|
||||||
|
|
||||||
static void OffsetTime(tmElements_t & tm, int offsetInSeconds);
|
static void OffsetTime(tmElements_t & tm, int offsetInSeconds);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue