Skip to content

Commit 9ea6bc3

Browse files
author
Louis Pearson
committed
Removed unsigned ints
These appear to have been the cause of my issues. Not sure why, I'd have to know the nrf52832 better to diagnose it.
1 parent 2fd2cdb commit 9ea6bc3

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/components/stopwatch/StopWatchController.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,34 +55,38 @@ void StopWatch::pushLap(TickType_t lapEnd) {
5555
lapHead = lapCount % LAP_CAPACITY;
5656
}
5757

58-
uint32_t StopWatch::getLapNum() {
58+
int StopWatch::getLapNum() {
5959
if (lapCount < LAP_CAPACITY)
6060
return lapCount;
6161
else
6262
return LAP_CAPACITY;
6363
}
6464

65-
uint32_t StopWatch::getLapCount() {
65+
int StopWatch::getLapCount() {
6666
return lapCount;
6767
}
6868

69-
LapInfo_t *StopWatch::lastLap(uint32_t lap) {
70-
if (lap >= LAP_CAPACITY || lap >= lapCount || lapCount == 0) {
69+
int wrap(int index) {
70+
return ((index % LAP_CAPACITY) + LAP_CAPACITY) % LAP_CAPACITY;
71+
}
72+
73+
LapInfo_t *StopWatch::lastLap(int lap) {
74+
if (lap >= LAP_CAPACITY || lap > lapCount || lapCount == 0) {
7175
// Return "empty" LapInfo_t
7276
return &emptyLapInfo;
7377
}
7478
// Index backwards
75-
uint32_t index = ((lapHead + LAP_CAPACITY) - lap) % LAP_CAPACITY;
79+
int index = wrap(lapHead - lap);
7680
return &laps[index];
7781
}
7882

7983
// Data acess
8084

81-
uint32_t StopWatch::getStart() {
85+
TickType_t StopWatch::getStart() {
8286
return startTime;
8387
}
8488

85-
uint32_t StopWatch::getElapsedPreviously() {
89+
TickType_t StopWatch::getElapsedPreviously() {
8690
return timeElapsedPreviously;
8791
}
8892

src/components/stopwatch/StopWatchController.h

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

1616
struct LapInfo_t {
17-
uint32_t count = 0; // Used to label the lap
17+
int count = 0; // Used to label the lap
1818
TickType_t time = 0; // delta time from beginning of stopwatch
1919
};
2020

@@ -36,15 +36,15 @@ namespace Pinetime {
3636
void pushLap(TickType_t lapEnd);
3737

3838
/// Returns actual count of stored laps
39-
uint32_t getLapNum();
39+
int getLapNum();
4040

4141
/// Returns lapCount
42-
uint32_t getLapCount();
42+
int getLapCount();
4343

4444
/// Indexes into lap history, with 0 being the latest lap.
4545
/// If the lap is unavailable, count and time will be 0. If there is a
4646
/// real value, count should be above 0
47-
LapInfo_t *lastLap(uint32_t lap=0);
47+
LapInfo_t *lastLap(int lap=0);
4848

4949
bool isRunning();
5050
bool isCleared();
@@ -60,8 +60,8 @@ namespace Pinetime {
6060
// Stores lap times
6161
LapInfo_t laps[LAP_CAPACITY];
6262
LapInfo_t emptyLapInfo = { .count = 0, .time = 0 };
63-
uint32_t lapCount = 0;
64-
uint32_t lapHead = 0;
63+
int lapCount = 0;
64+
int lapHead = 0;
6565
};
6666
}
6767
}

src/displayapp/screens/StopWatch.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,8 @@ void StopWatch::Refresh() {
183183
}
184184

185185
void StopWatch::refreshLaps() {
186-
Pinetime::Controllers::LapInfo_t
187-
// Latest lap
188-
*lap1 = stopWatchController.lastLap(),
189-
// Second latest lap
190-
*lap2 = stopWatchController.lastLap(1);
186+
Pinetime::Controllers::LapInfo_t *lap1 = stopWatchController.lastLap();
187+
Pinetime::Controllers::LapInfo_t *lap2 = stopWatchController.lastLap(1);
191188

192189
if (lap1->count != 0) {
193190
TimeSeparated_t laptime = convertTicksToTimeSegments(lap1->time);

0 commit comments

Comments
 (0)