From 20f50c702c056ff7638af40285cda2929351cc2b Mon Sep 17 00:00:00 2001 From: JustScott Date: Sun, 14 Jan 2024 15:34:48 -0600 Subject: [PATCH] Add Timer's Time Remaining to Digitial Watchface Adds a live output of the timer's time remaining, along with an hourGlass symbol to the left. Both of these are placed above the current time and are the same color as the date as to not draw attention away from the current time. The icon and the time remaining are both set to hidden if the timer isn't running. --- src/displayapp/screens/WatchFaceDigital.cpp | 28 ++++++++++++++++++++- src/displayapp/screens/WatchFaceDigital.h | 10 ++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index ca53691b12..566a116199 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -19,13 +19,15 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController) + Controllers::MotionController& motionController, + Controllers::Timer& timer) : currentDateTime {{}}, dateTimeController {dateTimeController}, notificationManager {notificationManager}, settingsController {settingsController}, heartRateController {heartRateController}, motionController {motionController}, + timer {timer}, statusIcons(batteryController, bleController) { statusIcons.Create(); @@ -35,6 +37,16 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(false)); lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0); + timerIcon = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(timerIcon, Symbols::hourGlass); + lv_obj_set_style_local_text_color(timerIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + lv_obj_align(timerIcon, lv_scr_act(), LV_ALIGN_IN_TOP_MID, -32, 60); + + timeRemaining = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(timeRemaining, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + lv_label_set_text(timeRemaining, "00:00"); + lv_obj_align(timeRemaining, nullptr, LV_ALIGN_IN_TOP_MID, 10, 60); + label_date = lv_label_create(lv_scr_act(), nullptr); lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); @@ -85,6 +97,20 @@ void WatchFaceDigital::Refresh() { lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } + if (timer.IsRunning()) { + auto secondsRemaining = std::chrono::duration_cast(timer.GetTimeRemaining()); + + int minutes = secondsRemaining.count() / 60; + int seconds = secondsRemaining.count() % 60; + lv_label_set_text_fmt(timeRemaining, "%02d:%02d", minutes, seconds); + + lv_obj_set_hidden(timeRemaining, false); + lv_obj_set_hidden(timerIcon, false); + } else { + lv_obj_set_hidden(timeRemaining, true); + lv_obj_set_hidden(timerIcon, true); + } + currentDateTime = std::chrono::time_point_cast(dateTimeController.CurrentDateTime()); if (currentDateTime.IsUpdated()) { diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index a4664792c0..85a5e00ca1 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -19,6 +19,7 @@ namespace Pinetime { class NotificationManager; class HeartRateController; class MotionController; + class Timer; } namespace Applications { @@ -32,7 +33,8 @@ namespace Pinetime { Controllers::NotificationManager& notificationManager, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, - Controllers::MotionController& motionController); + Controllers::MotionController& motionController, + Controllers::Timer& timer); ~WatchFaceDigital() override; void Refresh() override; @@ -53,6 +55,8 @@ namespace Pinetime { using days = std::chrono::duration>; // TODO: days is standard in c++20 Utility::DirtyValue> currentDate; + lv_obj_t* timerIcon; + lv_obj_t* timeRemaining; lv_obj_t* label_time; lv_obj_t* label_time_ampm; lv_obj_t* label_date; @@ -67,6 +71,7 @@ namespace Pinetime { Controllers::Settings& settingsController; Controllers::HeartRateController& heartRateController; Controllers::MotionController& motionController; + Controllers::Timer& timer; lv_task_t* taskRefresh; Widgets::StatusIcons statusIcons; @@ -85,7 +90,8 @@ namespace Pinetime { controllers.notificationManager, controllers.settingsController, controllers.heartRateController, - controllers.motionController); + controllers.motionController, + controllers.timer); }; static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {