Skip to content

Commit d251a47

Browse files
committed
WatchFaceG7710: Simplify time update check
1 parent 8d089b1 commit d251a47

2 files changed

Lines changed: 29 additions & 47 deletions

File tree

src/displayapp/screens/WatchFaceCasioStyleG7710.cpp

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -222,43 +222,36 @@ void WatchFaceCasioStyleG7710::Refresh() {
222222
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
223223
}
224224

225-
currentDateTime = dateTimeController.CurrentDateTime();
226-
225+
currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
227226
if (currentDateTime.IsUpdated()) {
228-
auto hour = dateTimeController.Hours();
229-
auto minute = dateTimeController.Minutes();
230-
auto year = dateTimeController.Year();
231-
auto month = dateTimeController.Month();
232-
auto dayOfWeek = dateTimeController.DayOfWeek();
233-
auto day = dateTimeController.Day();
234-
auto dayOfYear = dateTimeController.DayOfYear();
235-
236-
auto weekNumberFormat = "%V";
237-
238-
if (displayedHour != hour || displayedMinute != minute) {
239-
displayedHour = hour;
240-
displayedMinute = minute;
241-
242-
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
243-
char ampmChar[2] = "A";
244-
if (hour == 0) {
245-
hour = 12;
246-
} else if (hour == 12) {
247-
ampmChar[0] = 'P';
248-
} else if (hour > 12) {
249-
hour = hour - 12;
250-
ampmChar[0] = 'P';
251-
}
252-
lv_label_set_text(label_time_ampm, ampmChar);
253-
lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
254-
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 40);
255-
} else {
256-
lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
257-
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 40);
227+
uint8_t hour = dateTimeController.Hours();
228+
uint8_t minute = dateTimeController.Minutes();
229+
230+
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
231+
char ampmChar[2] = "A";
232+
if (hour == 0) {
233+
hour = 12;
234+
} else if (hour == 12) {
235+
ampmChar[0] = 'P';
236+
} else if (hour > 12) {
237+
hour = hour - 12;
238+
ampmChar[0] = 'P';
258239
}
240+
lv_label_set_text(label_time_ampm, ampmChar);
241+
lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute);
242+
} else {
243+
lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute);
259244
}
245+
lv_obj_realign(label_time);
260246

261-
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
247+
currentDate = std::chrono::time_point_cast<days>(currentDateTime.Get());
248+
if (currentDate.IsUpdated()) {
249+
const char* weekNumberFormat = "%V";
250+
251+
uint16_t year = dateTimeController.Year();
252+
Controllers::DateTime::Months month = dateTimeController.Month();
253+
uint8_t day = dateTimeController.Day();
254+
int dayOfYear = dateTimeController.DayOfYear();
262255
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) {
263256
// 24h mode: ddmmyyyy, first DOW=Monday;
264257
lv_label_set_text_fmt(label_date, "%3d-%2d", day, month);
@@ -293,11 +286,6 @@ void WatchFaceCasioStyleG7710::Refresh() {
293286
lv_obj_realign(label_day_of_year);
294287
lv_obj_realign(label_week_number);
295288
lv_obj_realign(label_date);
296-
297-
currentYear = year;
298-
currentMonth = month;
299-
currentDayOfWeek = dayOfWeek;
300-
currentDay = day;
301289
}
302290
}
303291

src/displayapp/screens/WatchFaceCasioStyleG7710.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,18 @@ namespace Pinetime {
4040
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
4141

4242
private:
43-
uint8_t displayedHour = -1;
44-
uint8_t displayedMinute = -1;
45-
46-
uint16_t currentYear = 1970;
47-
Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
48-
Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
49-
uint8_t currentDay = 0;
50-
5143
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
5244
Utility::DirtyValue<bool> powerPresent {};
5345
Utility::DirtyValue<bool> bleState {};
5446
Utility::DirtyValue<bool> bleRadioEnabled {};
55-
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 {};
5648
Utility::DirtyValue<bool> motionSensorOk {};
5749
Utility::DirtyValue<uint32_t> stepCount {};
5850
Utility::DirtyValue<uint8_t> heartbeat {};
5951
Utility::DirtyValue<bool> heartbeatRunning {};
6052
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;
6155

6256
lv_point_t line_icons_points[3] {{0, 5}, {117, 5}, {122, 0}};
6357
lv_point_t line_day_of_week_number_points[4] {{0, 0}, {100, 0}, {95, 95}, {0, 95}};

0 commit comments

Comments
 (0)