Skip to content

Commit f7d1b3f

Browse files
stephanie-engJF002
authored andcommitted
Moved trip meter update to MotionController and changed trip meter logic
1 parent fb87fdb commit f7d1b3f

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/components/motion/MotionController.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
1414
this->x = x;
1515
this->y = y;
1616
this->z = z;
17+
deltaSteps = nbSteps - this->nbSteps;
1718
this->nbSteps = nbSteps;
19+
if(deltaSteps > 0){
20+
currentTripSteps += deltaSteps;
21+
}
1822
}
1923

2024
bool MotionController::ShouldWakeUp(bool isSleeping) {

src/components/motion/MotionController.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ namespace Pinetime {
2828
uint32_t NbSteps() const {
2929
return nbSteps;
3030
}
31-
void SetTripSteps(uint32_t steps) {
32-
stepsAtLastTrip = steps;
31+
32+
void ResetTrip() {
33+
currentTripSteps = 0;
3334
}
3435
uint32_t GetTripSteps() const {
35-
return stepsAtLastTrip;
36+
return currentTripSteps;
3637
}
3738
bool ShouldWakeUp(bool isSleeping);
3839

@@ -50,7 +51,8 @@ namespace Pinetime {
5051

5152
private:
5253
uint32_t nbSteps;
53-
uint32_t stepsAtLastTrip = 0;
54+
int32_t deltaSteps = 0;
55+
uint32_t currentTripSteps = 0;
5456
int16_t x;
5557
int16_t y;
5658
int16_t z;

src/displayapp/screens/Steps.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ Steps::Steps(Pinetime::Applications::DisplayApp* app,
6565
lv_obj_set_style_local_text_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888));
6666
lv_label_set_text(txtTrip, "Reset");
6767

68-
if(stepsCount >= motionController.GetTripSteps()){
69-
currentTripSteps = stepsCount - motionController.GetTripSteps();
70-
} else {
71-
currentTripSteps = stepsCount + motionController.GetTripSteps();
72-
}
68+
currentTripSteps = motionController.GetTripSteps();
7369

7470
tripText = lv_label_create(lv_scr_act(), nullptr);
7571
lv_obj_set_style_local_text_color(tripText, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_YELLOW);
@@ -86,11 +82,7 @@ Steps::~Steps() {
8682

8783
void Steps::Refresh() {
8884
stepsCount = motionController.NbSteps();
89-
if(stepsCount >= motionController.GetTripSteps()){
90-
currentTripSteps = stepsCount - motionController.GetTripSteps();
91-
} else {
92-
currentTripSteps = stepsCount + motionController.GetTripSteps();
93-
}
85+
currentTripSteps = motionController.GetTripSteps();
9486

9587
lv_label_set_text_fmt(lSteps, "%li", stepsCount);
9688
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
@@ -106,7 +98,7 @@ void Steps::lapBtnEventHandler(lv_event_t event) {
10698
return;
10799
}
108100
stepsCount = motionController.NbSteps();
109-
motionController.SetTripSteps(stepsCount);
101+
motionController.ResetTrip();
110102
Refresh();
111103
}
112104

0 commit comments

Comments
 (0)