22
22
23
23
#define ARDUINO_REAL_TIME_CLOCK_API_VERSION 10000 // version 1.0.0
24
24
25
+ class RealTimeClock ;
26
+ class TimeProvider ;
27
+
25
28
// Functions to get and set current time
26
29
27
30
int year (); // current year as an integer
@@ -45,18 +48,36 @@ int day(unsigned long t); // day of t as an integer (1 - 31)
45
48
int hour (unsigned long t); // hour of t as an integer (0 - 23)
46
49
int minute (unsigned long t); // minute of t as an integer (0 - 59)
47
50
int second (unsigned long t); // second of t as an integer (0 - 59)
48
-
49
51
unsigned long convertTime (int hour, int minute, int second, int day, int month, int year);
50
52
53
+ // Synchronize the clock with a time provider
54
+ // Return true if the synchronization is successful, false otherwise.
55
+ bool setTime (TimeProvider &provider);
56
+
51
57
// Real Time Clock interface
52
- // Time sources should implement this interface
58
+ // Clocks should implement this interface
53
59
class RealTimeClock
54
60
{
55
61
public:
62
+ // Get the current time as unix-timestamp.
63
+ // Return 0 if time has not been set.
56
64
virtual unsigned long getTime () = 0;
65
+
66
+ // Set the current time as unix-timestamp
57
67
virtual bool setTime (unsigned long t) = 0;
58
68
};
59
69
60
70
extern RealTimeClock *arduinoSystemRTC;
61
71
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
+
62
83
#endif
0 commit comments