Skip to content

Commit ee20df4

Browse files
committed
Changed MotionController::Days from enum to enum class
1 parent 7421df8 commit ee20df4

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

src/components/motion/MotionController.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ namespace {
3737

3838
void MotionController::AdvanceDay() {
3939
--nbSteps; // Higher index = further in the past
40-
nbSteps[Today] = 0;
40+
NbStepsRef(Days::Today) = 0;
4141
if (service != nullptr) {
42-
service->OnNewStepCountValue(nbSteps[Today]);
42+
service->OnNewStepCountValue(NbSteps(Days::Today));
4343
}
4444
}
4545

4646
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
47-
if (this->nbSteps[Today] != nbSteps && service != nullptr) {
47+
uint32_t& oldSteps = NbStepsRef(Days::Today);
48+
if (oldSteps != nbSteps && service != nullptr) {
4849
service->OnNewStepCountValue(nbSteps);
4950
}
5051

@@ -64,11 +65,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
6465

6566
stats = GetAccelStats();
6667

67-
int32_t deltaSteps = nbSteps - this->nbSteps[Today];
68+
int32_t deltaSteps = nbSteps - oldSteps;
6869
if (deltaSteps > 0) {
6970
currentTripSteps += deltaSteps;
7071
}
71-
this->nbSteps[Today] = nbSteps;
72+
oldSteps = nbSteps;
7273
}
7374

7475
MotionController::AccelStats MotionController::GetAccelStats() const {

src/components/motion/MotionController.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ namespace Pinetime {
1818
BMA425,
1919
};
2020

21-
enum Days {
21+
enum class Days : uint8_t {
2222
Today = 0,
23-
Yesterday = 1,
23+
Yesterday,
24+
Last,
2425
};
2526

26-
static constexpr size_t stepHistorySize = 2; // Store this many day's step counter
27+
static constexpr size_t stepHistorySize = static_cast<std::underlying_type_t<Days>>(Days::Last); // Store this many day's step counter
2728

2829
void AdvanceDay();
2930

@@ -41,8 +42,8 @@ namespace Pinetime {
4142
return zHistory[0];
4243
}
4344

44-
uint32_t NbSteps(Days day = Today) const {
45-
return nbSteps[day];
45+
uint32_t NbSteps(Days day = Days::Today) const {
46+
return nbSteps[static_cast<std::underlying_type_t<Days>>(day)];
4647
}
4748

4849
void ResetTrip() {
@@ -79,6 +80,10 @@ namespace Pinetime {
7980
Utility::CircularBuffer<uint32_t, stepHistorySize> nbSteps = {0};
8081
uint32_t currentTripSteps = 0;
8182

83+
uint32_t& NbStepsRef(Days day = Days::Today) {
84+
return nbSteps[static_cast<std::underlying_type_t<Days>>(day)];
85+
}
86+
8287
TickType_t lastTime = 0;
8388
TickType_t time = 0;
8489

0 commit comments

Comments
 (0)