Skip to content

Commit bde41a3

Browse files
committed
Added TimeProvider and related functions
1 parent 9be6359 commit bde41a3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

api/RealTimeClock.h

+23-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
#define ARDUINO_REAL_TIME_CLOCK_API_VERSION 10000 // version 1.0.0
2424

25+
class RealTimeClock;
26+
class TimeProvider;
27+
2528
// Functions to get and set current time
2629

2730
int year(); // current year as an integer
@@ -45,18 +48,36 @@ int day(unsigned long t); // day of t as an integer (1 - 31)
4548
int hour(unsigned long t); // hour of t as an integer (0 - 23)
4649
int minute(unsigned long t); // minute of t as an integer (0 - 59)
4750
int second(unsigned long t); // second of t as an integer (0 - 59)
48-
4951
unsigned long convertTime(int hour, int minute, int second, int day, int month, int year);
5052

53+
// Synchronize the clock with a time provider
54+
// Return true if the synchronization is successful, false otherwise.
55+
bool setTime(TimeProvider &provider);
56+
5157
// Real Time Clock interface
52-
// Time sources should implement this interface
58+
// Clocks should implement this interface
5359
class RealTimeClock
5460
{
5561
public:
62+
// Get the current time as unix-timestamp.
63+
// Return 0 if time has not been set.
5664
virtual unsigned long getTime() = 0;
65+
66+
// Set the current time as unix-timestamp
5767
virtual bool setTime(unsigned long t) = 0;
5868
};
5969

6070
extern RealTimeClock *arduinoSystemRTC;
6171

72+
// Time Provider interface
73+
// Class that performs time synchronization with a master time (atomic clock, GPS,
74+
// NTP, etc.) should implement this interface.
75+
class TimeProvider
76+
{
77+
public:
78+
// Query the time provider for the current real time and return it as unix-timestamp.
79+
// Returns 0 if the query fails.
80+
virtual unsigned long getTime() = 0;
81+
};
82+
6283
#endif

0 commit comments

Comments
 (0)