summaryrefslogtreecommitdiff
path: root/src/components/datetime
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/datetime')
-rw-r--r--src/components/datetime/DateTimeController.cpp43
-rw-r--r--src/components/datetime/DateTimeController.h7
2 files changed, 50 insertions, 0 deletions
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp
index 4ac9e1f1..e0d12431 100644
--- a/src/components/datetime/DateTimeController.cpp
+++ b/src/components/datetime/DateTimeController.cpp
@@ -11,6 +11,9 @@ namespace {
char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
}
+DateTime::DateTime(Controllers::Settings& settingsController) : settingsController {settingsController} {
+}
+
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
this->currentDateTime = t;
UpdateTime(previousSystickCounter); // Update internal state without updating the time
@@ -36,6 +39,8 @@ void DateTime::SetTime(
UpdateTime(systickCounter);
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);
}
void DateTime::UpdateTime(uint32_t systickCounter) {
@@ -75,6 +80,24 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
minute = time.minutes().count();
second = time.seconds().count();
+ if (minute == 0 && !isHourAlreadyNotified) {
+ isHourAlreadyNotified = true;
+ if (systemTask != nullptr) {
+ systemTask->PushMessage(System::Messages::OnNewHour);
+ }
+ } else if (minute != 0) {
+ isHourAlreadyNotified = false;
+ }
+
+ if ((minute == 0 || minute == 30) && !isHalfHourAlreadyNotified) {
+ isHalfHourAlreadyNotified = true;
+ if (systemTask != nullptr) {
+ systemTask->PushMessage(System::Messages::OnNewHalfHour);
+ }
+ } else if (minute != 0 && minute != 30) {
+ isHalfHourAlreadyNotified = false;
+ }
+
// Notify new day to SystemTask
if (hour == 0 and not isMidnightAlreadyNotified) {
isMidnightAlreadyNotified = true;
@@ -101,3 +124,23 @@ void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}
+using ClockType = Pinetime::Controllers::Settings::ClockType;
+std::string DateTime::FormattedTime() {
+ // Return time as a string in 12- or 24-hour format
+ char buff[9];
+ if (settingsController.GetClockType() == ClockType::H12) {
+ uint8_t hour12;
+ const char* amPmStr;
+ if (hour < 12) {
+ hour12 = (hour == 0) ? 12 : hour;
+ amPmStr = "AM";
+ } else {
+ hour12 = (hour == 12) ? 12 : hour - 12;
+ amPmStr = "PM";
+ }
+ sprintf(buff, "%i:%02i %s", hour12, minute, amPmStr);
+ } else {
+ sprintf(buff, "%02i:%02i", hour, minute);
+ }
+ return std::string(buff);
+}
diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h
index 77ed68e8..6e5ee3ca 100644
--- a/src/components/datetime/DateTimeController.h
+++ b/src/components/datetime/DateTimeController.h
@@ -2,6 +2,8 @@
#include <cstdint>
#include <chrono>
+#include <string>
+#include "components/settings/Settings.h"
namespace Pinetime {
namespace System {
@@ -10,6 +12,7 @@ namespace Pinetime {
namespace Controllers {
class DateTime {
public:
+ DateTime(Controllers::Settings& settingsController);
enum class Days : uint8_t { Unknown, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
enum class Months : uint8_t {
Unknown,
@@ -71,6 +74,7 @@ namespace Pinetime {
void Register(System::SystemTask* systemTask);
void SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t);
+ std::string FormattedTime();
private:
uint16_t year = 0;
@@ -86,7 +90,10 @@ namespace Pinetime {
std::chrono::seconds uptime {0};
bool isMidnightAlreadyNotified = false;
+ bool isHourAlreadyNotified = true;
+ bool isHalfHourAlreadyNotified = true;
System::SystemTask* systemTask = nullptr;
+ Controllers::Settings& settingsController;
};
}
}