AceTime  0.3
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.
SystemClockHeartbeatLoop.h
1 #ifndef ACE_TIME_SYSTEM_CLOCK_HEARTBEAT_LOOP_H
2 #define ACE_TIME_SYSTEM_CLOCK_HEARTBEAT_LOOP_H
3 
4 #include <stdint.h>
5 #include "SystemClock.h"
6 
7 namespace ace_time {
8 namespace clock {
9 
15  public:
24  uint16_t heartbeatPeriodMillis = 5000):
25  mSystemClock(systemClock),
26  mHeartbeatPeriodMillis(heartbeatPeriodMillis) {}
27 
32  void loop() {
33  unsigned long nowMillis = millis();
34  uint16_t timeSinceLastSync = nowMillis - mLastSyncMillis;
35 
36  // Make sure that mEpochSeconds does not fall too far behind.
37  if (timeSinceLastSync >= mHeartbeatPeriodMillis) {
38  mSystemClock.getNow();
39  mLastSyncMillis = nowMillis;
40  }
41  }
42 
43  private:
44  SystemClock& mSystemClock;
45  uint16_t const mHeartbeatPeriodMillis;
46 
47  unsigned long mLastSyncMillis = 0; // should be the same type as millis()
48 };
49 
50 }
51 }
52 
53 #endif
acetime_t getNow() const override
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).
Definition: SystemClock.h:67
A TimeKeeper that uses the Arduino millis() function to advance the time returned to the user...
Definition: SystemClock.h:45
A class that peridically freshens the SystemClock using the heartbeat call to getNow().
SystemClockHeartbeatLoop(SystemClock &systemClock, uint16_t heartbeatPeriodMillis=5000)
Constructor.
void loop()
Call this from the global loop() method to make SystemClock keep in sync with the system millis()...