aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/stopwatch/StopWatchController.cpp26
-rw-r--r--src/components/stopwatch/StopWatchController.h24
-rw-r--r--src/displayapp/screens/StopWatch.cpp10
3 files changed, 30 insertions, 30 deletions
diff --git a/src/components/stopwatch/StopWatchController.cpp b/src/components/stopwatch/StopWatchController.cpp
index d8e48588..7af80367 100644
--- a/src/components/stopwatch/StopWatchController.cpp
+++ b/src/components/stopwatch/StopWatchController.cpp
@@ -22,31 +22,31 @@ void StopWatchController::Clear() {
currentState = StopWatchStates::Cleared;
timeElapsedPreviously = 0;
- for (int i = 0; i < lapCapacity; i++) {
- laps[i].count = 0;
- laps[i].time = 0;
+ for (int i = 0; i < histSize; i++) {
+ history[i].number = 0;
+ history[i].timeSinceStart = 0;
}
- lapCount = 0;
+ maxLapNumber = 0;
}
// Lap
-void StopWatchController::PushLap() {
+void StopWatchController::AddLapToHistory() {
TickType_t lapEnd = GetElapsedTime();
- laps[0].time = lapEnd;
- laps[0].count = ++lapCount;
- laps--;
+ history[0].timeSinceStart = lapEnd;
+ history[0].number = ++maxLapNumber;
+ history--;
}
-int StopWatchController::GetLapCount() {
- return lapCount;
+int StopWatchController::GetMaxLapNumber() {
+ return maxLapNumber;
}
-std::optional<LapInfo> StopWatchController::LastLap(int lap) {
- if (lap < 0 || lap >= lapCapacity || laps[lap].count == 0) {
+std::optional<LapInfo> StopWatchController::GetLapFromHistory(int index) {
+ if (index < 0 || index >= histSize || history[index].number == 0) {
return {};
}
- return laps[lap];
+ return history[index];
}
// Data / State acess
diff --git a/src/components/stopwatch/StopWatchController.h b/src/components/stopwatch/StopWatchController.h
index 626f214f..9386e351 100644
--- a/src/components/stopwatch/StopWatchController.h
+++ b/src/components/stopwatch/StopWatchController.h
@@ -14,8 +14,8 @@ namespace Pinetime {
enum class StopWatchStates { Cleared, Running, Paused };
struct LapInfo {
- int count = 0; // Used to label the lap
- TickType_t time = 0; // Delta time from beginning of stopwatch
+ int number = 0; // Used to label the lap
+ TickType_t timeSinceStart = 0; // Excluding pauses
};
@@ -32,14 +32,14 @@ namespace Pinetime {
// Lap functionality
- /// Only the latest laps are stored, the lap count is saved until reset
- void PushLap();
+ /// Only the latest histSize laps are stored
+ void AddLapToHistory();
- /// Returns lapCount
- int GetLapCount();
+ /// Returns maxLapNumber
+ int GetMaxLapNumber();
/// Indexes into lap history, with 0 being the latest lap.
- std::optional<LapInfo> LastLap(int lap = 0);
+ std::optional<LapInfo> GetLapFromHistory(int index);
bool IsRunning();
bool IsCleared();
@@ -53,12 +53,12 @@ namespace Pinetime {
// How much time was elapsed before current duration
TickType_t timeElapsedPreviously = 0;
- // Number of stored laps
- static constexpr int lapCapacity = 2;
+ // Maximum number of stored laps
+ static constexpr int histSize = 2;
// Lap storage
- Utility::CircularBuffer<LapInfo, lapCapacity> laps;
- // Total lap count; may exceed lapCapacity
- int lapCount = 0;
+ Utility::CircularBuffer<LapInfo, histSize> history;
+ // Highest lap number; may exceed histSize
+ int maxLapNumber = 0;
};
}
}
diff --git a/src/displayapp/screens/StopWatch.cpp b/src/displayapp/screens/StopWatch.cpp
index cc11f885..5d3404cc 100644
--- a/src/displayapp/screens/StopWatch.cpp
+++ b/src/displayapp/screens/StopWatch.cpp
@@ -81,7 +81,7 @@ StopWatch::StopWatch(System::SystemTask& systemTask,
if (stopWatchController.IsCleared()) {
DisplayCleared();
} else {
- if (stopWatchController.GetLapCount() > 0) {
+ if (stopWatchController.GetMaxLapNumber() > 0) {
RenderLaps();
}
RenderTime();
@@ -177,12 +177,12 @@ void StopWatch::RenderPause() {
void StopWatch::RenderLaps() {
lv_label_set_text(lapText, "");
for (int i = 0; i < displayedLaps; i++) {
- std::optional<LapInfo> lap = stopWatchController.LastLap(i);
+ std::optional<LapInfo> lap = stopWatchController.GetLapFromHistory(i);
if (lap) {
- TimeSeparated laptime = ConvertTicksToTimeSegments(lap->time);
+ TimeSeparated laptime = ConvertTicksToTimeSegments(lap->timeSinceStart);
char buffer[16];
- sprintf(buffer, "#%2d %2d:%02d.%02d\n", lap->count, laptime.mins, laptime.secs, laptime.hundredths);
+ sprintf(buffer, "#%2d %2d:%02d.%02d\n", lap->number, laptime.mins, laptime.secs, laptime.hundredths);
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer);
} else {
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, "\n");
@@ -213,7 +213,7 @@ void StopWatch::PlayPauseBtnEventHandler() {
void StopWatch::StopLapBtnEventHandler() {
if (stopWatchController.IsRunning()) {
- stopWatchController.PushLap();
+ stopWatchController.AddLapToHistory();
RenderLaps();
} else if (stopWatchController.IsPaused()) {
stopWatchController.Clear();