Skip to content

Commit

Permalink
Make lastY variable more generic and simplify lower to sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
FintasticMan committed Dec 13, 2021
1 parent fab8269 commit 7d020c7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
13 changes: 3 additions & 10 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
service->OnNewMotionValues(x, y, z);
}

lastY = this->y;
this->x = x;
this->y = y;
this->z = z;
Expand Down Expand Up @@ -39,16 +40,8 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
}
return false;
}
bool MotionController::ShouldSleep() {
bool ret = false;

if (y >= lastYForSleep + 192) {
ret = true;
}

lastYForSleep = (y > 320) ? y : 320;

return ret;
bool MotionController::ShouldLowerSleep() const {
return y >= 512 && y >= lastY + 192;
}

void MotionController::IsSensorOk(bool isOk) {
Expand Down
13 changes: 8 additions & 5 deletions src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ namespace Pinetime {
int16_t Z() const {
return z;
}
int16_t LastY() const {
return lastY;
}
uint32_t NbSteps() const {
return nbSteps;
}
bool ShouldWakeUp(bool isSleeping);
bool ShouldSleep();
bool ShouldLowerSleep() const;

void IsSensorOk(bool isOk);
bool IsSensorOk() const {
Expand All @@ -45,11 +48,11 @@ namespace Pinetime {

private:
uint32_t nbSteps;
int16_t x;
int16_t y;
int16_t z;
int16_t x = 0;
int16_t y = 0;
int16_t z = 0;
int16_t lastY = 0;
int16_t lastYForWakeUp = 0;
int16_t lastYForSleep = 0;
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
Pinetime::Controllers::MotionService* service = nullptr;
Expand Down
8 changes: 8 additions & 0 deletions src/displayapp/screens/Motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ Motion::Motion(Pinetime::Applications::DisplayApp* app, Controllers::MotionContr
lv_obj_align(labelStep, chart, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_label_set_text(labelStep, "Steps ---");

labelLastY = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(labelLastY, "LastY 0");
lv_label_set_align(labelLastY, LV_LABEL_ALIGN_RIGHT);
lv_obj_align(labelLastY, chart, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);

taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
}

Expand All @@ -58,4 +63,7 @@ void Motion::Refresh() {
motionController.Y() / 0x10,
motionController.Z() / 0x10);
lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10);

lv_label_set_text_fmt(labelLastY, "LastY %d", motionController.LastY() / 0x10);
lv_obj_align(labelLastY, chart, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
}
1 change: 1 addition & 0 deletions src/displayapp/screens/Motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Pinetime {
lv_obj_t* label;

lv_obj_t* labelStep;
lv_obj_t* labelLastY;
lv_task_t* taskRefresh;
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,9 @@ void SystemTask::UpdateMotion() {
if (motionController.ShouldWakeUp(isSleeping)) {
GoToRunning();
}
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist)) {
if (motionController.ShouldSleep() && !isSleeping)
PushMessage(Messages::GoToSleep);
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist) && !isSleeping &&
motionController.ShouldLowerSleep()) {
PushMessage(Messages::GoToSleep);
}
}

Expand Down

0 comments on commit 7d020c7

Please sign in to comment.