Skip to content

Commit c5c3e81

Browse files
committed
WatchFaceDigital: Simplify update check
1 parent 238a829 commit c5c3e81

2 files changed

Lines changed: 26 additions & 40 deletions

File tree

src/displayapp/screens/WatchFaceDigital.cpp

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -85,40 +85,34 @@ void WatchFaceDigital::Refresh() {
8585
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
8686
}
8787

88-
currentDateTime = dateTimeController.CurrentDateTime();
88+
currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
8989

9090
if (currentDateTime.IsUpdated()) {
91-
auto hour = dateTimeController.Hours();
92-
auto minute = dateTimeController.Minutes();
93-
auto year = dateTimeController.Year();
94-
auto month = dateTimeController.Month();
95-
auto dayOfWeek = dateTimeController.DayOfWeek();
96-
auto day = dateTimeController.Day();
97-
98-
if (displayedHour != hour || displayedMinute != minute) {
99-
displayedHour = hour;
100-
displayedMinute = minute;
101-
102-
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
103-
char ampmChar[3] = "AM";
104-
if (hour == 0) {
105-
hour = 12;
106-
} else if (hour == 12) {
107-
ampmChar[0] = 'P';
108-
} else if (hour > 12) {
109-
hour = hour - 12;
110-
ampmChar[0] = 'P';
111-
}
112-
lv_label_set_text(label_time_ampm, ampmChar);
113-
lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
114-
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
115-
} else {
116-
lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
117-
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
91+
uint8_t hour = dateTimeController.Hours();
92+
uint8_t minute = dateTimeController.Minutes();
93+
94+
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
95+
char ampmChar[3] = "AM";
96+
if (hour == 0) {
97+
hour = 12;
98+
} else if (hour == 12) {
99+
ampmChar[0] = 'P';
100+
} else if (hour > 12) {
101+
hour = hour - 12;
102+
ampmChar[0] = 'P';
118103
}
104+
lv_label_set_text(label_time_ampm, ampmChar);
105+
lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
106+
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0);
107+
} else {
108+
lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
109+
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
119110
}
120111

121-
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
112+
currentDate = std::chrono::time_point_cast<days>(currentDateTime.Get());
113+
if (currentDate.IsUpdated()) {
114+
uint16_t year = dateTimeController.Year();
115+
uint8_t day = dateTimeController.Day();
122116
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
123117
lv_label_set_text_fmt(label_date,
124118
"%s %d %s %d",
@@ -135,11 +129,6 @@ void WatchFaceDigital::Refresh() {
135129
year);
136130
}
137131
lv_obj_realign(label_date);
138-
139-
currentYear = year;
140-
currentMonth = month;
141-
currentDayOfWeek = dayOfWeek;
142-
currentDay = day;
143132
}
144133
}
145134

src/displayapp/screens/WatchFaceDigital.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,18 @@ namespace Pinetime {
4040
uint8_t displayedHour = -1;
4141
uint8_t displayedMinute = -1;
4242

43-
uint16_t currentYear = 1970;
44-
Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
45-
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
46-
uint8_t currentDay = 0;
47-
4843
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
4944
Utility::DirtyValue<bool> powerPresent {};
5045
Utility::DirtyValue<bool> bleState {};
5146
Utility::DirtyValue<bool> bleRadioEnabled {};
52-
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
47+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
5348
Utility::DirtyValue<bool> motionSensorOk {};
5449
Utility::DirtyValue<uint32_t> stepCount {};
5550
Utility::DirtyValue<uint8_t> heartbeat {};
5651
Utility::DirtyValue<bool> heartbeatRunning {};
5752
Utility::DirtyValue<bool> notificationState {};
53+
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
54+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
5855

5956
lv_obj_t* label_time;
6057
lv_obj_t* label_time_ampm;

0 commit comments

Comments
 (0)