Skip to content

Commit a0b3e54

Browse files
committed
Add internal functions to get and set RTC time
1 parent ba7ad8f commit a0b3e54

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/utility/time/TimeService.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ RTCZero rtc;
3838
**************************************************************************************/
3939

4040
time_t cvt_time(char const * time);
41+
unsigned long get_rtc_time();
42+
void set_rtc_time(unsigned long time);
4143

4244
/**************************************************************************************
4345
* CONSTANTS
@@ -274,6 +276,28 @@ time_t cvt_time(char const * time)
274276
return mktime(&t);
275277
}
276278

279+
unsigned long get_rtc_time() {
280+
#ifdef ARDUINO_ARCH_SAMD
281+
return rtc.getEpoch();
282+
#elif ARDUINO_ARCH_MBED
283+
return time(NULL);
284+
#else
285+
return EPOCH;
286+
#endif
287+
}
288+
289+
void set_rtc_time(unsigned long time) {
290+
#ifdef ARDUINO_ARCH_SAMD
291+
rtc.setEpoch(time);
292+
_is_rtc_configured = true;
293+
#elif ARDUINO_ARCH_MBED
294+
set_time(time);
295+
_is_rtc_configured = true;
296+
#else
297+
298+
#endif
299+
}
300+
277301
TimeService & ArduinoIoTCloudTimeService() {
278302
static TimeService _timeService_instance;
279303
return _timeService_instance;

0 commit comments

Comments
 (0)