aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2023-03-03 12:51:17 +0200
committerRiku Isokoski <riksu9000@gmail.com>2023-04-02 17:56:51 +0000
commitc5c3e81e15dce80607e301a3643a6e5b675a2f4a (patch)
treef05f47eba72e631065b54e44edff98f7ec7c79b0
parent238a829577c71dc9cfc5d96d01d098e47c9508ef (diff)
WatchFaceDigital: Simplify update check
-rw-r--r--src/displayapp/screens/WatchFaceDigital.cpp55
-rw-r--r--src/displayapp/screens/WatchFaceDigital.h9
2 files changed, 25 insertions, 39 deletions
diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp
index ad35b5c9..8b851289 100644
--- a/src/displayapp/screens/WatchFaceDigital.cpp
+++ b/src/displayapp/screens/WatchFaceDigital.cpp
@@ -85,40 +85,34 @@ void WatchFaceDigital::Refresh() {
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
}
- currentDateTime = dateTimeController.CurrentDateTime();
+ currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
if (currentDateTime.IsUpdated()) {
- auto hour = dateTimeController.Hours();
- auto minute = dateTimeController.Minutes();
- auto year = dateTimeController.Year();
- auto month = dateTimeController.Month();
- auto dayOfWeek = dateTimeController.DayOfWeek();
- auto day = dateTimeController.Day();
+ uint8_t hour = dateTimeController.Hours();
+ uint8_t minute = dateTimeController.Minutes();
- if (displayedHour != hour || displayedMinute != minute) {
- displayedHour = hour;
- displayedMinute = minute;
-
- if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
- char ampmChar[3] = "AM";
- if (hour == 0) {
- hour = 12;
- } else if (hour == 12) {
- ampmChar[0] = 'P';
- } else if (hour > 12) {
- hour = hour - 12;
- ampmChar[0] = 'P';
- }
- lv_label_set_text(label_time_ampm, ampmChar);
- lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
- lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
- } else {
- lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
- lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
+ if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
+ char ampmChar[3] = "AM";
+ if (hour == 0) {
+ hour = 12;
+ } else if (hour == 12) {
+ ampmChar[0] = 'P';
+ } else if (hour > 12) {
+ hour = hour - 12;
+ ampmChar[0] = 'P';
}
+ lv_label_set_text(label_time_ampm, ampmChar);
+ lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
+ lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
+ } else {
+ lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
+ lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
}
- if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
+ currentDate = std::chrono::time_point_cast<days>(currentDateTime.Get());
+ if (currentDate.IsUpdated()) {
+ uint16_t year = dateTimeController.Year();
+ uint8_t day = dateTimeController.Day();
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
lv_label_set_text_fmt(label_date,
"%s %d %s %d",
@@ -135,11 +129,6 @@ void WatchFaceDigital::Refresh() {
year);
}
lv_obj_realign(label_date);
-
- currentYear = year;
- currentMonth = month;
- currentDayOfWeek = dayOfWeek;
- currentDay = day;
}
}
diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h
index a51c24e4..d6395ee1 100644
--- a/src/displayapp/screens/WatchFaceDigital.h
+++ b/src/displayapp/screens/WatchFaceDigital.h
@@ -40,21 +40,18 @@ namespace Pinetime {
uint8_t displayedHour = -1;
uint8_t displayedMinute = -1;
- uint16_t currentYear = 1970;
- Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
- Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
- uint8_t currentDay = 0;
-
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
Utility::DirtyValue<bool> powerPresent {};
Utility::DirtyValue<bool> bleState {};
Utility::DirtyValue<bool> bleRadioEnabled {};
- Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
+ Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
Utility::DirtyValue<bool> motionSensorOk {};
Utility::DirtyValue<uint32_t> stepCount {};
Utility::DirtyValue<uint8_t> heartbeat {};
Utility::DirtyValue<bool> heartbeatRunning {};
Utility::DirtyValue<bool> notificationState {};
+ using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
+ Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
lv_obj_t* label_time;
lv_obj_t* label_time_ampm;