Skip to content

Commit 23f1789

Browse files
committed
improved naming of lap-related fields and methods
1 parent 4bc164e commit 23f1789

3 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/components/stopwatch/StopWatchController.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@ void StopWatchController::Clear() {
2222
currentState = StopWatchStates::Cleared;
2323
timeElapsedPreviously = 0;
2424

25-
for (int i = 0; i < lapCapacity; i++) {
26-
laps[i].count = 0;
27-
laps[i].time = 0;
25+
for (int i = 0; i < histSize; i++) {
26+
history[i].number = 0;
27+
history[i].timeSinceStart = 0;
2828
}
29-
lapCount = 0;
29+
maxLapNumber = 0;
3030
}
3131

3232
// Lap
3333

34-
void StopWatchController::PushLap() {
34+
void StopWatchController::AddLapToHistory() {
3535
TickType_t lapEnd = GetElapsedTime();
36-
laps[0].time = lapEnd;
37-
laps[0].count = ++lapCount;
38-
laps--;
36+
history[0].timeSinceStart = lapEnd;
37+
history[0].number = ++maxLapNumber;
38+
history--;
3939
}
4040

41-
int StopWatchController::GetLapCount() {
42-
return lapCount;
41+
int StopWatchController::GetMaxLapNumber() {
42+
return maxLapNumber;
4343
}
4444

45-
std::optional<LapInfo> StopWatchController::LastLap(int lap) {
46-
if (lap < 0 || lap >= lapCapacity || laps[lap].count == 0) {
45+
std::optional<LapInfo> StopWatchController::GetLapFromHistory(int index) {
46+
if (index < 0 || index >= histSize || history[index].number == 0) {
4747
return {};
4848
}
49-
return laps[lap];
49+
return history[index];
5050
}
5151

5252
// Data / State acess

src/components/stopwatch/StopWatchController.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Pinetime {
1414
enum class StopWatchStates { Cleared, Running, Paused };
1515

1616
struct LapInfo {
17-
int count = 0; // Used to label the lap
18-
TickType_t time = 0; // Delta time from beginning of stopwatch
17+
int number = 0; // Used to label the lap
18+
TickType_t timeSinceStart = 0; // Excluding pauses
1919
};
2020

2121

@@ -32,14 +32,14 @@ namespace Pinetime {
3232

3333
// Lap functionality
3434

35-
/// Only the latest laps are stored, the lap count is saved until reset
36-
void PushLap();
35+
/// Only the latest histSize laps are stored
36+
void AddLapToHistory();
3737

38-
/// Returns lapCount
39-
int GetLapCount();
38+
/// Returns maxLapNumber
39+
int GetMaxLapNumber();
4040

4141
/// Indexes into lap history, with 0 being the latest lap.
42-
std::optional<LapInfo> LastLap(int lap = 0);
42+
std::optional<LapInfo> GetLapFromHistory(int index);
4343

4444
bool IsRunning();
4545
bool IsCleared();
@@ -53,12 +53,12 @@ namespace Pinetime {
5353
// How much time was elapsed before current duration
5454
TickType_t timeElapsedPreviously = 0;
5555

56-
// Number of stored laps
57-
static constexpr int lapCapacity = 2;
56+
// Maximum number of stored laps
57+
static constexpr int histSize = 2;
5858
// Lap storage
59-
Utility::CircularBuffer<LapInfo, lapCapacity> laps;
60-
// Total lap count; may exceed lapCapacity
61-
int lapCount = 0;
59+
Utility::CircularBuffer<LapInfo, histSize> history;
60+
// Highest lap number; may exceed histSize
61+
int maxLapNumber = 0;
6262
};
6363
}
6464
}

src/displayapp/screens/StopWatch.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ StopWatch::StopWatch(System::SystemTask& systemTask,
8181
if (stopWatchController.IsCleared()) {
8282
DisplayCleared();
8383
} else {
84-
if (stopWatchController.GetLapCount() > 0) {
84+
if (stopWatchController.GetMaxLapNumber() > 0) {
8585
RenderLaps();
8686
}
8787
RenderTime();
@@ -177,12 +177,12 @@ void StopWatch::RenderPause() {
177177
void StopWatch::RenderLaps() {
178178
lv_label_set_text(lapText, "");
179179
for (int i = 0; i < displayedLaps; i++) {
180-
std::optional<LapInfo> lap = stopWatchController.LastLap(i);
180+
std::optional<LapInfo> lap = stopWatchController.GetLapFromHistory(i);
181181

182182
if (lap) {
183-
TimeSeparated laptime = ConvertTicksToTimeSegments(lap->time);
183+
TimeSeparated laptime = ConvertTicksToTimeSegments(lap->timeSinceStart);
184184
char buffer[16];
185-
sprintf(buffer, "#%2d %2d:%02d.%02d\n", lap->count, laptime.mins, laptime.secs, laptime.hundredths);
185+
sprintf(buffer, "#%2d %2d:%02d.%02d\n", lap->number, laptime.mins, laptime.secs, laptime.hundredths);
186186
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, buffer);
187187
} else {
188188
lv_label_ins_text(lapText, LV_LABEL_POS_LAST, "\n");
@@ -213,7 +213,7 @@ void StopWatch::PlayPauseBtnEventHandler() {
213213

214214
void StopWatch::StopLapBtnEventHandler() {
215215
if (stopWatchController.IsRunning()) {
216-
stopWatchController.PushLap();
216+
stopWatchController.AddLapToHistory();
217217
RenderLaps();
218218
} else if (stopWatchController.IsPaused()) {
219219
stopWatchController.Clear();

0 commit comments

Comments
 (0)