diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index 8d029019b6..b898e49db9 100644 --- a/src/displayapp/screens/StopWatch.cpp +++ b/src/displayapp/screens/StopWatch.cpp @@ -6,7 +6,7 @@ using namespace Pinetime::Applications::Screens; using namespace Pinetime::Controllers; -namespace { +namespace Pinetime::Applications::Screens { TimeSeparated ConvertTicksToTimeSegments(const TickType_t timeElapsed) { const uint32_t timeElapsedSecs = timeElapsed / configTICK_RATE_HZ; const uint16_t timeElapsedFraction = timeElapsed % configTICK_RATE_HZ; @@ -17,7 +17,9 @@ namespace { const uint16_t hours = (timeElapsedSecs / 60) / 60; return TimeSeparated {hours, mins, secs, hundredths, timeElapsedSecs}; } +} +namespace { void PlayPauseEventHandler(lv_obj_t* obj, lv_event_t event) { auto* stopWatch = static_cast(obj->user_data); if (event == LV_EVENT_CLICKED) { diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h index 5bc254ca1c..be5454cc64 100644 --- a/src/displayapp/screens/StopWatch.h +++ b/src/displayapp/screens/StopWatch.h @@ -20,6 +20,8 @@ namespace Pinetime::Applications { uint32_t epochSecs; }; + TimeSeparated ConvertTicksToTimeSegments(const TickType_t timeElapsed); + class StopWatch : public Screen { public: explicit StopWatch(System::SystemTask& systemTask, Controllers::StopWatchController& stopWatchController); diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index a037abfe16..cfcd286221 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -6,6 +6,8 @@ #include "displayapp/screens/NotificationIcon.h" #include "displayapp/screens/Symbols.h" #include "displayapp/screens/WeatherSymbols.h" +#include "displayapp/screens/WeatherSymbols.h" +#include "displayapp/screens/StopWatch.h" #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/ble/NotificationManager.h" @@ -24,6 +26,7 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, Controllers::MotionController& motionController, + Controllers::StopWatchController& stopWatchController, Controllers::SimpleWeatherService& weatherService) : currentDateTime {{}}, dateTimeController {dateTimeController}, @@ -31,6 +34,7 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, settingsController {settingsController}, heartRateController {heartRateController}, motionController {motionController}, + stopWatchController {stopWatchController}, weatherService {weatherService}, statusIcons(batteryController, bleController, alarmController) { @@ -86,6 +90,16 @@ WatchFaceDigital::WatchFaceDigital(Controllers::DateTime& dateTimeController, lv_label_set_text_static(stepIcon, Symbols::shoe); lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0); + stopWatchIcon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(stopWatchIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + lv_label_set_text_static(stopWatchIcon, ""); + lv_obj_align(stopWatchIcon, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0); + + stopWatchValue = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(stopWatchValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + lv_label_set_text_static(stopWatchValue, ""); + lv_obj_align(stopWatchValue, stopWatchIcon, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); Refresh(); } @@ -172,6 +186,26 @@ void WatchFaceDigital::Refresh() { lv_obj_realign(stepIcon); } + stopWatchTime = stopWatchController.GetElapsedTime(); + stopWatchRunning = !stopWatchController.IsCleared(); + if (stopWatchTime.IsUpdated() || stopWatchRunning.IsUpdated()) { + if (stopWatchRunning.Get()) { + TimeSeparated elapsedTime = ConvertTicksToTimeSegments(stopWatchTime.Get()); + lv_label_set_text_fmt(stopWatchValue, + "%02d:%02d:%02d:%02d", + elapsedTime.hours, + elapsedTime.mins, + elapsedTime.secs, + elapsedTime.hundredths); + lv_label_set_text_static(stopWatchIcon, Symbols::stopWatch); + } else { + lv_label_set_text_fmt(stopWatchValue, ""); + lv_label_set_text_static(stopWatchIcon, ""); + } + lv_obj_realign(stopWatchValue); + lv_obj_realign(stopWatchIcon); + } + currentWeather = weatherService.Current(); if (currentWeather.IsUpdated()) { auto optCurrentWeather = currentWeather.Get(); diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index e3a1ac649a..468e924806 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -36,6 +36,7 @@ namespace Pinetime { Controllers::Settings& settingsController, Controllers::HeartRateController& heartRateController, Controllers::MotionController& motionController, + Controllers::StopWatchController& stopWatchController, Controllers::SimpleWeatherService& weather); ~WatchFaceDigital() override; @@ -47,6 +48,8 @@ namespace Pinetime { Utility::DirtyValue> currentDateTime {}; Utility::DirtyValue stepCount {}; + Utility::DirtyValue stopWatchTime {}; + Utility::DirtyValue stopWatchRunning {}; Utility::DirtyValue heartbeat {}; Utility::DirtyValue heartbeatRunning {}; Utility::DirtyValue notificationState {}; @@ -61,6 +64,8 @@ namespace Pinetime { lv_obj_t* heartbeatValue; lv_obj_t* stepIcon; lv_obj_t* stepValue; + lv_obj_t* stopWatchIcon; + lv_obj_t* stopWatchValue; lv_obj_t* notificationIcon; lv_obj_t* weatherIcon; lv_obj_t* temperature; @@ -70,6 +75,7 @@ namespace Pinetime { Controllers::Settings& settingsController; Controllers::HeartRateController& heartRateController; Controllers::MotionController& motionController; + Controllers::StopWatchController& stopWatchController; Controllers::SimpleWeatherService& weatherService; lv_task_t* taskRefresh; @@ -91,6 +97,7 @@ namespace Pinetime { controllers.settingsController, controllers.heartRateController, controllers.motionController, + controllers.stopWatchController, *controllers.weatherController); };