|
| 1 | +#include "displayapp/screens/WatchFaceNumerals.h" |
| 2 | + |
| 3 | +#include <lvgl/lvgl.h> |
| 4 | +#include <cstdio> |
| 5 | +#include "displayapp/screens/Symbols.h" |
| 6 | +#include "components/ble/NotificationManager.h" |
| 7 | +#include "components/settings/Settings.h" |
| 8 | + |
| 9 | +using namespace Pinetime::Applications::Screens; |
| 10 | + |
| 11 | +WatchFaceNumerals::WatchFaceNumerals(Controllers::DateTime& dateTimeController, |
| 12 | + Controllers::NotificationManager& notificationManager, |
| 13 | + Controllers::Settings& settingsController, |
| 14 | + Controllers::FS& filesystem) |
| 15 | + : currentDateTime {{}}, |
| 16 | + dateTimeController {dateTimeController}, |
| 17 | + notificationManager {notificationManager}, |
| 18 | + settingsController {settingsController} { |
| 19 | + |
| 20 | + lfs_file f = {}; |
| 21 | + if (filesystem.FileOpen(&f, "/fonts/rounded_large.bin", LFS_O_RDONLY) >= 0) { |
| 22 | + filesystem.FileClose(&f); |
| 23 | + fontLarge = lv_font_load("F:/fonts/rounded_large.bin"); |
| 24 | + } |
| 25 | + |
| 26 | + if (filesystem.FileOpen(&f, "/fonts/rounded_small.bin", LFS_O_RDONLY) >= 0) { |
| 27 | + filesystem.FileClose(&f); |
| 28 | + fontSmall = lv_font_load("F:/fonts/rounded_small.bin"); |
| 29 | + } |
| 30 | + |
| 31 | + notificationIcon = lv_obj_create(lv_scr_act(), nullptr); |
| 32 | + lv_obj_set_style_local_bg_color(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); |
| 33 | + lv_obj_set_style_local_radius(notificationIcon, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); |
| 34 | + lv_obj_set_size(notificationIcon, 16, 16); |
| 35 | + lv_obj_align(notificationIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 4, -76); |
| 36 | + lv_obj_set_hidden(notificationIcon, true); |
| 37 | + |
| 38 | + labelTimeHour = lv_label_create(lv_scr_act(), nullptr); |
| 39 | + lv_obj_set_style_local_text_font(labelTimeHour, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontLarge); |
| 40 | + lv_obj_set_style_local_text_color(labelTimeHour, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); |
| 41 | + lv_obj_align(labelTimeHour, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -160, -125); |
| 42 | + |
| 43 | + labelTimeMinute = lv_label_create(lv_scr_act(), nullptr); |
| 44 | + lv_obj_set_style_local_text_font(labelTimeMinute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontLarge); |
| 45 | + lv_obj_set_style_local_text_color(labelTimeMinute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_AQUA); |
| 46 | + lv_obj_align(labelTimeMinute, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -160, 0); |
| 47 | + |
| 48 | + labelTimeAMPM1 = lv_label_create(lv_scr_act(), nullptr); |
| 49 | + lv_label_set_text_static(labelTimeAMPM1, ""); |
| 50 | + lv_obj_set_style_local_text_font(labelTimeAMPM1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall); |
| 51 | + lv_obj_set_style_local_text_color(labelTimeAMPM1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, ampmColor); |
| 52 | + lv_obj_align(labelTimeAMPM1, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 2, -34); |
| 53 | + // We use two labels for more flexibility with alignment |
| 54 | + labelTimeAMPM2 = lv_label_create(lv_scr_act(), nullptr); |
| 55 | + lv_label_set_text_static(labelTimeAMPM2, "M"); |
| 56 | + lv_obj_set_style_local_text_font(labelTimeAMPM2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall); |
| 57 | + lv_obj_set_style_local_text_color(labelTimeAMPM2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, ampmColor); |
| 58 | + lv_obj_align(labelTimeAMPM2, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); |
| 59 | + |
| 60 | + dateDayOfWeek = lv_label_create(lv_scr_act(), nullptr); |
| 61 | + lv_obj_set_style_local_text_color(dateDayOfWeek, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); |
| 62 | + lv_obj_set_style_local_text_font(dateDayOfWeek, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall); |
| 63 | + lv_obj_align(dateDayOfWeek, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0); |
| 64 | + |
| 65 | + dateDay = lv_label_create(lv_scr_act(), nullptr); |
| 66 | + lv_obj_set_style_local_text_color(dateDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); |
| 67 | + lv_obj_set_style_local_text_font(dateDay, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fontSmall); |
| 68 | + lv_obj_align(dateDay, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 36); |
| 69 | + |
| 70 | + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); |
| 71 | + Refresh(); |
| 72 | +} |
| 73 | + |
| 74 | +WatchFaceNumerals::~WatchFaceNumerals() { |
| 75 | + lv_task_del(taskRefresh); |
| 76 | + |
| 77 | + if (fontLarge != nullptr) { |
| 78 | + lv_font_free(fontLarge); |
| 79 | + } |
| 80 | + if (fontSmall != nullptr) { |
| 81 | + lv_font_free(fontSmall); |
| 82 | + } |
| 83 | + |
| 84 | + lv_obj_clean(lv_scr_act()); |
| 85 | +} |
| 86 | + |
| 87 | +void WatchFaceNumerals::Refresh() { |
| 88 | + notificationState = notificationManager.AreNewNotificationsAvailable(); |
| 89 | + if (notificationState.IsUpdated()) { |
| 90 | + lv_obj_set_hidden(notificationIcon, !notificationState.Get()); |
| 91 | + } |
| 92 | + |
| 93 | + currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime()); |
| 94 | + if (currentDateTime.IsUpdated()) { |
| 95 | + uint8_t hour = dateTimeController.Hours(); |
| 96 | + uint8_t minute = dateTimeController.Minutes(); |
| 97 | + |
| 98 | + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { |
| 99 | + char ampmChar[2] = "A"; |
| 100 | + if (hour == 0) { |
| 101 | + hour = 12; |
| 102 | + } else if (hour == 12) { |
| 103 | + ampmChar[0] = 'P'; |
| 104 | + } else if (hour > 12) { |
| 105 | + hour = hour - 12; |
| 106 | + ampmChar[0] = 'P'; |
| 107 | + } |
| 108 | + lv_label_set_text(labelTimeAMPM1, ampmChar); |
| 109 | + } else { |
| 110 | + lv_obj_set_hidden(labelTimeAMPM2, true); |
| 111 | + } |
| 112 | + lv_label_set_text_fmt(labelTimeHour, "%02d", hour); |
| 113 | + lv_label_set_text_fmt(labelTimeMinute, "%02d", minute); |
| 114 | + |
| 115 | + currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get()); |
| 116 | + if (currentDate.IsUpdated()) { |
| 117 | + lv_label_set_text_static(dateDayOfWeek, dateTimeController.DayOfWeekShortToString()); |
| 118 | + lv_label_set_text_fmt(dateDay, "%d", dateTimeController.Day()); |
| 119 | + lv_obj_realign(dateDay); |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +bool WatchFaceNumerals::IsAvailable(Pinetime::Controllers::FS& filesystem) { |
| 125 | + lfs_file file = {}; |
| 126 | + |
| 127 | + if (filesystem.FileOpen(&file, "/fonts/rounded_small.bin", LFS_O_RDONLY) < 0) { |
| 128 | + return false; |
| 129 | + } |
| 130 | + |
| 131 | + filesystem.FileClose(&file); |
| 132 | + if (filesystem.FileOpen(&file, "/fonts/rounded_large.bin", LFS_O_RDONLY) < 0) { |
| 133 | + return false; |
| 134 | + } |
| 135 | + |
| 136 | + filesystem.FileClose(&file); |
| 137 | + return true; |
| 138 | +} |
0 commit comments