Skip to content

Use mbed rtc API instead of always request remote time #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/utility/time/TimeService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static time_t const EPOCH_AT_COMPILE_TIME = cvt_time(__DATE__);

TimeService::TimeService()
: _con_hdl(nullptr)
#ifdef ARDUINO_ARCH_SAMD
#if defined (ARDUINO_ARCH_SAMD) || defined (TARGET_PORTENTA_H7)
, _is_rtc_configured(false)
#endif
{
Expand Down Expand Up @@ -79,6 +79,13 @@ unsigned long TimeService::getTime()
_is_rtc_configured = true;
}
return rtc.getEpoch();
#elif TARGET_PORTENTA_H7
if(!_is_rtc_configured)
{
set_time(getRemoteTime());
_is_rtc_configured = true;
}
return time(NULL);
#else
return getRemoteTime();
#endif
Expand Down
6 changes: 5 additions & 1 deletion src/utility/time/TimeService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <RTCZero.h>
#endif

#ifdef TARGET_PORTENTA_H7
#include <mbed_rtc_time.h>
#endif

/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/
Expand All @@ -46,7 +50,7 @@ class TimeService
private:

ConnectionHandler * _con_hdl;
#ifdef ARDUINO_ARCH_SAMD
#if defined (ARDUINO_ARCH_SAMD) || defined (TARGET_PORTENTA_H7)
bool _is_rtc_configured;
#endif

Expand Down