Skip to content

Commit 55a515b

Browse files
committed
WatchFaceAnalog: Add configurable widgets
1 parent 81f9b4a commit 55a515b

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

src/displayapp/screens/WatchFaceAnalog.cpp

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "displayapp/screens/BleIcon.h"
77
#include "displayapp/screens/Symbols.h"
88
#include "displayapp/screens/NotificationIcon.h"
9+
#include "components/heartrate/HeartRateController.h"
10+
#include "components/motion/MotionController.h"
911
#include "components/settings/Settings.h"
1012
#include "displayapp/InfiniTimeTheme.h"
1113

@@ -48,14 +50,18 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
4850
const Controllers::Battery& batteryController,
4951
const Controllers::Ble& bleController,
5052
Controllers::NotificationManager& notificationManager,
51-
Controllers::Settings& settingsController)
53+
Controllers::Settings& settingsController,
54+
Controllers::HeartRateController& heartRateController,
55+
Controllers::MotionController& motionController)
5256
: currentDateTime {{}},
5357
batteryIcon(true),
5458
dateTimeController {dateTimeController},
5559
batteryController {batteryController},
5660
bleController {bleController},
5761
notificationManager {notificationManager},
58-
settingsController {settingsController} {
62+
settingsController {settingsController},
63+
heartRateController {heartRateController},
64+
motionController {motionController} {
5965

6066
sHour = 99;
6167
sMinute = 99;
@@ -157,6 +163,30 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController,
157163
lv_style_set_line_rounded(&hour_line_style_trace, LV_STATE_DEFAULT, false);
158164
lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace);
159165

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

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

src/displayapp/screens/WatchFaceAnalog.h

Lines changed: 18 additions & 3 deletions
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)