Skip to content

Commit

Permalink
tightened declarations of integer fields
Browse files Browse the repository at this point in the history
  • Loading branch information
codingjourney committed Dec 14, 2024
1 parent 42729f8 commit 135e5f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/components/stopwatch/StopWatchController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void StopWatchController::Clear() {
currentState = StopWatchStates::Cleared;
timeElapsedPreviously = 0;

for (int i = 0; i < histSize; i++) {
for (uint8_t i = 0; i < histSize; i++) {
history[i].number = 0;
history[i].timeSinceStart = 0;
}
Expand All @@ -38,12 +38,12 @@ void StopWatchController::AddLapToHistory() {
history[0].number = ++maxLapNumber % lapNumberBoundary;
}

int StopWatchController::GetMaxLapNumber() {
uint16_t StopWatchController::GetMaxLapNumber() {
return maxLapNumber;
}

std::optional<LapInfo> StopWatchController::GetLapFromHistory(int index) {
if (index < 0 || index >= histSize || history[index].number == 0) {
std::optional<LapInfo> StopWatchController::GetLapFromHistory(uint8_t index) {
if (index >= histSize || history[index].number == 0) {
return {};
}
return history[index];
Expand Down
14 changes: 7 additions & 7 deletions src/components/stopwatch/StopWatchController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Pinetime {
enum class StopWatchStates { Cleared, Running, Paused };

struct LapInfo {
int number = 0; // Used to label the lap
uint16_t number = 0; // Used to label the lap
TickType_t timeSinceStart = 0; // Excluding pauses
};

Expand All @@ -36,18 +36,18 @@ namespace Pinetime {
void AddLapToHistory();

/// Returns maxLapNumber
int GetMaxLapNumber();
uint16_t GetMaxLapNumber();

/// Indexes into lap history, with 0 being the latest lap.
std::optional<LapInfo> GetLapFromHistory(int index);
std::optional<LapInfo> GetLapFromHistory(uint8_t index);

bool IsRunning();
bool IsCleared();
bool IsPaused();

private:
// Time at which stopwatch wraps around to zero (1000 hours)
static constexpr TickType_t elapsedTimeBoundary = (TickType_t) configTICK_RATE_HZ * 60 * 60 * 1000;
static constexpr TickType_t elapsedTimeBoundary = static_cast<TickType_t>(configTICK_RATE_HZ) * 60 * 60 * 1000;
// Current state of stopwatch
StopWatchStates currentState = StopWatchStates::Cleared;
// Start time of current duration
Expand All @@ -56,13 +56,13 @@ namespace Pinetime {
TickType_t timeElapsedPreviously;

// Maximum number of stored laps
static constexpr int histSize = 4;
static constexpr uint8_t histSize = 4;
// Value at which lap numbers wrap around to zero
static constexpr int lapNumberBoundary = 1000;
static constexpr uint16_t lapNumberBoundary = 1000;
// Lap storage
Utility::CircularBuffer<LapInfo, histSize> history;
// Highest lap number; less than lapNumberBoundary, may exceed histSize
int maxLapNumber;
uint16_t maxLapNumber;
};
}
}
12 changes: 6 additions & 6 deletions src/displayapp/screens/StopWatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ using namespace Pinetime::Controllers;

namespace {
TimeSeparated ConvertTicksToTimeSegments(const TickType_t timeElapsed) {
const int timeElapsedSecs = timeElapsed / configTICK_RATE_HZ;
const int timeElapsedFraction = timeElapsed % configTICK_RATE_HZ;
const uint32_t timeElapsedSecs = timeElapsed / configTICK_RATE_HZ;
const uint16_t timeElapsedFraction = timeElapsed % configTICK_RATE_HZ;

const int hundredths = timeElapsedFraction * 100 / configTICK_RATE_HZ;
const int secs = (timeElapsedSecs) % 60;
const int mins = (timeElapsedSecs / 60) % 60;
const int hours = (timeElapsedSecs / 60) / 60;
const uint8_t hundredths = timeElapsedFraction * 100 / configTICK_RATE_HZ;
const uint8_t secs = (timeElapsedSecs) % 60;
const uint8_t mins = (timeElapsedSecs / 60) % 60;
const uint16_t hours = (timeElapsedSecs / 60) / 60;
return TimeSeparated {hours, mins, secs, hundredths, timeElapsedSecs};
}

Expand Down
12 changes: 6 additions & 6 deletions src/displayapp/screens/StopWatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace Pinetime::Applications {
namespace Screens {

struct TimeSeparated {
int hours;
int mins;
int secs;
int hundredths;
int epochSecs;
uint16_t hours;
uint8_t mins;
uint8_t secs;
uint8_t hundredths;
uint32_t epochSecs;
};

class StopWatch : public Screen {
Expand Down Expand Up @@ -46,7 +46,7 @@ namespace Pinetime::Applications {
Pinetime::System::WakeLock wakeLock;
Controllers::StopWatchController& stopWatchController;
TickType_t blinkTime = 0;
int displayedLaps = 3;
uint8_t displayedLaps = 3;
lv_obj_t *time, *msecTime, *btnPlayPause, *btnStopLap, *txtPlayPause, *txtStopLap;
lv_obj_t* lapText;
Utility::DirtyValue<TickType_t> renderedSeconds;
Expand Down

0 comments on commit 135e5f8

Please sign in to comment.