Skip to content

Commit

Permalink
Removed unsigned ints
Browse files Browse the repository at this point in the history
These appear to have been the cause of my issues. Not sure why, I'd have
to know the nrf52832 better to diagnose it.
  • Loading branch information
Louis Pearson committed Nov 30, 2021
1 parent 2fd2cdb commit 9ea6bc3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
18 changes: 11 additions & 7 deletions src/components/stopwatch/StopWatchController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,38 @@ void StopWatch::pushLap(TickType_t lapEnd) {
lapHead = lapCount % LAP_CAPACITY;
}

uint32_t StopWatch::getLapNum() {
int StopWatch::getLapNum() {
if (lapCount < LAP_CAPACITY)
return lapCount;
else
return LAP_CAPACITY;
}

uint32_t StopWatch::getLapCount() {
int StopWatch::getLapCount() {
return lapCount;
}

LapInfo_t *StopWatch::lastLap(uint32_t lap) {
if (lap >= LAP_CAPACITY || lap >= lapCount || lapCount == 0) {
int wrap(int index) {
return ((index % LAP_CAPACITY) + LAP_CAPACITY) % LAP_CAPACITY;
}

LapInfo_t *StopWatch::lastLap(int lap) {
if (lap >= LAP_CAPACITY || lap > lapCount || lapCount == 0) {
// Return "empty" LapInfo_t
return &emptyLapInfo;
}
// Index backwards
uint32_t index = ((lapHead + LAP_CAPACITY) - lap) % LAP_CAPACITY;
int index = wrap(lapHead - lap);
return &laps[index];
}

// Data acess

uint32_t StopWatch::getStart() {
TickType_t StopWatch::getStart() {
return startTime;
}

uint32_t StopWatch::getElapsedPreviously() {
TickType_t StopWatch::getElapsedPreviously() {
return timeElapsedPreviously;
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/stopwatch/StopWatchController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Pinetime {
enum class StopWatchStates { Cleared, Running, Paused };

struct LapInfo_t {
uint32_t count = 0; // Used to label the lap
int count = 0; // Used to label the lap
TickType_t time = 0; // delta time from beginning of stopwatch
};

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

/// Returns actual count of stored laps
uint32_t getLapNum();
int getLapNum();

/// Returns lapCount
uint32_t getLapCount();
int getLapCount();

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

bool isRunning();
bool isCleared();
Expand All @@ -60,8 +60,8 @@ namespace Pinetime {
// Stores lap times
LapInfo_t laps[LAP_CAPACITY];
LapInfo_t emptyLapInfo = { .count = 0, .time = 0 };
uint32_t lapCount = 0;
uint32_t lapHead = 0;
int lapCount = 0;
int lapHead = 0;
};
}
}
7 changes: 2 additions & 5 deletions src/displayapp/screens/StopWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,8 @@ void StopWatch::Refresh() {
}

void StopWatch::refreshLaps() {
Pinetime::Controllers::LapInfo_t
// Latest lap
*lap1 = stopWatchController.lastLap(),
// Second latest lap
*lap2 = stopWatchController.lastLap(1);
Pinetime::Controllers::LapInfo_t *lap1 = stopWatchController.lastLap();
Pinetime::Controllers::LapInfo_t *lap2 = stopWatchController.lastLap(1);

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

0 comments on commit 9ea6bc3

Please sign in to comment.