summaryrefslogtreecommitdiff
path: root/src/components/datetime
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/datetime')
-rw-r--r--src/components/datetime/DateTimeController.cpp23
-rw-r--r--src/components/datetime/DateTimeController.h5
2 files changed, 21 insertions, 7 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
diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h
index 00bbc2e..48fe2b1 100644
--- a/src/components/datetime/DateTimeController.h
+++ b/src/components/datetime/DateTimeController.h
@@ -91,7 +91,10 @@ namespace Pinetime {
bool isMidnightAlreadyNotified = false;
bool isHourAlreadyNotified = true;
- bool isHalfHourAlreadyNotified = true;
+ bool hasChimed = true;
+ public:
+ uint8_t chimePeriod = 5;
+ private:
System::SystemTask* systemTask = nullptr;
Controllers::Settings& settingsController;
};