Converted MotionController::nbSteps to CircularBuffer internally

This commit is contained in:
Sándor Rátkai 2024-09-08 22:13:08 +02:00 committed by Hunman
parent a083358b98
commit 9687154f2f
2 changed files with 6 additions and 5 deletions

View file

@ -37,7 +37,7 @@ namespace {
} }
void MotionController::Update(int16_t x, int16_t y, int16_t z, MotionController::step_t nbSteps) { void MotionController::Update(int16_t x, int16_t y, int16_t z, MotionController::step_t nbSteps) {
if (this->nbSteps != nbSteps && service != nullptr) { if (this->nbSteps[0] != nbSteps && service != nullptr) {
service->OnNewStepCountValue(nbSteps); service->OnNewStepCountValue(nbSteps);
} }
@ -57,11 +57,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, MotionController:
stats = GetAccelStats(); stats = GetAccelStats();
int32_t deltaSteps = nbSteps - this->nbSteps; int32_t deltaSteps = nbSteps - this->nbSteps[0];
if (deltaSteps > 0) { if (deltaSteps > 0) {
currentTripSteps += deltaSteps; currentTripSteps += deltaSteps;
} }
this->nbSteps = nbSteps; this->nbSteps[0] = nbSteps;
} }
MotionController::AccelStats MotionController::GetAccelStats() const { MotionController::AccelStats MotionController::GetAccelStats() const {

View file

@ -20,6 +20,7 @@ namespace Pinetime {
}; };
using step_t = uint32_t; using step_t = uint32_t;
static constexpr size_t stepHistorySize = 2; // Store this many day's step counter
void Update(int16_t x, int16_t y, int16_t z, step_t nbSteps); void Update(int16_t x, int16_t y, int16_t z, step_t nbSteps);
@ -36,7 +37,7 @@ namespace Pinetime {
} }
step_t NbSteps() const { step_t NbSteps() const {
return nbSteps; return nbSteps[0];
} }
void ResetTrip() { void ResetTrip() {
@ -70,7 +71,7 @@ namespace Pinetime {
} }
private: private:
step_t nbSteps = 0; Utility::CircularBuffer<step_t, stepHistorySize> nbSteps = {0};
step_t currentTripSteps = 0; step_t currentTripSteps = 0;
TickType_t lastTime = 0; TickType_t lastTime = 0;