Skip to content

Commit e2e4dcc

Browse files
feat: show timer on the Digital Watch Face
1 parent 0fabfe9 commit e2e4dcc

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

src/displayapp/screens/StopWatch.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using namespace Pinetime::Applications::Screens;
77
using namespace Pinetime::Controllers;
88

9-
namespace {
9+
namespace Pinetime::Applications::Screens {
1010
TimeSeparated ConvertTicksToTimeSegments(const TickType_t timeElapsed) {
1111
const uint32_t timeElapsedSecs = timeElapsed / configTICK_RATE_HZ;
1212
const uint16_t timeElapsedFraction = timeElapsed % configTICK_RATE_HZ;
@@ -17,7 +17,9 @@ namespace {
1717
const uint16_t hours = (timeElapsedSecs / 60) / 60;
1818
return TimeSeparated {hours, mins, secs, hundredths, timeElapsedSecs};
1919
}
20+
}
2021

22+
namespace {
2123
void PlayPauseEventHandler(lv_obj_t* obj, lv_event_t event) {
2224
auto* stopWatch = static_cast<StopWatch*>(obj->user_data);
2325
if (event == LV_EVENT_CLICKED) {

src/displayapp/screens/StopWatch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace Pinetime::Applications {
2020
uint32_t epochSecs;
2121
};
2222

23+
TimeSeparated ConvertTicksToTimeSegments(const TickType_t timeElapsed);
24+
2325
class StopWatch : public Screen {
2426
public:
2527
explicit StopWatch(System::SystemTask& systemTask, Controllers::StopWatchController& stopWatchController);

src/displayapp/screens/WatchFaceDigital.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "displayapp/screens/NotificationIcon.h"
77
#include "displayapp/screens/Symbols.h"
88
#include "displayapp/screens/WeatherSymbols.h"
9+
#include "displayapp/screens/WeatherSymbols.h"
10+
#include "displayapp/screens/StopWatch.h"
911
#include "components/battery/BatteryController.h"
1012
#include "components/ble/BleController.h"
1113
#include "components/ble/NotificationManager.h"
@@ -24,13 +26,15 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
2426
Controllers::Settings& settingsController,
2527
Controllers::HeartRateController& heartRateController,
2628
Controllers::MotionController& motionController,
29+
Controllers::StopWatchController& stopWatchController,
2730
Controllers::SimpleWeatherService& weatherService)
2831
: currentDateTime {{}},
2932
dateTimeController {dateTimeController},
3033
notificationManager {notificationManager},
3134
settingsController {settingsController},
3235
heartRateController {heartRateController},
3336
motionController {motionController},
37+
stopWatchController {stopWatchController},
3438
weatherService {weatherService},
3539
statusIcons(batteryController, bleController, alarmController) {
3640

@@ -86,6 +90,16 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController,
8690
lv_label_set_text_static(stepIcon, Symbols::shoe);
8791
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
8892

93+
stopWatchIcon = lv_label_create(lv_scr_act(), nullptr);
94+
lv_obj_set_style_local_text_color(stopWatchIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
95+
lv_label_set_text_static(stopWatchIcon, "");
96+
lv_obj_align(stopWatchIcon, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
97+
98+
stopWatchValue = lv_label_create(lv_scr_act(), nullptr);
99+
lv_obj_set_style_local_text_color(stopWatchValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF));
100+
lv_label_set_text_static(stopWatchValue, "");
101+
lv_obj_align(stopWatchValue, stopWatchIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
102+
89103
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
90104
Refresh();
91105
}
@@ -172,6 +186,21 @@ void WatchFaceDigital::Refresh() {
172186
lv_obj_realign(stepIcon);
173187
}
174188

189+
stopWatchTime = stopWatchController.GetElapsedTime();
190+
stopWatchRunning = !stopWatchController.IsCleared();
191+
if (stopWatchTime.IsUpdated() || stopWatchRunning.IsUpdated()) {
192+
if (stopWatchRunning.Get()) {
193+
TimeSeparated elapsedTime = ConvertTicksToTimeSegments(stopWatchTime.Get());
194+
lv_label_set_text_fmt(stopWatchValue, "%02d:%02d:%02d:%02d", elapsedTime.hours, elapsedTime.mins, elapsedTime.secs, elapsedTime.hundredths);
195+
lv_label_set_text_static(stopWatchIcon, Symbols::stopWatch);
196+
} else {
197+
lv_label_set_text_fmt(stopWatchValue, "");
198+
lv_label_set_text_static(stopWatchIcon, "");
199+
}
200+
lv_obj_realign(stopWatchValue);
201+
lv_obj_realign(stopWatchIcon);
202+
}
203+
175204
currentWeather = weatherService.Current();
176205
if (currentWeather.IsUpdated()) {
177206
auto optCurrentWeather = currentWeather.Get();

src/displayapp/screens/WatchFaceDigital.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace Pinetime {
3636
Controllers::Settings& settingsController,
3737
Controllers::HeartRateController& heartRateController,
3838
Controllers::MotionController& motionController,
39+
Controllers::StopWatchController& stopWatchController,
3940
Controllers::SimpleWeatherService& weather);
4041
~WatchFaceDigital() override;
4142

@@ -47,6 +48,8 @@ namespace Pinetime {
4748

4849
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
4950
Utility::DirtyValue<uint32_t> stepCount {};
51+
Utility::DirtyValue<TickType_t> stopWatchTime {};
52+
Utility::DirtyValue<bool> stopWatchRunning {};
5053
Utility::DirtyValue<uint8_t> heartbeat {};
5154
Utility::DirtyValue<bool> heartbeatRunning {};
5255
Utility::DirtyValue<bool> notificationState {};
@@ -61,6 +64,8 @@ namespace Pinetime {
6164
lv_obj_t* heartbeatValue;
6265
lv_obj_t* stepIcon;
6366
lv_obj_t* stepValue;
67+
lv_obj_t* stopWatchIcon;
68+
lv_obj_t* stopWatchValue;
6469
lv_obj_t* notificationIcon;
6570
lv_obj_t* weatherIcon;
6671
lv_obj_t* temperature;
@@ -70,6 +75,7 @@ namespace Pinetime {
7075
Controllers::Settings& settingsController;
7176
Controllers::HeartRateController& heartRateController;
7277
Controllers::MotionController& motionController;
78+
Controllers::StopWatchController& stopWatchController;
7379
Controllers::SimpleWeatherService& weatherService;
7480

7581
lv_task_t* taskRefresh;
@@ -91,6 +97,7 @@ namespace Pinetime {
9197
controllers.settingsController,
9298
controllers.heartRateController,
9399
controllers.motionController,
100+
controllers.stopWatchController,
94101
*controllers.weatherController);
95102
};
96103

0 commit comments

Comments
 (0)