Skip to content

Commit d472a71

Browse files
fossisonfossisonJF002
authored
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>
1 parent 5d45392 commit d472a71

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/displayapp/screens/StopWatch.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ namespace {
1212

1313
const int hundredths = (timeElapsedCentis % 100);
1414
const int secs = (timeElapsedCentis / 100) % 60;
15-
const int mins = (timeElapsedCentis / 100) / 60;
16-
return TimeSeparated_t {mins, secs, hundredths};
15+
const int mins = ((timeElapsedCentis / 100) / 60) % 60;
16+
const int hours = ((timeElapsedCentis / 100) / 60) / 60;
17+
return TimeSeparated_t {hours, mins, secs, hundredths};
1718
}
1819

1920
void play_pause_event_handler(lv_obj_t* obj, lv_event_t event) {
@@ -110,6 +111,12 @@ void StopWatch::SetInterfaceStopped() {
110111
lv_label_set_text_static(time, "00:00");
111112
lv_label_set_text_static(msecTime, "00");
112113

114+
if (isHoursLabelUpdated) {
115+
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
116+
lv_obj_realign(time);
117+
isHoursLabelUpdated = false;
118+
}
119+
113120
lv_label_set_text_static(lapText, "");
114121
lv_label_set_text_static(txtPlayPause, Symbols::play);
115122
lv_label_set_text_static(txtStopLap, Symbols::lapsFlag);
@@ -146,7 +153,16 @@ void StopWatch::Refresh() {
146153
laps[lapsDone] = oldTimeElapsed + xTaskGetTickCount() - startTime;
147154

148155
TimeSeparated_t currentTimeSeparated = convertTicksToTimeSegments(laps[lapsDone]);
149-
lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
156+
if (currentTimeSeparated.hours == 0) {
157+
lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
158+
} else {
159+
lv_label_set_text_fmt(time, "%02d:%02d:%02d", currentTimeSeparated.hours, currentTimeSeparated.mins, currentTimeSeparated.secs);
160+
if (!isHoursLabelUpdated) {
161+
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
162+
lv_obj_realign(time);
163+
isHoursLabelUpdated = true;
164+
}
165+
}
150166
lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths);
151167
} else if (currentState == States::Halted) {
152168
const TickType_t currentTime = xTaskGetTickCount();
@@ -183,7 +199,11 @@ void StopWatch::stopLapBtnEventHandler() {
183199
}
184200
TimeSeparated_t times = convertTicksToTimeSegments(laps[i]);
185201
char buffer[16];
186-
sprintf(buffer, "#%2d %2d:%02d.%02d\n", i + 1, times.mins, times.secs, times.hundredths);
202+
if (times.hours == 0) {
203+
sprintf(buffer, "#%2d %2d:%02d.%02d\n", i + 1, times.mins, times.secs, times.hundredths);
204+
} else {
205+
sprintf(buffer, "#%2d %2d:%02d:%02d.%02d\n", i + 1, times.hours, times.mins, times.secs, times.hundredths);
206+
}
187207
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer);
188208
}
189209
} else if (currentState == States::Halted) {

src/displayapp/screens/StopWatch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Pinetime::Applications::Screens {
1313
enum class States { Init, Running, Halted };
1414

1515
struct TimeSeparated_t {
16+
int hours;
1617
int mins;
1718
int secs;
1819
int hundredths;
@@ -48,6 +49,7 @@ namespace Pinetime::Applications::Screens {
4849
int lapsDone = 0;
4950
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
5051
lv_obj_t* lapText;
52+
bool isHoursLabelUpdated = false;
5153

5254
lv_task_t* taskRefresh;
5355
};

0 commit comments

Comments
 (0)