aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/motion
diff options
context:
space:
mode:
authorHunman <sanyi.exe@gmail.com>2025-11-08 21:58:23 +0100
committerGitHub <noreply@github.com>2025-11-08 20:58:23 +0000
commit716deff7d0456cdd9eb1d152d3b29f1f39c7a231 (patch)
tree8cb2e940071bf3a0db4219b326038ad85b30be68 /src/components/motion
parent9093d18efc1df0be5366444fd72129dae19b2f20 (diff)
Step counter history
Store 2 days steps history and display yesterday's steps on the Steps screen
Diffstat (limited to 'src/components/motion')
-rw-r--r--src/components/motion/MotionController.cpp15
-rw-r--r--src/components/motion/MotionController.h19
2 files changed, 28 insertions, 6 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index 6cfff61f..ce959f0e 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -35,8 +35,17 @@ namespace {
}
}
+void MotionController::AdvanceDay() {
+ --nbSteps; // Higher index = further in the past
+ SetSteps(Days::Today, 0);
+ if (service != nullptr) {
+ service->OnNewStepCountValue(NbSteps(Days::Today));
+ }
+}
+
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
- if (this->nbSteps != nbSteps && service != nullptr) {
+ uint32_t oldSteps = NbSteps(Days::Today);
+ if (oldSteps != nbSteps && service != nullptr) {
service->OnNewStepCountValue(nbSteps);
}
@@ -64,11 +73,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
stats = GetAccelStats();
- int32_t deltaSteps = nbSteps - this->nbSteps;
+ int32_t deltaSteps = nbSteps - oldSteps;
if (deltaSteps > 0) {
currentTripSteps += deltaSteps;
}
- this->nbSteps = nbSteps;
+ SetSteps(Days::Today, nbSteps);
}
MotionController::AccelStats MotionController::GetAccelStats() const {
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index ad95f31f..ed6cbbd1 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -18,6 +18,15 @@ namespace Pinetime {
BMA425,
};
+ enum class Days : uint8_t {
+ Today = 0,
+ Yesterday,
+ };
+
+ static constexpr size_t stepHistorySize = 2; // Store this many day's step counter
+
+ void AdvanceDay();
+
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
int16_t X() const {
@@ -32,8 +41,8 @@ namespace Pinetime {
return zHistory[0];
}
- uint32_t NbSteps() const {
- return nbSteps;
+ uint32_t NbSteps(Days day = Days::Today) const {
+ return nbSteps[static_cast<std::underlying_type_t<Days>>(day)];
}
void ResetTrip() {
@@ -66,9 +75,13 @@ namespace Pinetime {
}
private:
- uint32_t nbSteps = 0;
+ Utility::CircularBuffer<uint32_t, stepHistorySize> nbSteps = {0};
uint32_t currentTripSteps = 0;
+ void SetSteps(Days day, uint32_t steps) {
+ nbSteps[static_cast<std::underlying_type_t<Days>>(day)] = steps;
+ }
+
TickType_t lastTime = 0;
TickType_t time = 0;