Skip to content

Commit 135e5f8

Browse files
committed
tightened declarations of integer fields
1 parent 42729f8 commit 135e5f8

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

src/components/stopwatch/StopWatchController.cpp

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

25-
for (int i = 0; i < histSize; i++) {
25+
for (uint8_t i = 0; i < histSize; i++) {
2626
history[i].number = 0;
2727
history[i].timeSinceStart = 0;
2828
}
@@ -38,12 +38,12 @@ void StopWatchController::AddLapToHistory() {
3838
history[0].number = ++maxLapNumber % lapNumberBoundary;
3939
}
4040

41-
int StopWatchController::GetMaxLapNumber() {
41+
uint16_t StopWatchController::GetMaxLapNumber() {
4242
return maxLapNumber;
4343
}
4444

45-
std::optional<LapInfo> StopWatchController::GetLapFromHistory(int index) {
46-
if (index < 0 || index >= histSize || history[index].number == 0) {
45+
std::optional<LapInfo> StopWatchController::GetLapFromHistory(uint8_t index) {
46+
if (index >= histSize || history[index].number == 0) {
4747
return {};
4848
}
4949
return history[index];

src/components/stopwatch/StopWatchController.h

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

1717
struct LapInfo {
18-
int number = 0; // Used to label the lap
18+
uint16_t number = 0; // Used to label the lap
1919
TickType_t timeSinceStart = 0; // Excluding pauses
2020
};
2121

@@ -36,18 +36,18 @@ namespace Pinetime {
3636
void AddLapToHistory();
3737

3838
/// Returns maxLapNumber
39-
int GetMaxLapNumber();
39+
uint16_t GetMaxLapNumber();
4040

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

4444
bool IsRunning();
4545
bool IsCleared();
4646
bool IsPaused();
4747

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

5858
// Maximum number of stored laps
59-
static constexpr int histSize = 4;
59+
static constexpr uint8_t histSize = 4;
6060
// Value at which lap numbers wrap around to zero
61-
static constexpr int lapNumberBoundary = 1000;
61+
static constexpr uint16_t lapNumberBoundary = 1000;
6262
// Lap storage
6363
Utility::CircularBuffer<LapInfo, histSize> history;
6464
// Highest lap number; less than lapNumberBoundary, may exceed histSize
65-
int maxLapNumber;
65+
uint16_t maxLapNumber;
6666
};
6767
}
6868
}

src/displayapp/screens/StopWatch.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ using namespace Pinetime::Controllers;
88

99
namespace {
1010
TimeSeparated ConvertTicksToTimeSegments(const TickType_t timeElapsed) {
11-
const int timeElapsedSecs = timeElapsed / configTICK_RATE_HZ;
12-
const int timeElapsedFraction = timeElapsed % configTICK_RATE_HZ;
11+
const uint32_t timeElapsedSecs = timeElapsed / configTICK_RATE_HZ;
12+
const uint16_t timeElapsedFraction = timeElapsed % configTICK_RATE_HZ;
1313

14-
const int hundredths = timeElapsedFraction * 100 / configTICK_RATE_HZ;
15-
const int secs = (timeElapsedSecs) % 60;
16-
const int mins = (timeElapsedSecs / 60) % 60;
17-
const int hours = (timeElapsedSecs / 60) / 60;
14+
const uint8_t hundredths = timeElapsedFraction * 100 / configTICK_RATE_HZ;
15+
const uint8_t secs = (timeElapsedSecs) % 60;
16+
const uint8_t mins = (timeElapsedSecs / 60) % 60;
17+
const uint16_t hours = (timeElapsedSecs / 60) / 60;
1818
return TimeSeparated {hours, mins, secs, hundredths, timeElapsedSecs};
1919
}
2020

src/displayapp/screens/StopWatch.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace Pinetime::Applications {
1313
namespace Screens {
1414

1515
struct TimeSeparated {
16-
int hours;
17-
int mins;
18-
int secs;
19-
int hundredths;
20-
int epochSecs;
16+
uint16_t hours;
17+
uint8_t mins;
18+
uint8_t secs;
19+
uint8_t hundredths;
20+
uint32_t epochSecs;
2121
};
2222

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

0 commit comments

Comments
 (0)