Skip to content

Commit 3a51035

Browse files
author
Louis Pearson
committed
Add time of day to stopwatch app
1 parent 34511a6 commit 3a51035

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/displayapp/DisplayApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
424424
ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
425425
break;
426426
case Apps::StopWatch:
427-
currentScreen = std::make_unique<Screens::StopWatch>(this, *systemTask);
427+
currentScreen = std::make_unique<Screens::StopWatch>(this, *systemTask, dateTimeController);
428428
break;
429429
case Apps::Twos:
430430
currentScreen = std::make_unique<Screens::Twos>(this);

src/displayapp/screens/StopWatch.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,18 @@ static void stop_lap_event_handler(lv_obj_t* obj, lv_event_t event) {
4545
stopWatch->stopLapBtnEventHandler(event);
4646
}
4747

48-
StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask)
48+
StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask, Controllers::DateTime& dateTimeController)
4949
: Screen(app),
5050
systemTask {systemTask},
51+
dateTimeController {dateTimeController},
5152
currentState {States::Init},
5253
startTime {},
5354
oldTimeElapsed {},
5455
currentTimeSeparated {},
5556
lapBuffer {},
5657
lapNr {} {
5758

59+
// Running time
5860
time = lv_label_create(lv_scr_act(), nullptr);
5961
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
6062
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
@@ -101,6 +103,13 @@ StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask)
101103
lv_obj_align(lapTwoText, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 50, 55);
102104
lv_label_set_text(lapTwoText, "");
103105

106+
// Date time
107+
dateTime = lv_label_create(lv_scr_act(), nullptr);
108+
lv_label_set_text_fmt(dateTime, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
109+
lv_label_set_align(dateTime, LV_LABEL_ALIGN_CENTER);
110+
lv_obj_align(dateTime, nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
111+
lv_obj_set_style_local_text_color(dateTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
112+
104113
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
105114
}
106115

@@ -152,6 +161,7 @@ void StopWatch::pause() {
152161
}
153162

154163
void StopWatch::Refresh() {
164+
lv_label_set_text_fmt(dateTime, "%02i:%02i", dateTimeController.Hours(), dateTimeController.Minutes());
155165
if (currentState == States::Running) {
156166
timeElapsed = calculateDelta(startTime, xTaskGetTickCount());
157167
currentTimeSeparated = convertTicksToTimeSegments((oldTimeElapsed + timeElapsed));

src/displayapp/screens/StopWatch.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ namespace Pinetime::Applications::Screens {
6262

6363
class StopWatch : public Screen {
6464
public:
65-
StopWatch(DisplayApp* app, System::SystemTask& systemTask);
65+
StopWatch(DisplayApp* app,
66+
System::SystemTask& systemTask,
67+
Controllers::DateTime& dateTimeController);
6668
~StopWatch() override;
6769
void Refresh() override;
6870

@@ -76,6 +78,8 @@ namespace Pinetime::Applications::Screens {
7678

7779
private:
7880
Pinetime::System::SystemTask& systemTask;
81+
Controllers::DateTime& dateTimeController;
82+
7983
TickType_t timeElapsed;
8084
States currentState;
8185
TickType_t startTime;
@@ -85,6 +89,7 @@ namespace Pinetime::Applications::Screens {
8589
int lapNr = 0;
8690
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
8791
lv_obj_t *lapOneText, *lapTwoText;
92+
lv_obj_t *dateTime;
8893

8994
lv_task_t* taskRefresh;
9095
};

0 commit comments

Comments
 (0)