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>
This commit is contained in:
parent
5d45392453
commit
d472a71078
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user