|
1 | 1 | #include "displayapp/screens/WatchFaceDigital.h" |
2 | 2 |
|
3 | | -#include <lvgl/lvgl.h> |
4 | | -#include <cstdio> |
5 | | - |
6 | | -#include "displayapp/screens/NotificationIcon.h" |
7 | | -#include "displayapp/screens/Symbols.h" |
8 | | -#include "displayapp/screens/WeatherSymbols.h" |
9 | | -#include "components/battery/BatteryController.h" |
10 | | -#include "components/ble/BleController.h" |
11 | | -#include "components/ble/NotificationManager.h" |
12 | | -#include "components/heartrate/HeartRateController.h" |
13 | | -#include "components/motion/MotionController.h" |
14 | | -#include "components/ble/SimpleWeatherService.h" |
15 | | -#include "components/settings/Settings.h" |
| 3 | +#include "watchface_digital.h" |
| 4 | +#include "WatchFaceDigital.h" |
16 | 5 |
|
17 | 6 | using namespace Pinetime::Applications::Screens; |
18 | 7 |
|
19 | | -WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, |
20 | | - const Controllers::Battery& batteryController, |
21 | | - const Controllers::Ble& bleController, |
22 | | - const Controllers::AlarmController& alarmController, |
23 | | - Controllers::NotificationManager& notificationManager, |
24 | | - Controllers::Settings& settingsController, |
25 | | - Controllers::HeartRateController& heartRateController, |
26 | | - Controllers::MotionController& motionController, |
27 | | - Controllers::SimpleWeatherService& weatherService) |
28 | | - : currentDateTime {{}}, |
29 | | - dateTimeController {dateTimeController}, |
30 | | - notificationManager {notificationManager}, |
31 | | - settingsController {settingsController}, |
32 | | - heartRateController {heartRateController}, |
33 | | - motionController {motionController}, |
34 | | - weatherService {weatherService}, |
35 | | - statusIcons(batteryController, bleController, alarmController) { |
36 | | - |
37 | | - statusIcons.Create(); |
38 | | - |
39 | | - notificationIcon = lv_label_create(lv_scr_act(), nullptr); |
40 | | - lv_obj_set_style_local_text_color(notificationIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME); |
41 | | - lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); |
42 | | - lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); |
43 | | - |
44 | | - weatherIcon = lv_label_create(lv_scr_act(), nullptr); |
45 | | - lv_obj_set_style_local_text_color(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); |
46 | | - lv_obj_set_style_local_text_font(weatherIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &fontawesome_weathericons); |
47 | | - lv_label_set_text(weatherIcon, ""); |
48 | | - lv_obj_align(weatherIcon, nullptr, LV_ALIGN_IN_TOP_MID, -20, 50); |
49 | | - lv_obj_set_auto_realign(weatherIcon, true); |
50 | | - |
51 | | - temperature = lv_label_create(lv_scr_act(), nullptr); |
52 | | - lv_obj_set_style_local_text_color(temperature, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); |
53 | | - lv_label_set_text(temperature, ""); |
54 | | - lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 50); |
55 | | - |
56 | | - label_date = lv_label_create(lv_scr_act(), nullptr); |
57 | | - lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); |
58 | | - lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); |
59 | | - |
60 | | - label_time = lv_label_create(lv_scr_act(), nullptr); |
61 | | - lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_extrabold_compressed); |
62 | | - |
63 | | - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); |
64 | | - |
65 | | - label_time_ampm = lv_label_create(lv_scr_act(), nullptr); |
66 | | - lv_label_set_text_static(label_time_ampm, ""); |
67 | | - lv_obj_align(label_time_ampm, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -30, -55); |
68 | | - |
69 | | - heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); |
70 | | - lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); |
71 | | - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); |
72 | | - lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); |
73 | | - |
74 | | - heartbeatValue = lv_label_create(lv_scr_act(), nullptr); |
75 | | - lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); |
76 | | - lv_label_set_text_static(heartbeatValue, ""); |
77 | | - lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); |
78 | | - |
79 | | - stepValue = lv_label_create(lv_scr_act(), nullptr); |
80 | | - lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7)); |
81 | | - lv_label_set_text_static(stepValue, "0"); |
82 | | - lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); |
83 | | - |
84 | | - stepIcon = lv_label_create(lv_scr_act(), nullptr); |
85 | | - lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7)); |
86 | | - lv_label_set_text_static(stepIcon, Symbols::shoe); |
87 | | - lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); |
88 | | - |
89 | | - taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); |
90 | | - Refresh(); |
91 | | -} |
92 | | - |
93 | | -WatchFaceDigital::~WatchFaceDigital() { |
94 | | - lv_task_del(taskRefresh); |
95 | | - lv_obj_clean(lv_scr_act()); |
96 | | -} |
97 | | - |
98 | | -void WatchFaceDigital::Refresh() { |
99 | | - statusIcons.Update(); |
100 | | - |
101 | | - notificationState = notificationManager.AreNewNotificationsAvailable(); |
102 | | - if (notificationState.IsUpdated()) { |
103 | | - lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); |
104 | | - } |
105 | | - |
106 | | - currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime()); |
107 | | - |
108 | | - if (currentDateTime.IsUpdated()) { |
109 | | - uint8_t hour = dateTimeController.Hours(); |
110 | | - uint8_t minute = dateTimeController.Minutes(); |
111 | | - |
112 | | - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) { |
113 | | - char ampmChar[3] = "AM"; |
114 | | - if (hour == 0) { |
115 | | - hour = 12; |
116 | | - } else if (hour == 12) { |
117 | | - ampmChar[0] = 'P'; |
118 | | - } else if (hour > 12) { |
119 | | - hour = hour - 12; |
120 | | - ampmChar[0] = 'P'; |
121 | | - } |
122 | | - lv_label_set_text(label_time_ampm, ampmChar); |
123 | | - lv_label_set_text_fmt(label_time, "%2d:%02d", hour, minute); |
124 | | - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 0, 0); |
125 | | - } else { |
126 | | - lv_label_set_text_fmt(label_time, "%02d:%02d", hour, minute); |
127 | | - lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); |
128 | | - } |
129 | | - |
130 | | - currentDate = std::chrono::time_point_cast<std::chrono::days>(currentDateTime.Get()); |
131 | | - if (currentDate.IsUpdated()) { |
132 | | - uint16_t year = dateTimeController.Year(); |
133 | | - uint8_t day = dateTimeController.Day(); |
134 | | - if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { |
135 | | - lv_label_set_text_fmt(label_date, |
136 | | - "%s %d %s %d", |
137 | | - dateTimeController.DayOfWeekShortToString(), |
138 | | - day, |
139 | | - dateTimeController.MonthShortToString(), |
140 | | - year); |
141 | | - } else { |
142 | | - lv_label_set_text_fmt(label_date, |
143 | | - "%s %s %d %d", |
144 | | - dateTimeController.DayOfWeekShortToString(), |
145 | | - dateTimeController.MonthShortToString(), |
146 | | - day, |
147 | | - year); |
148 | | - } |
149 | | - lv_obj_realign(label_date); |
150 | | - } |
151 | | - } |
152 | | - |
153 | | - heartbeat = heartRateController.HeartRate(); |
154 | | - heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; |
155 | | - if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { |
156 | | - if (heartbeatRunning.Get()) { |
157 | | - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); |
158 | | - lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get()); |
159 | | - } else { |
160 | | - lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B)); |
161 | | - lv_label_set_text_static(heartbeatValue, ""); |
162 | | - } |
163 | | - |
164 | | - lv_obj_realign(heartbeatIcon); |
165 | | - lv_obj_realign(heartbeatValue); |
166 | | - } |
167 | | - |
168 | | - stepCount = motionController.NbSteps(); |
169 | | - if (stepCount.IsUpdated()) { |
170 | | - lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get()); |
171 | | - lv_obj_realign(stepValue); |
172 | | - lv_obj_realign(stepIcon); |
173 | | - } |
174 | | - |
175 | | - currentWeather = weatherService.Current(); |
176 | | - if (currentWeather.IsUpdated()) { |
177 | | - auto optCurrentWeather = currentWeather.Get(); |
178 | | - if (optCurrentWeather) { |
179 | | - int16_t temp = optCurrentWeather->temperature.Celsius(); |
180 | | - char tempUnit = 'C'; |
181 | | - if (settingsController.GetWeatherFormat() == Controllers::Settings::WeatherFormat::Imperial) { |
182 | | - temp = optCurrentWeather->temperature.Fahrenheit(); |
183 | | - tempUnit = 'F'; |
184 | | - } |
185 | | - lv_label_set_text_fmt(temperature, "%d°%c", temp, tempUnit); |
186 | | - lv_label_set_text(weatherIcon, Symbols::GetSymbol(optCurrentWeather->iconId)); |
187 | | - } else { |
188 | | - lv_label_set_text_static(temperature, ""); |
189 | | - lv_label_set_text(weatherIcon, ""); |
190 | | - } |
191 | | - lv_obj_realign(temperature); |
192 | | - lv_obj_realign(weatherIcon); |
193 | | - } |
| 8 | +WatchFaceDigital::WatchFaceDigital(AppControllers& controllers) : Pawn(watchface_digital, controllers) { |
194 | 9 | } |
0 commit comments