summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephanie <eng.steph@gmail.com>2021-10-21 23:37:35 -0400
committerJF <JF002@users.noreply.github.com>2021-12-30 21:51:43 +0100
commitf7d1b3f36847bcbd0699feeb8515bb6517690066 (patch)
tree690a297b78c10a421db90b7f950f8361a854661e /src
parentfb87fdb2d9720ce1bca2c4920b859658a6480167 (diff)
Moved trip meter update to MotionController and changed trip meter logic
Diffstat (limited to 'src')
-rw-r--r--src/components/motion/MotionController.cpp4
-rw-r--r--src/components/motion/MotionController.h10
-rw-r--r--src/displayapp/screens/Steps.cpp14
3 files changed, 13 insertions, 15 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index cae49105..59114f4c 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -14,7 +14,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
this->x = x;
this->y = y;
this->z = z;
+ deltaSteps = nbSteps - this->nbSteps;
this->nbSteps = nbSteps;
+ if(deltaSteps > 0){
+ currentTripSteps += deltaSteps;
+ }
}
bool MotionController::ShouldWakeUp(bool isSleeping) {
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index aea82f76..17bdc52e 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -28,11 +28,12 @@ namespace Pinetime {
uint32_t NbSteps() const {
return nbSteps;
}
- void SetTripSteps(uint32_t steps) {
- stepsAtLastTrip = steps;
+
+ void ResetTrip() {
+ currentTripSteps = 0;
}
uint32_t GetTripSteps() const {
- return stepsAtLastTrip;
+ return currentTripSteps;
}
bool ShouldWakeUp(bool isSleeping);
@@ -50,7 +51,8 @@ namespace Pinetime {
private:
uint32_t nbSteps;
- uint32_t stepsAtLastTrip = 0;
+ int32_t deltaSteps = 0;
+ uint32_t currentTripSteps = 0;
int16_t x;
int16_t y;
int16_t z;
diff --git a/src/displayapp/screens/Steps.cpp b/src/displayapp/screens/Steps.cpp
index 5d8c3861..cb1297b6 100644
--- a/src/displayapp/screens/Steps.cpp
+++ b/src/displayapp/screens/Steps.cpp
@@ -65,11 +65,7 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app,
lv_obj_set_style_local_text_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888));
lv_label_set_text(txtTrip, "Reset");
- if(stepsCount >= motionController.GetTripSteps()){
- currentTripSteps = stepsCount - motionController.GetTripSteps();
- } else {
- currentTripSteps = stepsCount + motionController.GetTripSteps();
- }
+ currentTripSteps = motionController.GetTripSteps();
tripText = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(tripText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
@@ -86,11 +82,7 @@ Steps::~Steps() {
void Steps::Refresh() {
stepsCount = motionController.NbSteps();
- if(stepsCount >= motionController.GetTripSteps()){
- currentTripSteps = stepsCount - motionController.GetTripSteps();
- } else {
- currentTripSteps = stepsCount + motionController.GetTripSteps();
- }
+ currentTripSteps = motionController.GetTripSteps();
lv_label_set_text_fmt(lSteps, "%li", stepsCount);
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
@@ -106,7 +98,7 @@ void Steps::lapBtnEventHandler(lv_event_t event) {
return;
}
stepsCount = motionController.NbSteps();
- motionController.SetTripSteps(stepsCount);
+ motionController.ResetTrip();
Refresh();
}