aboutsummaryrefslogtreecommitdiffstats
path: root/src/displayapp/screens
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2023-03-03 13:03:00 +0200
committerRiku Isokoski <riksu9000@gmail.com>2023-04-02 18:07:29 +0000
commit8d089b1429e2d448debc2d3e5149895eafe31fd8 (patch)
treef08e08c60ece8f10e0ed3275c6e88e13c1a410cb /src/displayapp/screens
parentc5c3e81e15dce80607e301a3643a6e5b675a2f4a (diff)
WatchFaceInfineat: Simplify time update check
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r--src/displayapp/screens/WatchFaceInfineat.cpp60
-rw-r--r--src/displayapp/screens/WatchFaceInfineat.h10
2 files changed, 20 insertions, 50 deletions
diff --git a/src/displayapp/screens/WatchFaceInfineat.cpp b/src/displayapp/screens/WatchFaceInfineat.cpp
index ab0898e0..88e17b79 100644
--- a/src/displayapp/screens/WatchFaceInfineat.cpp
+++ b/src/displayapp/screens/WatchFaceInfineat.cpp
@@ -397,63 +397,37 @@ void WatchFaceInfineat::Refresh() {
lv_obj_align(notificationIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
}
- 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();
-
- char minutesChar[3];
- sprintf(minutesChar, "%02d", static_cast<int>(minute));
-
- char hoursChar[3];
- char ampmChar[3];
+ uint8_t hour = dateTimeController.Hours();
+ uint8_t minute = dateTimeController.Minutes();
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
- if (hour < 12) {
- if (hour == 0) {
- hour = 12;
- }
- sprintf(ampmChar, "AM");
- } else { // hour >= 12
- if (hour != 12) {
- hour = hour - 12;
- }
- sprintf(ampmChar, "PM");
+ 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(labelTimeAmPm, ampmChar);
}
- sprintf(hoursChar, "%02d", hour);
-
- if ((hoursChar[0] != displayedChar[0]) || (hoursChar[1] != displayedChar[1]) || (minutesChar[0] != displayedChar[2]) ||
- (minutesChar[1] != displayedChar[3])) {
- displayedChar[0] = hoursChar[0];
- displayedChar[1] = hoursChar[1];
- displayedChar[2] = minutesChar[0];
- displayedChar[3] = minutesChar[1];
-
- lv_label_set_text_fmt(labelHour, "%s", hoursChar);
- lv_label_set_text_fmt(labelMinutes, "%s", minutesChar);
- }
+ lv_label_set_text_fmt(labelHour, "%02d", hour);
+ lv_label_set_text_fmt(labelMinutes, "%02d", minute);
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
- lv_label_set_text(labelTimeAmPm, ampmChar);
lv_obj_align(labelTimeAmPm, timeContainer, LV_ALIGN_OUT_RIGHT_TOP, 0, 10);
lv_obj_align(labelHour, timeContainer, LV_ALIGN_IN_TOP_MID, 0, 5);
lv_obj_align(labelMinutes, timeContainer, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
}
- if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
+ currentDate = std::chrono::time_point_cast<days>(currentDateTime.Get());
+ if (currentDate.IsUpdated()) {
+ uint8_t day = dateTimeController.Day();
lv_label_set_text_fmt(labelDate, "%s %02d", dateTimeController.DayOfWeekShortToStringLow(), day);
lv_obj_realign(labelDate);
-
- currentYear = year;
- currentMonth = month;
- currentDayOfWeek = dayOfWeek;
- currentDay = day;
}
}
diff --git a/src/displayapp/screens/WatchFaceInfineat.h b/src/displayapp/screens/WatchFaceInfineat.h
index ef908ffc..2dcd59b9 100644
--- a/src/displayapp/screens/WatchFaceInfineat.h
+++ b/src/displayapp/screens/WatchFaceInfineat.h
@@ -43,12 +43,6 @@ namespace Pinetime {
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
private:
- char displayedChar[5] {};
-
- uint16_t currentYear = 1970;
- Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
- Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
- uint8_t currentDay = 0;
uint32_t savedTick = 0;
uint8_t chargingBatteryPercent = 101; // not a mistake ;)
@@ -56,10 +50,12 @@ namespace Pinetime {
Utility::DirtyValue<bool> isCharging {};
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<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;
// Lines making up the side cover
lv_obj_t* lineBattery;