AceTime
1.2
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
|
6 #ifndef ACE_TIME_SYSTEM_CLOCK_H
7 #define ACE_TIME_SYSTEM_CLOCK_H
12 extern "C" unsigned long millis();
13 class SystemClockLoopTest;
14 class SystemClockLoopTest_syncNow;
15 class SystemClockCoroutineTest;
57 if (mBackupClock !=
nullptr) {
63 if (!mIsInit)
return kInvalidSeconds;
65 while ((uint16_t) ((uint16_t)
clockMillis() - mPrevMillis) >= 1000) {
72 void setNow(acetime_t epochSeconds)
override {
76 if (mReferenceClock !=
nullptr) {
77 mReferenceClock->
setNow(epochSeconds);
83 acetime_t nowSeconds = mReferenceClock->
getNow();
96 bool isInit()
const {
return mIsInit; }
99 friend class ::SystemClockLoopTest;
100 friend class ::SystemClockCoroutineTest;
101 friend class ::SystemClockLoopTest_syncNow;
116 Clock* referenceClock ,
117 Clock* backupClock ):
118 mReferenceClock(referenceClock),
119 mBackupClock(backupClock) {}
140 if (mBackupClock !=
nullptr) {
141 mBackupClock->
setNow(nowSeconds);
156 if (epochSeconds == kInvalidSeconds)
return;
157 mLastSyncTime = epochSeconds;
158 if (mEpochSeconds == epochSeconds)
return;
160 mEpochSeconds = epochSeconds;
164 if (mBackupClock != mReferenceClock) {
169 Clock*
const mReferenceClock;
170 Clock*
const mBackupClock;
172 mutable acetime_t mEpochSeconds = kInvalidSeconds;
173 acetime_t mLastSyncTime = kInvalidSeconds;
174 mutable uint16_t mPrevMillis = 0;
175 bool mIsInit =
false;
acetime_t getLastSyncTime() const
Return the time (seconds since Epoch) of the last valid sync() call.
bool isInit() const
Return true if initialized by setNow() or syncNow().
virtual acetime_t getNow() const =0
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
void syncNow(acetime_t epochSeconds)
Similar to setNow() except that backupNow() is called only if the backupClock is different from the r...
void keepAlive()
Call this (or getNow() every 65.535 seconds or faster to keep the internal counter in sync with milli...
SystemClock(Clock *referenceClock, Clock *backupClock)
Constructor.
virtual void setNow(acetime_t)
Set the time to the indicated seconds.
void setNow(acetime_t epochSeconds) override
Set the time to the indicated seconds.
void setup()
Attempt to retrieve the time from the backupClock if it exists.
Base class for objects that provide and store time.
void forceSync()
Force a sync with the mReferenceClock.
virtual unsigned long clockMillis() const
Return the Arduino millis().
void backupNow(acetime_t nowSeconds)
Write the nowSeconds to the backupClock (which can be an RTC that has non-volatile memory,...
A Clock that uses the Arduino millis() function to advance the time returned to the user.
acetime_t getNow() const override
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).