Skip to content

Commit

Permalink
Add Timer's Time Remaining to Digitial Watchface
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JustScott committed Jan 17, 2024
1 parent 034d83f commit 63b24cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/displayapp/screens/WatchFaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down Expand Up @@ -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<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());

if (currentDateTime.IsUpdated()) {
Expand Down
10 changes: 8 additions & 2 deletions src/displayapp/screens/WatchFaceDigital.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Pinetime {
class NotificationManager;
class HeartRateController;
class MotionController;
class Timer;
}

namespace Applications {
Expand All @@ -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;
Expand All @@ -53,6 +55,8 @@ namespace Pinetime {
using days = std::chrono::duration<int32_t, std::ratio<86400>>; // TODO: days is standard in c++20
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, days>> 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;
Expand All @@ -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;
Expand All @@ -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*/) {
Expand Down

0 comments on commit 63b24cb

Please sign in to comment.