summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/StopWatch.h
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2022-07-22 11:01:47 +0300
committerJF <JF002@users.noreply.github.com>2022-08-02 22:51:59 +0200
commit67e0cad5733c6d3201f1414b89c8faf568dcb2bd (patch)
treeb0a5de22f4f3dfac5eb61176fe417e65ddabebe3 /src/displayapp/screens/StopWatch.h
parent1467324c5011e1f9eb0c363b6f9975dd7888fcf2 (diff)
Simplified stopwatch lap buffer
Overriding the earlier laps doesn't seem like a good idea.
Diffstat (limited to 'src/displayapp/screens/StopWatch.h')
-rw-r--r--src/displayapp/screens/StopWatch.h58
1 files changed, 8 insertions, 50 deletions
diff --git a/src/displayapp/screens/StopWatch.h b/src/displayapp/screens/StopWatch.h
index ef55e2d2..f2f57110 100644
--- a/src/displayapp/screens/StopWatch.h
+++ b/src/displayapp/screens/StopWatch.h
@@ -1,13 +1,11 @@
#pragma once
#include "displayapp/screens/Screen.h"
-#include "components/datetime/DateTimeController.h"
-#include "displayapp/LittleVgl.h"
+#include <lvgl/lvgl.h>
#include <FreeRTOS.h>
#include "portmacro_cmsis.h"
-#include <array>
#include "systemtask/SystemTask.h"
namespace Pinetime::Applications::Screens {
@@ -20,46 +18,6 @@ namespace Pinetime::Applications::Screens {
int hundredths;
};
- // A simple buffer to hold the latest two laps
- template <int N> struct LapTextBuffer_t {
- LapTextBuffer_t() : buffer {}, currentSize {}, capacity {N}, head {-1} {
- }
-
- void addLaps(const TimeSeparated_t& timeVal) {
- head++;
- head %= capacity;
- buffer[head] = timeVal;
-
- if (currentSize < capacity) {
- currentSize++;
- }
- }
-
- void clearBuffer() {
- buffer = {};
- currentSize = 0;
- head = -1;
- }
-
- TimeSeparated_t* operator[](std::size_t idx) {
- // Sanity check for out-of-bounds
- if (idx >= 0 && idx < capacity) {
- if (idx < currentSize) {
- // This transformation is to ensure that head is always pointing to index 0.
- const auto transformed_idx = (head - idx) % capacity;
- return (&buffer[transformed_idx]);
- }
- }
- return nullptr;
- }
-
- private:
- std::array<TimeSeparated_t, N> buffer;
- uint8_t currentSize;
- uint8_t capacity;
- int8_t head;
- };
-
class StopWatch : public Screen {
public:
StopWatch(DisplayApp* app, System::SystemTask& systemTask);
@@ -76,15 +34,15 @@ namespace Pinetime::Applications::Screens {
private:
Pinetime::System::SystemTask& systemTask;
- TickType_t timeElapsed;
- States currentState;
+ States currentState = States::Init;
TickType_t startTime;
- TickType_t oldTimeElapsed;
- TimeSeparated_t currentTimeSeparated; // Holds Mins, Secs, millisecs
- LapTextBuffer_t<2> lapBuffer;
- int lapNr = 0;
+ TickType_t oldTimeElapsed = 0;
+ static constexpr int maxLapCount = 20;
+ TickType_t laps[maxLapCount + 1];
+ static constexpr int displayedLaps = 2;
+ int lapsDone = 0;
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
- lv_obj_t *lapOneText, *lapTwoText;
+ lv_obj_t* lapText;
lv_task_t* taskRefresh;
};