diff options
| -rw-r--r-- | src/components/motion/MotionController.cpp | 28 | ||||
| -rw-r--r-- | src/components/motion/MotionController.h | 15 | ||||
| -rw-r--r-- | src/components/settings/Settings.h | 6 | ||||
| -rw-r--r-- | src/displayapp/screens/Motion.cpp | 8 | ||||
| -rw-r--r-- | src/displayapp/screens/Motion.h | 1 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/SettingWakeUp.cpp | 12 | ||||
| -rw-r--r-- | src/systemtask/SystemTask.cpp | 8 |
7 files changed, 45 insertions, 33 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index 7dd3212..c57d8aa 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -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; @@ -21,27 +22,8 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) } } -bool MotionController::Should_RaiseWake(bool isSleeping) { - if ((x + 335) <= 670 && z < 0) { - if (not isSleeping) { - if (y <= 0) { - return false; - } else { - lastYForWakeUp = 0; - return false; - } - } - - if (y >= 0) { - lastYForWakeUp = 0; - return false; - } - if (y + 230 < lastYForWakeUp) { - lastYForWakeUp = y; - return true; - } - } - return false; +bool MotionController::ShouldRaiseWake() const { + return x >= -384 && x <= 384 && z <= 0 && y <= -160 && y <= lastY - 160; } bool MotionController::Should_ShakeWake(uint16_t thresh) { @@ -66,6 +48,10 @@ int32_t MotionController::currentShakeSpeed() { return accumulatedspeed; } +bool MotionController::ShouldLowerSleep() const { + return y >= 512 && y >= lastY + 192; +} + void MotionController::IsSensorOk(bool isOk) { isSensorOk = isOk; } diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index f80b11b..297db59 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -25,6 +25,9 @@ namespace Pinetime { int16_t Z() const { return z; } + int16_t LastY() const { + return lastY; + } uint32_t NbSteps() const { return nbSteps; } @@ -36,9 +39,10 @@ namespace Pinetime { return currentTripSteps; } + bool ShouldRaiseWake() const; bool Should_ShakeWake(uint16_t thresh); - bool Should_RaiseWake(bool isSleeping); int32_t currentShakeSpeed(); + bool ShouldLowerSleep() const; void IsSensorOk(bool isOk); bool IsSensorOk() const { return isSensorOk; @@ -54,9 +58,10 @@ namespace Pinetime { private: uint32_t nbSteps; uint32_t currentTripSteps = 0; - 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; bool isSensorOk = false; DeviceTypes deviceType = DeviceTypes::Unknown; @@ -69,4 +74,4 @@ namespace Pinetime { uint32_t lastShakeTime = 0; }; } -}
\ No newline at end of file +} diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 44a1a85..34e1af4 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -16,6 +16,7 @@ namespace Pinetime { DoubleTap = 1, RaiseWrist = 2, Shake = 3, + LowerWrist = 4 }; enum class Colors : uint8_t { White, @@ -172,7 +173,7 @@ namespace Pinetime { } }; - std::bitset<4> getWakeUpModes() const { + std::bitset<5> getWakeUpModes() const { return settings.wakeUpMode; } @@ -227,8 +228,9 @@ namespace Pinetime { PineTimeStyle PTS; - std::bitset<4> wakeUpMode {0}; + std::bitset<5> wakeUpMode {0}; uint16_t shakeWakeThreshold = 150; + Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; }; diff --git a/src/displayapp/screens/Motion.cpp b/src/displayapp/screens/Motion.cpp index 23eb276..77b6518 100644 --- a/src/displayapp/screens/Motion.cpp +++ b/src/displayapp/screens/Motion.cpp @@ -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); } @@ -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); } diff --git a/src/displayapp/screens/Motion.h b/src/displayapp/screens/Motion.h index 4d2bd4f..315660c 100644 --- a/src/displayapp/screens/Motion.h +++ b/src/displayapp/screens/Motion.h @@ -27,6 +27,7 @@ namespace Pinetime { lv_obj_t* label; lv_obj_t* labelStep; + lv_obj_t* labelLastY; lv_task_t* taskRefresh; }; } diff --git a/src/displayapp/screens/settings/SettingWakeUp.cpp b/src/displayapp/screens/settings/SettingWakeUp.cpp index e1b6e36..4fc0994 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.cpp +++ b/src/displayapp/screens/settings/SettingWakeUp.cpp @@ -24,9 +24,9 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime:: lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); - lv_obj_set_pos(container1, 10, 60); + lv_obj_set_pos(container1, 10, 35); lv_obj_set_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); + lv_obj_set_height(container1, LV_VER_RES - 20); lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); @@ -73,6 +73,14 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime:: lv_checkbox_set_checked(cbOption[optionsTotal], true); } optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Lower Wrist"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist)) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + optionsTotal++; } SettingWakeUp::~SettingWakeUp() { diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 77cf411..75136a0 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -492,15 +492,17 @@ void SystemTask::UpdateMotion() { motionController.IsSensorOk(motionSensor.IsOk()); motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps); - - if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) && - motionController.Should_RaiseWake(isSleeping)) { + if (isSleeping && motionController.ShouldRaiseWake()) { GoToRunning(); } if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) { GoToRunning(); } + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist) && !isSleeping && + motionController.ShouldLowerSleep()) { + PushMessage(Messages::GoToSleep); + } } void SystemTask::HandleButtonAction(Controllers::ButtonActions action) { |
