Skip to content

Commit 8d089b1

Browse files
committed
WatchFaceInfineat: Simplify time update check
1 parent c5c3e81 commit 8d089b1

2 files changed

Lines changed: 20 additions & 50 deletions

File tree

src/displayapp/screens/WatchFaceInfineat.cpp

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -397,63 +397,37 @@ void WatchFaceInfineat::Refresh() {
397397
lv_obj_align(notificationIcon, lv_scr_act(), LV_ALIGN_IN_TOP_RIGHT, 0, 0);
398398
}
399399

400-
currentDateTime = dateTimeController.CurrentDateTime();
401-
400+
currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
402401
if (currentDateTime.IsUpdated()) {
403-
auto hour = dateTimeController.Hours();
404-
auto minute = dateTimeController.Minutes();
405-
auto year = dateTimeController.Year();
406-
auto month = dateTimeController.Month();
407-
auto dayOfWeek = dateTimeController.DayOfWeek();
408-
auto day = dateTimeController.Day();
409-
410-
char minutesChar[3];
411-
sprintf(minutesChar, "%02d", static_cast<int>(minute));
412-
413-
char hoursChar[3];
414-
char ampmChar[3];
402+
uint8_t hour = dateTimeController.Hours();
403+
uint8_t minute = dateTimeController.Minutes();
415404

416405
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
417-
if (hour < 12) {
418-
if (hour == 0) {
419-
hour = 12;
420-
}
421-
sprintf(ampmChar, "AM");
422-
} else { // hour >= 12
423-
if (hour != 12) {
424-
hour = hour - 12;
425-
}
426-
sprintf(ampmChar, "PM");
406+
char ampmChar[3] = "AM";
407+
if (hour == 0) {
408+
hour = 12;
409+
} else if (hour == 12) {
410+
ampmChar[0] = 'P';
411+
} else if (hour > 12) {
412+
hour = hour - 12;
413+
ampmChar[0] = 'P';
427414
}
415+
lv_label_set_text(labelTimeAmPm, ampmChar);
428416
}
429-
sprintf(hoursChar, "%02d", hour);
430-
431-
if ((hoursChar[0] != displayedChar[0]) || (hoursChar[1] != displayedChar[1]) || (minutesChar[0] != displayedChar[2]) ||
432-
(minutesChar[1] != displayedChar[3])) {
433-
displayedChar[0] = hoursChar[0];
434-
displayedChar[1] = hoursChar[1];
435-
displayedChar[2] = minutesChar[0];
436-
displayedChar[3] = minutesChar[1];
437-
438-
lv_label_set_text_fmt(labelHour, "%s", hoursChar);
439-
lv_label_set_text_fmt(labelMinutes, "%s", minutesChar);
440-
}
417+
lv_label_set_text_fmt(labelHour, "%02d", hour);
418+
lv_label_set_text_fmt(labelMinutes, "%02d", minute);
441419

442420
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
443-
lv_label_set_text(labelTimeAmPm, ampmChar);
444421
lv_obj_align(labelTimeAmPm, timeContainer, LV_ALIGN_OUT_RIGHT_TOP, 0, 10);
445422
lv_obj_align(labelHour, timeContainer, LV_ALIGN_IN_TOP_MID, 0, 5);
446423
lv_obj_align(labelMinutes, timeContainer, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
447424
}
448425

449-
if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) {
426+
currentDate = std::chrono::time_point_cast<days>(currentDateTime.Get());
427+
if (currentDate.IsUpdated()) {
428+
uint8_t day = dateTimeController.Day();
450429
lv_label_set_text_fmt(labelDate, "%s %02d", dateTimeController.DayOfWeekShortToStringLow(), day);
451430
lv_obj_realign(labelDate);
452-
453-
currentYear = year;
454-
currentMonth = month;
455-
currentDayOfWeek = dayOfWeek;
456-
currentDay = day;
457431
}
458432
}
459433

src/displayapp/screens/WatchFaceInfineat.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,19 @@ namespace Pinetime {
4343
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
4444

4545
private:
46-
char displayedChar[5] {};
47-
48-
uint16_t currentYear = 1970;
49-
Pinetime::Controllers::DateTime::Months currentMonth = Pinetime::Controllers::DateTime::Months::Unknown;
50-
Pinetime::Controllers::DateTime::Days currentDayOfWeek = Pinetime::Controllers::DateTime::Days::Unknown;
51-
uint8_t currentDay = 0;
5246
uint32_t savedTick = 0;
5347
uint8_t chargingBatteryPercent = 101; // not a mistake ;)
5448

5549
Utility::DirtyValue<uint8_t> batteryPercentRemaining {};
5650
Utility::DirtyValue<bool> isCharging {};
5751
Utility::DirtyValue<bool> bleState {};
5852
Utility::DirtyValue<bool> bleRadioEnabled {};
59-
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime {};
53+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
6054
Utility::DirtyValue<bool> motionSensorOk {};
6155
Utility::DirtyValue<uint32_t> stepCount {};
6256
Utility::DirtyValue<bool> notificationState {};
57+
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
58+
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> currentDate;
6359

6460
// Lines making up the side cover
6561
lv_obj_t* lineBattery;

0 commit comments

Comments
 (0)