diff options
Diffstat (limited to 'src/displayapp/screens/StopWatch.cpp')
| -rw-r--r-- | src/displayapp/screens/StopWatch.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index 72904c88..ff852beb 100644 --- a/src/displayapp/screens/StopWatch.cpp +++ b/src/displayapp/screens/StopWatch.cpp @@ -12,8 +12,9 @@ namespace { const int hundredths = (timeElapsedCentis % 100); const int secs = (timeElapsedCentis / 100) % 60; - const int mins = (timeElapsedCentis / 100) / 60; - return TimeSeparated_t {mins, secs, hundredths}; + const int mins = ((timeElapsedCentis / 100) / 60) % 60; + const int hours = ((timeElapsedCentis / 100) / 60) / 60; + return TimeSeparated_t {hours, mins, secs, hundredths}; } void play_pause_event_handler(lv_obj_t* obj, lv_event_t event) { @@ -33,7 +34,7 @@ namespace { constexpr TickType_t blinkInterval = pdMS_TO_TICKS(1000); } -StopWatch::StopWatch(System::SystemTask& systemTask) : systemTask {systemTask} { +StopWatch::StopWatch(System::SystemTask& systemTask) : wakeLock(systemTask) { static constexpr uint8_t btnWidth = 115; static constexpr uint8_t btnHeight = 80; btnPlayPause = lv_btn_create(lv_scr_act(), nullptr); @@ -78,7 +79,6 @@ StopWatch::StopWatch(System::SystemTask& systemTask) : systemTask {systemTask} { StopWatch::~StopWatch() { lv_task_del(taskRefresh); - systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); lv_obj_clean(lv_scr_act()); } @@ -110,6 +110,12 @@ void StopWatch::SetInterfaceStopped() { lv_label_set_text_static(time, "00:00"); lv_label_set_text_static(msecTime, "00"); + if (isHoursLabelUpdated) { + lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); + lv_obj_realign(time); + isHoursLabelUpdated = false; + } + lv_label_set_text_static(lapText, ""); lv_label_set_text_static(txtPlayPause, Symbols::play); lv_label_set_text_static(txtStopLap, Symbols::lapsFlag); @@ -128,7 +134,7 @@ void StopWatch::Start() { SetInterfaceRunning(); startTime = xTaskGetTickCount(); currentState = States::Running; - systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); + wakeLock.Lock(); } void StopWatch::Pause() { @@ -138,7 +144,7 @@ void StopWatch::Pause() { oldTimeElapsed = laps[lapsDone]; blinkTime = xTaskGetTickCount() + blinkInterval; currentState = States::Halted; - systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); + wakeLock.Release(); } void StopWatch::Refresh() { @@ -146,7 +152,16 @@ void StopWatch::Refresh() { laps[lapsDone] = oldTimeElapsed + xTaskGetTickCount() - startTime; TimeSeparated_t currentTimeSeparated = convertTicksToTimeSegments(laps[lapsDone]); - lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs); + if (currentTimeSeparated.hours == 0) { + lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs); + } else { + lv_label_set_text_fmt(time, "%02d:%02d:%02d", currentTimeSeparated.hours, currentTimeSeparated.mins, currentTimeSeparated.secs); + if (!isHoursLabelUpdated) { + lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); + lv_obj_realign(time); + isHoursLabelUpdated = true; + } + } lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths); } else if (currentState == States::Halted) { const TickType_t currentTime = xTaskGetTickCount(); @@ -182,8 +197,12 @@ void StopWatch::stopLapBtnEventHandler() { continue; } TimeSeparated_t times = convertTicksToTimeSegments(laps[i]); - char buffer[16]; - sprintf(buffer, "#%2d %2d:%02d.%02d\n", i + 1, times.mins, times.secs, times.hundredths); + char buffer[17]; + if (times.hours == 0) { + snprintf(buffer, sizeof(buffer), "#%2d %2d:%02d.%02d\n", i + 1, times.mins, times.secs, times.hundredths); + } else { + snprintf(buffer, sizeof(buffer), "#%2d %2d:%02d:%02d.%02d\n", i + 1, times.hours, times.mins, times.secs, times.hundredths); + } lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer); } } else if (currentState == States::Halted) { |
