From 0f9f606b78ffbb93b1365156d8492bbf4ee4995d Mon Sep 17 00:00:00 2001 From: FintasticMan Date: Sun, 27 Aug 2023 18:15:21 +0200 Subject: [PATCH] lowersleep: Implement Lower to Sleep functionality (#827) --- src/components/motion/MotionController.cpp | 14 ++++++++++++++ src/components/motion/MotionController.h | 1 + src/components/settings/Settings.h | 14 +++++--------- src/displayapp/screens/settings/SettingWakeUp.cpp | 6 +++--- src/displayapp/screens/settings/SettingWakeUp.h | 3 ++- src/systemtask/SystemTask.cpp | 4 ++++ 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index feb9ead0..d28378d5 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -115,6 +115,20 @@ bool MotionController::ShouldShakeWake(uint16_t thresh) { return accumulatedSpeed > thresh; } +bool MotionController::ShouldLowerSleep() const { + if (stats.yMean < 724 || DegreesRolled(stats.yMean, stats.zMean, stats.prevYMean, stats.prevZMean) < 30) { + return false; + } + + for (uint8_t i = AccelStats::numHistory + 1; i < yHistory.Size(); i++) { + if (yHistory[i] < 265) { + return false; + } + } + + return true; +} + void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) { switch (types) { case Drivers::Bma421::DeviceTypes::BMA421: diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index 1ad032b8..0aa7823e 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -46,6 +46,7 @@ namespace Pinetime { bool ShouldShakeWake(uint16_t thresh); bool ShouldRaiseWake() const; + bool ShouldLowerSleep() const; int32_t CurrentShakeSpeed() const { return accumulatedSpeed; diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index efa44fde..81cf4923 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -12,12 +12,7 @@ namespace Pinetime { enum class ClockType : uint8_t { H24, H12 }; enum class Notification : uint8_t { On, Off, Sleep }; enum class ChimesOption : uint8_t { None, Hours, HalfHours }; - enum class WakeUpMode : uint8_t { - SingleTap = 0, - DoubleTap = 1, - RaiseWrist = 2, - Shake = 3, - }; + enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 }; enum class Colors : uint8_t { White, Silver, @@ -238,7 +233,7 @@ namespace Pinetime { } }; - std::bitset<4> getWakeUpModes() const { + std::bitset<5> getWakeUpModes() const { return settings.wakeUpMode; } @@ -279,7 +274,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x0005; + static constexpr uint32_t settingsVersion = 0x0006; struct SettingsData { uint32_t version = settingsVersion; @@ -296,8 +291,9 @@ namespace Pinetime { WatchFaceInfineat watchFaceInfineat; - 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/settings/SettingWakeUp.cpp b/src/displayapp/screens/settings/SettingWakeUp.cpp index 8df34c20..4649dc82 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.cpp +++ b/src/displayapp/screens/settings/SettingWakeUp.cpp @@ -8,7 +8,7 @@ using namespace Pinetime::Applications::Screens; -constexpr std::array SettingWakeUp::options; +constexpr std::array SettingWakeUp::options; namespace { void event_handler(lv_obj_t* obj, lv_event_t event) { @@ -27,9 +27,9 @@ SettingWakeUp::SettingWakeUp(Pinetime::Controllers::Settings& settingsController 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); diff --git a/src/displayapp/screens/settings/SettingWakeUp.h b/src/displayapp/screens/settings/SettingWakeUp.h index 28219ca1..61edabce 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.h +++ b/src/displayapp/screens/settings/SettingWakeUp.h @@ -25,11 +25,12 @@ namespace Pinetime { }; Controllers::Settings& settingsController; - static constexpr std::array options = {{ + static constexpr std::array options = {{ {Controllers::Settings::WakeUpMode::SingleTap, "Single Tap"}, {Controllers::Settings::WakeUpMode::DoubleTap, "Double Tap"}, {Controllers::Settings::WakeUpMode::RaiseWrist, "Raise Wrist"}, {Controllers::Settings::WakeUpMode::Shake, "Shake Wake"}, + {Controllers::Settings::WakeUpMode::LowerWrist, "Lower Wrist"}, }}; lv_obj_t* cbOption[options.size()]; diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 4719bb50..e59a0ff7 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -436,6 +436,10 @@ void SystemTask::UpdateMotion() { GoToRunning(); } } + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist) && state == SystemTaskState::Running && + motionController.ShouldLowerSleep()) { + PushMessage(Messages::GoToSleep); + } } void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {