Skip to content

Commit

Permalink
Changed MotionController::Days from enum to enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
Hunman committed Sep 16, 2024
1 parent 7421df8 commit ee20df4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ namespace {

void MotionController::AdvanceDay() {
--nbSteps; // Higher index = further in the past
nbSteps[Today] = 0;
NbStepsRef(Days::Today) = 0;
if (service != nullptr) {
service->OnNewStepCountValue(nbSteps[Today]);
service->OnNewStepCountValue(NbSteps(Days::Today));
}
}

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

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

stats = GetAccelStats();

int32_t deltaSteps = nbSteps - this->nbSteps[Today];
int32_t deltaSteps = nbSteps - oldSteps;
if (deltaSteps > 0) {
currentTripSteps += deltaSteps;
}
this->nbSteps[Today] = nbSteps;
oldSteps = nbSteps;
}

MotionController::AccelStats MotionController::GetAccelStats() const {
Expand Down
15 changes: 10 additions & 5 deletions src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ namespace Pinetime {
BMA425,
};

enum Days {
enum class Days : uint8_t {
Today = 0,
Yesterday = 1,
Yesterday,
Last,
};

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

void AdvanceDay();

Expand All @@ -41,8 +42,8 @@ namespace Pinetime {
return zHistory[0];
}

uint32_t NbSteps(Days day = Today) const {
return nbSteps[day];
uint32_t NbSteps(Days day = Days::Today) const {
return nbSteps[static_cast<std::underlying_type_t<Days>>(day)];
}

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

uint32_t& NbStepsRef(Days day = Days::Today) {
return nbSteps[static_cast<std::underlying_type_t<Days>>(day)];
}

TickType_t lastTime = 0;
TickType_t time = 0;

Expand Down

0 comments on commit ee20df4

Please sign in to comment.