Skip to content

Commit

Permalink
Fix stopwatch display issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Pearson committed Nov 30, 2021
1 parent ec2b673 commit 04a6b70
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/displayapp/screens/StopWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ StopWatch::StopWatch(DisplayApp* app, System::SystemTask& systemTask, Controller
lv_obj_set_style_local_text_color(dateTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);

taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);

if (stopWatchController.isRunning()) {
start();
} else if (stopWatchController.isPaused()) {
pause();
currentTimeSeparated = convertTicksToTimeSegments(stopWatchController.getElapsedPreviously());

lv_label_set_text_fmt(time, "%02d:%02d", currentTimeSeparated.mins, currentTimeSeparated.secs);
lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.hundredths);
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
}
}

StopWatch::~StopWatch() {
Expand All @@ -119,8 +131,6 @@ StopWatch::~StopWatch() {
}

void StopWatch::reset() {
stopWatchController.clear();

lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);

Expand All @@ -136,8 +146,6 @@ void StopWatch::reset() {
}

void StopWatch::start() {
stopWatchController.start(xTaskGetTickCount());

lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);
lv_obj_set_state(txtStopLap, LV_STATE_DEFAULT);
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
Expand All @@ -149,13 +157,14 @@ void StopWatch::start() {
}

void StopWatch::pause() {
stopWatchController.pause(xTaskGetTickCount());
lv_obj_set_state(btnStopLap, LV_STATE_DEFAULT);

lv_label_set_text(txtPlayPause, Symbols::play);
lv_label_set_text(txtStopLap, Symbols::stop);
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
lv_obj_set_style_local_text_color(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);

lv_label_set_text(txtPlayPause, Symbols::play);
lv_label_set_text(txtStopLap, Symbols::stop);

systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping);
}

Expand All @@ -176,8 +185,10 @@ void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
}
if (stopWatchController.isCleared() || stopWatchController.isPaused()) {
stopWatchController.start(xTaskGetTickCount());
start();
} else if (stopWatchController.isRunning()) {
stopWatchController.pause(xTaskGetTickCount());
pause();
}
}

Expand All @@ -197,13 +208,15 @@ void StopWatch::stopLapBtnEventHandler(lv_event_t event) {
lv_label_set_text_fmt(lapTwoText, "#%2d %2d:%02d.%02d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->hundredths);
}
} else if (stopWatchController.isPaused()) {
stopWatchController.clear();
reset();
}
}

bool StopWatch::OnButtonPushed() {
if (stopWatchController.isRunning()) {
stopWatchController.pause(xTaskGetTickCount());
pause();
return true;
}
return false;
Expand Down

0 comments on commit 04a6b70

Please sign in to comment.