Adding laps completed.

This commit is contained in:
panky-codes 2021-03-13 13:59:54 +01:00
parent 00f2a053bf
commit 5d57b9054a
2 changed files with 17 additions and 6 deletions

View File

@ -52,10 +52,12 @@ StopWatch::StopWatch(DisplayApp* app, const Pinetime::Controllers::DateTime& dat
time = lv_label_create(lv_scr_act(), nullptr); time = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_extrabold_compressed); lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_extrabold_compressed);
lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -50); lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -50);
lv_label_set_text(time, "00:00");
msecTime = lv_label_create(lv_scr_act(), nullptr); msecTime = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20); lv_obj_set_style_local_text_font(msecTime, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
lv_obj_align(msecTime, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 113, 0); lv_obj_align(msecTime, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 113, 0);
lv_label_set_text(msecTime, "00");
btnPlayPause = lv_btn_create(lv_scr_act(), nullptr); btnPlayPause = lv_btn_create(lv_scr_act(), nullptr);
btnPlayPause->user_data = this; btnPlayPause->user_data = this;
@ -97,6 +99,8 @@ bool StopWatch::Refresh() {
lv_label_set_text(lapOneText, ""); lv_label_set_text(lapOneText, "");
lv_label_set_text(lapTwoText, ""); lv_label_set_text(lapTwoText, "");
lapBuffer.clearBuffer();
lapNr = 0;
if (currentEvent == Events::PLAY) { if (currentEvent == Events::PLAY) {
btnStopLap = lv_btn_create(lv_scr_act(), nullptr); btnStopLap = lv_btn_create(lv_scr_act(), nullptr);
@ -124,11 +128,11 @@ bool StopWatch::Refresh() {
lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.msecs); lv_label_set_text_fmt(msecTime, "%02d", currentTimeSeparated.msecs);
if (lapPressed == true) { if (lapPressed == true) {
if (lapBuffer[0]) {
lv_label_set_text_fmt(lapOneText, "#%d %d:%d:%d", (lapNr - 1), lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->msecs);
}
if (lapBuffer[1]) { if (lapBuffer[1]) {
lv_label_set_text_fmt(lapTwoText, "#%d %d:%d:%d", lapNr, lapBuffer[1]->mins, lapBuffer[1]->secs, lapBuffer[1]->msecs); lv_label_set_text_fmt(lapOneText, "#%d %d:%d:%d", (lapNr - 1), lapBuffer[1]->mins, lapBuffer[1]->secs, lapBuffer[1]->msecs);
}
if (lapBuffer[0]) {
lv_label_set_text_fmt(lapTwoText, "#%d %d:%d:%d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->msecs);
} }
// Reset the bool to avoid setting the text in each cycle // Reset the bool to avoid setting the text in each cycle
lapPressed = false; lapPressed = false;

View File

@ -26,20 +26,27 @@ namespace Pinetime::Applications::Screens {
} }
void addLaps(const TimeSeparated_t& timeVal) { void addLaps(const TimeSeparated_t& timeVal) {
head++;
head %= capacity; head %= capacity;
_arr[head++] = timeVal; _arr[head] = timeVal;
if (currentSz < capacity) { if (currentSz < capacity) {
currentSz++; currentSz++;
} }
} }
void clearBuffer() {
_arr = {};
currentSz = 0;
head = -1;
}
// Optional return type would be much more appropriate here // Optional return type would be much more appropriate here
TimeSeparated_t* operator[](std::size_t idx) { TimeSeparated_t* operator[](std::size_t idx) {
// Sanity check for out-of-bounds // Sanity check for out-of-bounds
if (idx >= 0 && idx < capacity) { if (idx >= 0 && idx < capacity) {
if (idx < currentSz) { if (idx < currentSz) {
const auto transformed_idx = (head + capacity - idx) % capacity; const auto transformed_idx = (head - idx) % capacity;
return (&_arr[transformed_idx]); return (&_arr[transformed_idx]);
} }
} }