From d472a71078ba42b67acbb9f5cd1e9b6da5ed47dc Mon Sep 17 00:00:00 2001 From: fossison <100048769+fossison@users.noreply.github.com> Date: Sun, 16 Apr 2023 06:55:49 -0700 Subject: [PATCH] stopwatch: Add hours tracking (#1692) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stopwatch application : add hours tracking --------- Co-authored-by: fossison Co-authored-by: Jean-François Milants --- src/displayapp/screens/StopWatch.cpp | 28 ++++++++++++++++++++++++---- src/displayapp/screens/StopWatch.h | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp index 72904c88..239ebe39 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) { @@ -110,6 +111,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); @@ -146,7 +153,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(); @@ -183,7 +199,11 @@ void StopWatch::stopLapBtnEventHandler() { } TimeSeparated_t times = convertTicksToTimeSegments(laps[i]); char buffer[16]; - sprintf(buffer, "#%2d %2d:%02d.%02d\n", i + 1, times.mins, times.secs, times.hundredths); + if (times.hours == 0) { + sprintf(buffer, "#%2d %2d:%02d.%02d\n", i + 1, times.mins, times.secs, times.hundredths); + } else { + sprintf(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) { diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h index 409e3a19..d1acd162 100644 --- a/src/displayapp/screens/StopWatch.h +++ b/src/displayapp/screens/StopWatch.h @@ -13,6 +13,7 @@ namespace Pinetime::Applications::Screens { enum class States { Init, Running, Halted }; struct TimeSeparated_t { + int hours; int mins; int secs; int hundredths; @@ -48,6 +49,7 @@ namespace Pinetime::Applications::Screens { int lapsDone = 0; lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap; lv_obj_t* lapText; + bool isHoursLabelUpdated = false; lv_task_t* taskRefresh; };