Make lastY variable more generic and simplify lower to sleep

This commit is contained in:
Finlay Davidson 2021-12-13 20:21:36 +01:00
parent a90d44f664
commit 42149218b1
5 changed files with 23 additions and 18 deletions

View File

@ -11,6 +11,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
service->OnNewMotionValues(x, y, z); service->OnNewMotionValues(x, y, z);
} }
lastY = this->y;
this->x = x; this->x = x;
this->y = y; this->y = y;
this->z = z; this->z = z;
@ -66,16 +67,8 @@ int32_t MotionController::currentShakeSpeed() {
return accumulatedspeed; return accumulatedspeed;
} }
bool MotionController::ShouldSleep() { bool MotionController::ShouldLowerSleep() const {
bool ret = false; return z <= 0 && y >= 512 && y >= lastY + 192;
if (y >= lastYForSleep + 192) {
ret = true;
}
lastYForSleep = (y > 320) ? y : 320;
return ret;
} }
void MotionController::IsSensorOk(bool isOk) { void MotionController::IsSensorOk(bool isOk) {

View File

@ -25,6 +25,9 @@ namespace Pinetime {
int16_t Z() const { int16_t Z() const {
return z; return z;
} }
int16_t LastY() const {
return lastY;
}
uint32_t NbSteps() const { uint32_t NbSteps() const {
return nbSteps; return nbSteps;
} }
@ -39,7 +42,7 @@ namespace Pinetime {
bool Should_ShakeWake(uint16_t thresh); bool Should_ShakeWake(uint16_t thresh);
bool Should_RaiseWake(bool isSleeping); bool Should_RaiseWake(bool isSleeping);
int32_t currentShakeSpeed(); int32_t currentShakeSpeed();
bool ShouldSleep(); bool ShouldLowerSleep() const;
void IsSensorOk(bool isOk); void IsSensorOk(bool isOk);
bool IsSensorOk() const { bool IsSensorOk() const {
return isSensorOk; return isSensorOk;
@ -55,11 +58,11 @@ namespace Pinetime {
private: private:
uint32_t nbSteps; uint32_t nbSteps;
uint32_t currentTripSteps = 0; uint32_t currentTripSteps = 0;
int16_t x; int16_t x = 0;
int16_t y; int16_t y = 0;
int16_t z; int16_t z = 0;
int16_t lastY = 0;
int16_t lastYForWakeUp = 0; int16_t lastYForWakeUp = 0;
int16_t lastYForSleep = 0;
bool isSensorOk = false; bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown; DeviceTypes deviceType = DeviceTypes::Unknown;
Pinetime::Controllers::MotionService* service = nullptr; Pinetime::Controllers::MotionService* service = nullptr;

View File

@ -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_obj_align(labelStep, chart, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_label_set_text_static(labelStep, "Steps ---"); lv_label_set_text_static(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); taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
} }
@ -58,4 +63,7 @@ void Motion::Refresh() {
motionController.Y() / 0x10, motionController.Y() / 0x10,
motionController.Z() / 0x10); motionController.Z() / 0x10);
lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); 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);
} }

View File

@ -27,6 +27,7 @@ namespace Pinetime {
lv_obj_t* label; lv_obj_t* label;
lv_obj_t* labelStep; lv_obj_t* labelStep;
lv_obj_t* labelLastY;
lv_task_t* taskRefresh; lv_task_t* taskRefresh;
}; };
} }

View File

@ -503,9 +503,9 @@ void SystemTask::UpdateMotion() {
motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) { motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) {
GoToRunning(); GoToRunning();
} }
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist)) { if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist) && !isSleeping &&
if (motionController.ShouldSleep() && !isSleeping) motionController.ShouldLowerSleep()) {
PushMessage(Messages::GoToSleep); PushMessage(Messages::GoToSleep);
} }
} }