From 904749654acb9412c5c1b3a407992a0a08fbdb2c Mon Sep 17 00:00:00 2001 From: Julian Foad Date: Fri, 10 May 2024 20:51:31 +0100 Subject: [PATCH] Analog: include heart and step info --- src/displayapp/screens/WatchFaceAnalog.cpp | 52 +++++++++++++++++++++- src/displayapp/screens/WatchFaceAnalog.h | 19 +++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/WatchFaceAnalog.cpp b/src/displayapp/screens/WatchFaceAnalog.cpp index 4bb43a89..66d2e838 100644 --- a/src/displayapp/screens/WatchFaceAnalog.cpp +++ b/src/displayapp/screens/WatchFaceAnalog.cpp @@ -5,6 +5,8 @@ #include "displayapp/screens/BleIcon.h" #include "displayapp/screens/Symbols.h" #include "displayapp/screens/NotificationIcon.h" +#include "components/heartrate/HeartRateController.h" +#include "components/motion/MotionController.h" #include "components/settings/Settings.h" #include "displayapp/InfiniTimeTheme.h" @@ -45,14 +47,18 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController, const Controllers::Battery& batteryController, const Controllers::Ble& bleController, Controllers::NotificationManager& notificationManager, - Controllers::Settings& settingsController) + Controllers::Settings& settingsController, + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController) : currentDateTime {{}}, batteryIcon(true), dateTimeController {dateTimeController}, batteryController {batteryController}, bleController {bleController}, notificationManager {notificationManager}, - settingsController {settingsController} { + settingsController {settingsController}, + heartRateController {heartRateController}, + motionController {motionController} { sHour = 99; sMinute = 99; @@ -159,6 +165,26 @@ WatchFaceAnalog::WatchFaceAnalog(Controllers::DateTime& dateTimeController, lv_style_set_line_rounded(&hour_line_style_trace, LV_STATE_DEFAULT, false); lv_obj_add_style(hour_body_trace, LV_LINE_PART_MAIN, &hour_line_style_trace); + heartbeatIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(heartbeatIcon, Symbols::heartBeat); + lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); + lv_obj_align(heartbeatIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); + + heartbeatValue = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(heartbeatValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); + lv_label_set_text_static(heartbeatValue, ""); + lv_obj_align(heartbeatValue, heartbeatIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + + stepIcon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(stepIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7)); + lv_label_set_text_static(stepIcon, Symbols::shoe); + lv_obj_align(stepIcon, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); + + stepValue = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x00FFE7)); + lv_label_set_text_static(stepValue, "0"); + lv_obj_align(stepValue, stepIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); @@ -268,4 +294,26 @@ void WatchFaceAnalog::Refresh() { lv_obj_align(label_date_day, nullptr, LV_ALIGN_CENTER, 50, 0); } } + + heartbeat = heartRateController.HeartRate(); + heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped; + if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) { + if (heartbeatRunning.Get()) { + lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B)); + lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get()); + } else { + lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B)); + lv_label_set_text_static(heartbeatValue, ""); + } + + lv_obj_realign(heartbeatIcon); + lv_obj_realign(heartbeatValue); + } + + stepCount = motionController.NbSteps(); + if (stepCount.IsUpdated()) { + lv_label_set_text_fmt(stepValue, "%lu", stepCount.Get()); + lv_obj_realign(stepValue); + lv_obj_realign(stepIcon); + } } diff --git a/src/displayapp/screens/WatchFaceAnalog.h b/src/displayapp/screens/WatchFaceAnalog.h index a045b322..9005fe5d 100644 --- a/src/displayapp/screens/WatchFaceAnalog.h +++ b/src/displayapp/screens/WatchFaceAnalog.h @@ -18,6 +18,8 @@ namespace Pinetime { class Battery; class Ble; class NotificationManager; + class HeartRateController; + class MotionController; } namespace Applications { @@ -29,7 +31,9 @@ namespace Pinetime { const Controllers::Battery& batteryController, const Controllers::Ble& bleController, Controllers::NotificationManager& notificationManager, - Controllers::Settings& settingsController); + Controllers::Settings& settingsController, + Controllers::HeartRateController& heartRateController, + Controllers::MotionController& motionController); ~WatchFaceAnalog() override; @@ -42,6 +46,9 @@ namespace Pinetime { Utility::DirtyValue isCharging {}; Utility::DirtyValue bleState {}; Utility::DirtyValue> currentDateTime; + Utility::DirtyValue stepCount {}; + Utility::DirtyValue heartbeat {}; + Utility::DirtyValue heartbeatRunning {}; Utility::DirtyValue notificationState {false}; Utility::DirtyValue> currentDate; @@ -74,6 +81,10 @@ namespace Pinetime { lv_obj_t* plugIcon; lv_obj_t* notificationIcon; lv_obj_t* bleIcon; + lv_obj_t* heartbeatIcon; + lv_obj_t* heartbeatValue; + lv_obj_t* stepIcon; + lv_obj_t* stepValue; BatteryIcon batteryIcon; @@ -82,6 +93,8 @@ namespace Pinetime { const Controllers::Ble& bleController; Controllers::NotificationManager& notificationManager; Controllers::Settings& settingsController; + Controllers::HeartRateController& heartRateController; + Controllers::MotionController& motionController; void UpdateClock(); void SetBatteryIcon(); @@ -100,7 +113,9 @@ namespace Pinetime { controllers.batteryController, controllers.bleController, controllers.notificationManager, - controllers.settingsController); + controllers.settingsController, + controllers.heartRateController, + controllers.motionController); }; static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {