Skip to content

Commit

Permalink
Moved trip meter update to MotionController and changed trip meter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanie-eng committed Oct 22, 2021
1 parent 3a20b48 commit 5098895
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,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) {
Expand Down
10 changes: 6 additions & 4 deletions src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,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);

Expand All @@ -48,7 +49,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;
Expand Down
14 changes: 3 additions & 11 deletions src/displayapp/screens/Steps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -106,7 +98,7 @@ void Steps::lapBtnEventHandler(lv_event_t event) {
return;
}
stepsCount = motionController.NbSteps();
motionController.SetTripSteps(stepsCount);
motionController.ResetTrip();
Refresh();
}

0 comments on commit 5098895

Please sign in to comment.