diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-16 14:04:52 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-16 14:04:52 (GMT) |
| commit | 9311f4787551373406a66d726de2a5fdae6cfb99 (patch) | |
| tree | 56a782d733dee81ee1e45eb62148b846ce79b742 /src/components/datetime/DateTimeController.cpp | |
| parent | 9f682f4132a71ca1fef0b567b1334031df382abb (diff) | |
Differentiate time adjustment (< 3h for example time zone change when crossing a border or because of daylight saving) and time setting (for example when the firmware is booted for the first time and the companion app sends the time)
Diffstat (limited to 'src/components/datetime/DateTimeController.cpp')
| -rw-r--r-- | src/components/datetime/DateTimeController.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 01e2859..76407f0 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -30,6 +30,7 @@ void DateTime::SetTime( /* .tm_year = */ year - 1900, }; tm.tm_isdst = -1; // Use DST value from local time zone + auto previousDateTime = currentDateTime; currentDateTime = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::from_time_t(std::mktime(&tm))); NRF_LOG_INFO("%d %d %d ", day, month, year); @@ -40,7 +41,17 @@ void DateTime::SetTime( NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second); NRF_LOG_INFO("* %d %d %d ", this->day, ((int)this->month), this->year); - systemTask->PushMessage(System::Messages::OnNewTime); + decltype(currentDateTime - previousDateTime) timeDifference; + + if (currentDateTime > previousDateTime) { + timeDifference = currentDateTime - previousDateTime; + } else { + timeDifference = previousDateTime - currentDateTime; + } + + using namespace std::chrono_literals; + + systemTask->PushMessage(timeDifference < 3h ? System::Messages::OnAdjustTime : System::Messages::OnNewTime); } void DateTime::UpdateTime(uint32_t systickCounter) { |
