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.
This commit is contained in:
JustScott 2024-01-14 15:34:48 -06:00
parent 7dbb8f54c6
commit 8c18106bf1
2 changed files with 35 additions and 3 deletions

View file

@ -22,7 +22,8 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController, Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController, Controllers::MotionController& motionController,
Controllers::SimpleWeatherService& weatherService) Controllers::SimpleWeatherService& weatherService,
Controllers::Timer& timer)
: currentDateTime {{}}, : currentDateTime {{}},
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
notificationManager {notificationManager}, notificationManager {notificationManager},
@ -30,6 +31,7 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
heartRateController {heartRateController}, heartRateController {heartRateController},
motionController {motionController}, motionController {motionController},
weatherService {weatherService}, weatherService {weatherService},
timer {timer},
statusIcons(batteryController, bleController) { statusIcons(batteryController, bleController) {
statusIcons.Create(); statusIcons.Create();
@ -51,6 +53,16 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
lv_label_set_text(temperature, ""); lv_label_set_text(temperature, "");
lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 50); lv_obj_align(temperature, nullptr, LV_ALIGN_IN_TOP_MID, 20, 50);
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); label_date = lv_label_create(lv_scr_act(), nullptr);
lv_obj_align(label_date, lv_scr_act(), LV_ALIGN_CENTER, 0, 60); 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)); lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999));
@ -101,6 +113,20 @@ void WatchFaceDigital::Refresh() {
lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get()));
} }
if (timer.IsRunning()) {
auto secondsRemaining = std::chrono::duration_cast<std::chrono::seconds>(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<std::chrono::minutes>(dateTimeController.CurrentDateTime()); currentDateTime = std::chrono::time_point_cast<std::chrono::minutes>(dateTimeController.CurrentDateTime());
if (currentDateTime.IsUpdated()) { if (currentDateTime.IsUpdated()) {

View file

@ -20,6 +20,7 @@ namespace Pinetime {
class NotificationManager; class NotificationManager;
class HeartRateController; class HeartRateController;
class MotionController; class MotionController;
class Timer;
} }
namespace Applications { namespace Applications {
@ -34,7 +35,8 @@ namespace Pinetime {
Controllers::Settings& settingsController, Controllers::Settings& settingsController,
Controllers::HeartRateController& heartRateController, Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController, Controllers::MotionController& motionController,
Controllers::SimpleWeatherService& weather); Controllers::SimpleWeatherService& weather,
Controllers::Timer& timer);
~WatchFaceDigital() override; ~WatchFaceDigital() override;
void Refresh() override; void Refresh() override;
@ -56,6 +58,8 @@ namespace Pinetime {
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate; Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
lv_obj_t* timerIcon;
lv_obj_t* timeRemaining;
lv_obj_t* label_time; lv_obj_t* label_time;
lv_obj_t* label_time_ampm; lv_obj_t* label_time_ampm;
lv_obj_t* label_date; lv_obj_t* label_date;
@ -73,6 +77,7 @@ namespace Pinetime {
Controllers::HeartRateController& heartRateController; Controllers::HeartRateController& heartRateController;
Controllers::MotionController& motionController; Controllers::MotionController& motionController;
Controllers::SimpleWeatherService& weatherService; Controllers::SimpleWeatherService& weatherService;
Controllers::Timer& timer;
lv_task_t* taskRefresh; lv_task_t* taskRefresh;
Widgets::StatusIcons statusIcons; Widgets::StatusIcons statusIcons;
@ -92,7 +97,8 @@ namespace Pinetime {
controllers.settingsController, controllers.settingsController,
controllers.heartRateController, controllers.heartRateController,
controllers.motionController, controllers.motionController,
*controllers.weatherController); *controllers.weatherController,
controllers.timer);
}; };
static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) { static bool IsAvailable(Pinetime::Controllers::FS& /*filesystem*/) {