|
| 1 | +#include <date/date.h> |
| 2 | +#include <lvgl/lvgl.h> |
| 3 | +#include "displayapp/screens/WatchFaceTerminal.h" |
| 4 | +#include "displayapp/screens/BatteryIcon.h" |
| 5 | +#include "displayapp/screens/NotificationIcon.h" |
| 6 | +#include "displayapp/screens/Symbols.h" |
| 7 | +#include "components/battery/BatteryController.h" |
| 8 | +#include "components/ble/BleController.h" |
| 9 | +#include "components/ble/NotificationManager.h" |
| 10 | +#include "components/heartrate/HeartRateController.h" |
| 11 | +#include "components/motion/MotionController.h" |
| 12 | +#include "components/settings/Settings.h" |
| 13 | + |
| 14 | +using namespace Pinetime::Applications::Screens; |
| 15 | + |
| 16 | +WatchFaceTerminal::WatchFaceTerminal(DisplayApp* app, |
| 17 | + Controllers::DateTime& dateTimeController, |
| 18 | + Controllers::Battery& batteryController, |
| 19 | + Controllers::Ble& bleController, |
| 20 | + Controllers::NotificationManager& notificatioManager, |
| 21 | + Controllers::Settings& settingsController, |
| 22 | + Controllers::HeartRateController& heartRateController, |
| 23 | + Controllers::MotionController& motionController) |
| 24 | + : Screen(app), |
| 25 | + currentDateTime {{}}, |
| 26 | + dateTimeController {dateTimeController}, |
| 27 | + batteryController {batteryController}, |
| 28 | + bleController {bleController}, |
| 29 | + notificatioManager {notificatioManager}, |
| 30 | + settingsController {settingsController}, |
| 31 | + heartRateController {heartRateController}, |
| 32 | + motionController {motionController} { |
| 33 | + settingsController.SetClockFace(3); |
| 34 | + |
| 35 | + batteryIcon = lv_label_create(lv_scr_act(), nullptr); |
| 36 | + lv_label_set_text(batteryIcon, Symbols::batteryFull); |
| 37 | + lv_obj_align(batteryIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, 2); |
| 38 | + |
| 39 | + batteryPlug = lv_label_create(lv_scr_act(), nullptr); |
| 40 | + lv_label_set_text(batteryPlug, Symbols::plug); |
| 41 | + lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); |
| 42 | + |
| 43 | + batteryValue = lv_label_create(lv_scr_act(), nullptr); |
| 44 | + lv_label_set_recolor(batteryValue, true); |
| 45 | + lv_obj_align(batteryValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20); |
| 46 | + |
| 47 | + connectState = lv_label_create(lv_scr_act(), nullptr); |
| 48 | + lv_label_set_recolor(connectState, true); |
| 49 | + lv_label_set_text(connectState, "[STAT]#387b54 Disconnected#"); |
| 50 | + lv_obj_align(connectState, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 40); |
| 51 | + |
| 52 | + notificationIcon = lv_label_create(lv_scr_act(), nullptr); |
| 53 | + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); |
| 54 | + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 10, 0); |
| 55 | + |
| 56 | + label_date = lv_label_create(lv_scr_act(), nullptr); |
| 57 | + lv_label_set_recolor(label_date, true); |
| 58 | + lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -40); |
| 59 | + |
| 60 | + label_prompt_1 = lv_label_create(lv_scr_act(), nullptr); |
| 61 | + lv_obj_align(label_prompt_1, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -80); |
| 62 | + lv_label_set_text(label_prompt_1, "user@watch:~ $ now"); |
| 63 | + |
| 64 | + label_prompt_2 = lv_label_create(lv_scr_act(), nullptr); |
| 65 | + lv_obj_align(label_prompt_2, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 60); |
| 66 | + lv_label_set_text(label_prompt_2, "user@watch:~ $"); |
| 67 | + |
| 68 | + label_time = lv_label_create(lv_scr_act(), nullptr); |
| 69 | + lv_label_set_recolor(label_time, true); |
| 70 | + lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -60); |
| 71 | + |
| 72 | + backgroundLabel = lv_label_create(lv_scr_act(), nullptr); |
| 73 | + lv_obj_set_click(backgroundLabel, true); |
| 74 | + lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP); |
| 75 | + lv_obj_set_size(backgroundLabel, 240, 240); |
| 76 | + lv_obj_set_pos(backgroundLabel, 0, 0); |
| 77 | + lv_label_set_text(backgroundLabel, ""); |
| 78 | + |
| 79 | + heartbeatValue = lv_label_create(lv_scr_act(), nullptr); |
| 80 | + lv_label_set_recolor(heartbeatValue, true); |
| 81 | + lv_label_set_text(heartbeatValue, "[L_HR]#ee3311 0 bpm#"); |
| 82 | + lv_obj_align(heartbeatValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 20); |
| 83 | + |
| 84 | + stepValue = lv_label_create(lv_scr_act(), nullptr); |
| 85 | + lv_label_set_recolor(stepValue, true); |
| 86 | + lv_label_set_text(stepValue, "[STEP]#ee3377 0 steps#"); |
| 87 | + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, 0); |
| 88 | + |
| 89 | + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); |
| 90 | + Refresh(); |
| 91 | +} |
| 92 | + |
| 93 | +WatchFaceTerminal::~WatchFaceTerminal() { |
| 94 | + lv_task_del(taskRefresh); |
| 95 | + lv_obj_clean(lv_scr_act()); |
| 96 | +} |
| 97 | + |
| 98 | +void WatchFaceTerminal::Refresh() { |
| 99 | + powerPresent = batteryController.IsPowerPresent(); |
| 100 | + if (powerPresent.IsUpdated()) { |
| 101 | + lv_label_set_text_static(batteryPlug, BatteryIcon::GetPlugIcon(powerPresent.Get())); |
| 102 | + } |
| 103 | + |
| 104 | + batteryPercentRemaining = batteryController.PercentRemaining(); |
| 105 | + if (batteryPercentRemaining.IsUpdated()) { |
| 106 | + auto batteryPercent = batteryPercentRemaining.Get(); |
| 107 | + if (batteryPercent == 100) { |
| 108 | + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN); |
| 109 | + } else { |
| 110 | + lv_obj_set_style_local_text_color(batteryIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); |
| 111 | + } |
| 112 | + lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryPercent)); |
| 113 | + lv_label_set_text_fmt(batteryValue, "[BATT]#387b54 %d%\%#", batteryPercent); |
| 114 | + } |
| 115 | + |
| 116 | + bleState = bleController.IsConnected(); |
| 117 | + if (bleState.IsUpdated()) { |
| 118 | + if (bleState.Get()) { |
| 119 | + lv_label_set_text_static(connectState, "[STAT]#387b54 Connected#"); |
| 120 | + } else { |
| 121 | + lv_label_set_text_static(connectState, "[STAT]#387b54 Disconnected#"); |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + notificationState = notificatioManager.AreNewNotificationsAvailable(); |
| 126 | + if (notificationState.IsUpdated()) { |
| 127 | + if (notificationState.Get()) { |
| 128 | + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true)); |
| 129 | + } else { |
| 130 | + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + currentDateTime = dateTimeController.CurrentDateTime(); |
| 135 | + |
| 136 | + if (currentDateTime.IsUpdated()) { |
| 137 | + auto newDateTime = currentDateTime.Get(); |
| 138 | + |
| 139 | + auto dp = date::floor<date::days>(newDateTime); |
| 140 | + auto time = date::make_time(newDateTime - dp); |
| 141 | + auto yearMonthDay = date::year_month_day(dp); |
| 142 | + |
| 143 | + auto year = static_cast<int>(yearMonthDay.year()); |
| 144 | + auto month = static_cast<Pinetime::Controllers::DateTime::Months>(static_cast<unsigned>(yearMonthDay.month())); |
| 145 | + auto day = static_cast<unsigned>(yearMonthDay.day()); |
| 146 | + auto dayOfWeek = static_cast<Pinetime::Controllers::DateTime::Days>(date::weekday(yearMonthDay).iso_encoding()); |
| 147 | + |
| 148 | + uint8_t hour = time.hours().count(); |
| 149 | + uint8_t minute = time.minutes().count(); |
| 150 | + uint8_t second = time.seconds().count(); |
| 151 | + |
| 152 | + if (displayedHour != hour || displayedMinute != minute || displayedSecond != second) { |
| 153 | + displayedHour = hour; |
| 154 | + displayedMinute = minute; |
| 155 | + displayedSecond = second; |
| 156 | + |
| 157 | + if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { |
| 158 | + char ampmChar[3] = "AM"; |
| 159 | + if (hour == 0) { |
| 160 | + hour = 12; |
| 161 | + } else if (hour == 12) { |
| 162 | + ampmChar[0] = 'P'; |
| 163 | + } else if (hour > 12) { |
| 164 | + hour = hour - 12; |
| 165 | + ampmChar[0] = 'P'; |
| 166 | + } |
| 167 | + lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d %s#", hour, minute, second, ampmChar); |
| 168 | + } else { |
| 169 | + lv_label_set_text_fmt(label_time, "[TIME]#11cc55 %02d:%02d:%02d", hour, minute, second); |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + if ((year != currentYear) || (month != currentMonth) || (dayOfWeek != currentDayOfWeek) || (day != currentDay)) { |
| 174 | + lv_label_set_text_fmt(label_date, "[DATE]#007fff %04d.%02d.%02d#", short(year), char(month), char(day)); |
| 175 | + |
| 176 | + currentYear = year; |
| 177 | + currentMonth = month; |
| 178 | + currentDayOfWeek = dayOfWeek; |
| 179 | + currentDay = day; |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + heartbeat = heartRateController.HeartRate(); |
| 184 | + heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; |
| 185 | + if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { |
| 186 | + if (heartbeatRunning.Get()) { |
| 187 | + lv_label_set_text_fmt(heartbeatValue, "[L_HR]#ee3311 %d bpm#", heartbeat.Get()); |
| 188 | + } else { |
| 189 | + lv_label_set_text_static(heartbeatValue, "[L_HR]#ee3311 ---#"); |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + stepCount = motionController.NbSteps(); |
| 194 | + motionSensorOk = motionController.IsSensorOk(); |
| 195 | + if (stepCount.IsUpdated() || motionSensorOk.IsUpdated()) { |
| 196 | + lv_label_set_text_fmt(stepValue, "[STEP]#ee3377 %lu steps#", stepCount.Get()); |
| 197 | + } |
| 198 | +} |
0 commit comments