AceTime  0.1
Date and time classes for Arduino that supports the TZ DAtabase, and a system clock synchronized from an NTP server or an RTC chip.
SystemTimeHeartbeatLoop.h
1 #ifndef ACE_TIME_SYSTEM_TIME_HEARTBEAT_LOOP_H
2 #define ACE_TIME_SYSTEM_TIME_HEARTBEAT_LOOP_H
3 
4 #include <stdint.h>
5 #include "SystemTimeKeeper.h"
6 
7 namespace ace_time {
8 namespace provider {
9 
15  public:
24  uint16_t heartbeatPeriodMillis = 5000):
25  mSystemTimeKeeper(systemTimeKeeper),
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  mSystemTimeKeeper.getNow();
39  mLastSyncMillis = nowMillis;
40  }
41  }
42 
43  private:
44  SystemTimeKeeper& mSystemTimeKeeper;
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
A class that peridically freshens the SystemTimeKeeper using the heartbeat call to getNow()...
SystemTimeHeartbeatLoop(SystemTimeKeeper &systemTimeKeeper, uint16_t heartbeatPeriodMillis=5000)
Constructor.
A TimeKeeper that uses the Arduino millis() function to advance the time returned to the user...
void loop()
Call this from the global loop() method to make SystemTimeKeeper keep in sync with the system millis(...
acetime_t getNow() const override
Return the number of seconds since the AceTime epoch (2000-01-01T00:00:00Z).