Moved trip meter update to MotionController and changed trip meter logic
This commit is contained in:
parent
fb87fdb2d9
commit
f7d1b3f368
|
@ -14,7 +14,11 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
|
||||||
this->x = x;
|
this->x = x;
|
||||||
this->y = y;
|
this->y = y;
|
||||||
this->z = z;
|
this->z = z;
|
||||||
|
deltaSteps = nbSteps - this->nbSteps;
|
||||||
this->nbSteps = nbSteps;
|
this->nbSteps = nbSteps;
|
||||||
|
if(deltaSteps > 0){
|
||||||
|
currentTripSteps += deltaSteps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MotionController::ShouldWakeUp(bool isSleeping) {
|
bool MotionController::ShouldWakeUp(bool isSleeping) {
|
||||||
|
|
|
@ -28,11 +28,12 @@ namespace Pinetime {
|
||||||
uint32_t NbSteps() const {
|
uint32_t NbSteps() const {
|
||||||
return nbSteps;
|
return nbSteps;
|
||||||
}
|
}
|
||||||
void SetTripSteps(uint32_t steps) {
|
|
||||||
stepsAtLastTrip = steps;
|
void ResetTrip() {
|
||||||
|
currentTripSteps = 0;
|
||||||
}
|
}
|
||||||
uint32_t GetTripSteps() const {
|
uint32_t GetTripSteps() const {
|
||||||
return stepsAtLastTrip;
|
return currentTripSteps;
|
||||||
}
|
}
|
||||||
bool ShouldWakeUp(bool isSleeping);
|
bool ShouldWakeUp(bool isSleeping);
|
||||||
|
|
||||||
|
@ -50,7 +51,8 @@ namespace Pinetime {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t nbSteps;
|
uint32_t nbSteps;
|
||||||
uint32_t stepsAtLastTrip = 0;
|
int32_t deltaSteps = 0;
|
||||||
|
uint32_t currentTripSteps = 0;
|
||||||
int16_t x;
|
int16_t x;
|
||||||
int16_t y;
|
int16_t y;
|
||||||
int16_t z;
|
int16_t z;
|
||||||
|
|
|
@ -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_obj_set_style_local_text_color(btnTrip, LV_BTN_PART_MAIN, LV_STATE_DISABLED, lv_color_hex(0x888888));
|
||||||
lv_label_set_text(txtTrip, "Reset");
|
lv_label_set_text(txtTrip, "Reset");
|
||||||
|
|
||||||
if(stepsCount >= motionController.GetTripSteps()){
|
currentTripSteps = motionController.GetTripSteps();
|
||||||
currentTripSteps = stepsCount - motionController.GetTripSteps();
|
|
||||||
} else {
|
|
||||||
currentTripSteps = stepsCount + motionController.GetTripSteps();
|
|
||||||
}
|
|
||||||
|
|
||||||
tripText = lv_label_create(lv_scr_act(), nullptr);
|
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);
|
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() {
|
void Steps::Refresh() {
|
||||||
stepsCount = motionController.NbSteps();
|
stepsCount = motionController.NbSteps();
|
||||||
if(stepsCount >= motionController.GetTripSteps()){
|
currentTripSteps = motionController.GetTripSteps();
|
||||||
currentTripSteps = stepsCount - motionController.GetTripSteps();
|
|
||||||
} else {
|
|
||||||
currentTripSteps = stepsCount + motionController.GetTripSteps();
|
|
||||||
}
|
|
||||||
|
|
||||||
lv_label_set_text_fmt(lSteps, "%li", stepsCount);
|
lv_label_set_text_fmt(lSteps, "%li", stepsCount);
|
||||||
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
|
lv_obj_align(lSteps, nullptr, LV_ALIGN_CENTER, 0, -40);
|
||||||
|
@ -106,7 +98,7 @@ void Steps::lapBtnEventHandler(lv_event_t event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stepsCount = motionController.NbSteps();
|
stepsCount = motionController.NbSteps();
|
||||||
motionController.SetTripSteps(stepsCount);
|
motionController.ResetTrip();
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue