Skip to content

Commit 743ab9e

Browse files
committed
WatchFaceAnalog: Add configurable widgets
1 parent 6cd92d3 commit 743ab9e

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

src/displayapp/screens/WatchFaceAnalog.cpp

+58-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "displayapp/screens/BleIcon.h"
66
#include "displayapp/screens/Symbols.h"
77
#include "displayapp/screens/NotificationIcon.h"
8+
#include "components/heartrate/HeartRateController.h"
9+
#include "components/motion/MotionController.h"
810
#include "components/settings/Settings.h"
911
#include "displayapp/InfiniTimeTheme.h"
1012

@@ -45,14 +47,18 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
4547
const Controllers::Battery& batteryController,
4648
const Controllers::Ble& bleController,
4749
Controllers::NotificationManager& notificationManager,
48-
Controllers::Settings& settingsController)
50+
Controllers::Settings& settingsController,
51+
Controllers::HeartRateController& heartRateController,
52+
Controllers::MotionController& motionController)
4953
: currentDateTime {{}},
5054
batteryIcon(true),
5155
dateTimeController {dateTimeController},
5256
batteryController {batteryController},
5357
bleController {bleController},
5458
notificationManager {notificationManager},
55-
settingsController {settingsController} {
59+
settingsController {settingsController},
60+
heartRateController {heartRateController},
61+
motionController {motionController} {
5662

5763
sHour = 99;
5864
sMinute = 99;
@@ -154,6 +160,30 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
154160
lv_style_set_line_rounded(&hour_line_style_trace, LV_STATE_DEFAULT, false);
155161
lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace);
156162

163+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::HeartRate)) {
164+
heartbeatIcon = lv_label_create(lv_scr_act(), nullptr);
165+
lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat);
166+
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
167+
lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
168+
169+
heartbeatValue = lv_label_create(lv_scr_act(), nullptr);
170+
lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
171+
lv_label_set_text_static(heartbeatValue, "");
172+
lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
173+
}
174+
175+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Steps)) {
176+
stepValue = lv_label_create(lv_scr_act(), nullptr);
177+
lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
178+
lv_label_set_text_static(stepValue, "0");
179+
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
180+
181+
stepIcon = lv_label_create(lv_scr_act(), nullptr);
182+
lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7));
183+
lv_label_set_text_static(stepIcon, Symbols::shoe);
184+
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
185+
}
186+
157187
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
158188

159189
Refresh();
@@ -261,4 +291,30 @@ void WatchFaceAnalog::Refresh() {
261291
lv_label_set_text_fmt(label_date_day, "%s\n%02i", dateTimeController.DayOfWeekShortToString(), dateTimeController.Day());
262292
}
263293
}
294+
295+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::HeartRate)) {
296+
heartbeat = heartRateController.HeartRate();
297+
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
298+
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
299+
if (heartbeatRunning.Get()) {
300+
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
301+
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
302+
} else {
303+
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B));
304+
lv_label_set_text_static(heartbeatValue, "");
305+
}
306+
307+
lv_obj_realign(heartbeatIcon);
308+
lv_obj_realign(heartbeatValue);
309+
}
310+
}
311+
312+
if (settingsController.IsWidgetOn(Pinetime::Controllers::Settings::Widget::Steps)) {
313+
stepCount = motionController.NbSteps();
314+
if (stepCount.IsUpdated()) {
315+
lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get());
316+
lv_obj_realign(stepValue);
317+
lv_obj_realign(stepIcon);
318+
}
319+
}
264320
}

src/displayapp/screens/WatchFaceAnalog.h

+18-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace Pinetime {
1818
class Battery;
1919
class Ble;
2020
class NotificationManager;
21+
class HeartRateController;
22+
class MotionController;
2123
}
2224

2325
namespace Applications {
@@ -29,8 +31,9 @@ namespace Pinetime {
2931
const Controllers::Battery& batteryController,
3032
const Controllers::Ble& bleController,
3133
Controllers::NotificationManager& notificationManager,
32-
Controllers::Settings& settingsController);
33-
34+
Controllers::Settings& settingsController,
35+
Controllers::HeartRateController& heartRateController,
36+
Controllers::MotionController& motionController);
3437
~WatchFaceAnalog() override;
3538

3639
void Refresh() override;
@@ -42,6 +45,9 @@ namespace Pinetime {
4245
Utility::DirtyValue<bool> isCharging {};
4346
Utility::DirtyValue<bool> bleState {};
4447
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime;
48+
Utility::DirtyValue<uint32_t> stepCount {};
49+
Utility::DirtyValue<uint8_t> heartbeat {};
50+
Utility::DirtyValue<bool> heartbeatRunning {};
4551
Utility::DirtyValue<bool> notificationState {false};
4652
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
4753

@@ -73,13 +79,20 @@ namespace Pinetime {
7379
lv_obj_t* notificationIcon;
7480
lv_obj_t* bleIcon;
7581

82+
lv_obj_t* heartbeatIcon;
83+
lv_obj_t* heartbeatValue;
84+
lv_obj_t* stepIcon;
85+
lv_obj_t* stepValue;
86+
7687
BatteryIcon batteryIcon;
7788

7889
Controllers::DateTime& dateTimeController;
7990
const Controllers::Battery& batteryController;
8091
const Controllers::Ble& bleController;
8192
Controllers::NotificationManager& notificationManager;
8293
Controllers::Settings& settingsController;
94+
Controllers::HeartRateController& heartRateController;
95+
Controllers::MotionController& motionController;
8396

8497
void UpdateClock();
8598
void SetBatteryIcon();
@@ -98,7 +111,9 @@ namespace Pinetime {
98111
controllers.batteryController,
99112
controllers.bleController,
100113
controllers.notificationManager,
101-
controllers.settingsController);
114+
controllers.settingsController,
115+
controllers.heartRateController,
116+
controllers.motionController);
102117
};
103118

104119
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {

0 commit comments

Comments
 (0)