aboutsummaryrefslogtreecommitdiffstats
path: root/src/displayapp/screens/StopWatch.cpp
diff options
context:
space:
mode:
authorfossison <100048769+fossison@users.noreply.github.com>2023-04-16 06:55:49 -0700
committerGitHub <noreply@github.com>2023-04-16 15:55:49 +0200
commitd472a71078ba42b67acbb9f5cd1e9b6da5ed47dc (patch)
tree9090647fd748d068c6385c3b2fb192451b533bd7 /src/displayapp/screens/StopWatch.cpp
parent5d45392453e964767cac98f806be3c2162b7c3e1 (diff)
stopwatch: Add hours tracking (#1692)
Stopwatch application : add hours tracking --------- Co-authored-by: fossison <fossison@mailbox.org> Co-authored-by: Jean-François Milants <jf@codingfield.com>
Diffstat (limited to 'src/displayapp/screens/StopWatch.cpp')
-rw-r--r--src/displayapp/screens/StopWatch.cpp28
1 files changed, 24 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) {