summaryrefslogtreecommitdiff
path: root/src/components/datetime/DateTimeController.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/datetime/DateTimeController.cpp')
-rw-r--r--src/components/datetime/DateTimeController.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp
index ba04705..1f7182c 100644
--- a/src/components/datetime/DateTimeController.cpp
+++ b/src/components/datetime/DateTimeController.cpp
@@ -36,6 +36,7 @@ void DateTime::SetTime(uint16_t year,
/* .tm_year = */ year - 1900,
};
tm.tm_isdst = -1; // Use DST value from local time zone
+ auto previousDateTime = currentDateTime;
currentDateTime = std::chrono::system_clock::from_time_t(std::mktime(&tm));
NRF_LOG_INFO("%d %d %d ", day, month, year);
@@ -46,7 +47,17 @@ void DateTime::SetTime(uint16_t year,
NRF_LOG_INFO("* %d %d %d ", this->hour, this->minute, this->second);
NRF_LOG_INFO("* %d %d %d ", this->day, 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) {
@@ -95,13 +106,13 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
isHourAlreadyNotified = false;
}
- if ((minute == 0 || minute == 30) && !isHalfHourAlreadyNotified) {
- isHalfHourAlreadyNotified = true;
+ if (minute%chimePeriod) {
+ hasChimed = false;
+ } else if (!hasChimed) {
if (systemTask != nullptr) {
- systemTask->PushMessage(System::Messages::OnNewHalfHour);
+ systemTask->PushMessage(System::Messages::OnChime);
+ hasChimed = true;
}
- } else if (minute != 0 && minute != 30) {
- isHalfHourAlreadyNotified = false;
}
// Notify new day to SystemTask