From 446d5f1406878d47398949d40bc6534af8eb6b67 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 27 Sep 2021 01:20:44 +0000 Subject: [PATCH 01/17] Added Shake to wake --- src/components/motion/MotionController.cpp | 18 +++++++++++++++++- src/components/motion/MotionController.h | 13 ++++++++++++- src/components/settings/Settings.h | 8 +++++--- .../screens/settings/SettingWakeUp.cpp | 8 ++++++++ .../screens/settings/SettingWakeUp.h | 2 +- src/systemtask/SystemTask.cpp | 13 +++++++++---- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index b0dbada47f..e82e1b6b90 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -1,4 +1,5 @@ #include "MotionController.h" +#include "os/os_cputime.h" using namespace Pinetime::Controllers; @@ -9,7 +10,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) this->nbSteps = nbSteps; } -bool MotionController::ShouldWakeUp(bool isSleeping) { +bool MotionController::Should_RaiseWake(bool isSleeping) { if ((x + 335) <= 670 && z < 0) { if (not isSleeping) { if (y <= 0) { @@ -31,6 +32,21 @@ bool MotionController::ShouldWakeUp(bool isSleeping) { } return false; } + +bool MotionController::Should_ShakeWake() { + bool wake = false; + auto diff = xTaskGetTickCount() - lastShakeTime; + lastShakeTime = xTaskGetTickCount(); + int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10; + if (speed > 150) { // TODO move threshold to a setting + wake = true; + } + lastXForShake = x; + lastYForShake = y; + lastZForShake = z; + return wake; +} + void MotionController::IsSensorOk(bool isOk) { isSensorOk = isOk; } diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index ff715093f4..c6e976d5d3 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -12,6 +12,10 @@ namespace Pinetime { BMA421, BMA425, }; + enum class WakeUpMode : uint8_t { + RaiseWrist = 0, + Shake, + }; void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps); @@ -27,7 +31,9 @@ namespace Pinetime { uint32_t NbSteps() const { return nbSteps; } - bool ShouldWakeUp(bool isSleeping); + + bool Should_ShakeWake(); + bool Should_RaiseWake(bool isSleeping); void IsSensorOk(bool isOk); bool IsSensorOk() const { @@ -48,6 +54,11 @@ namespace Pinetime { int16_t lastYForWakeUp = 0; bool isSensorOk = false; DeviceTypes deviceType = DeviceTypes::Unknown; + + int16_t lastXForShake = 0; + int16_t lastYForShake = 0; + int16_t lastZForShake = 0; + 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 871ff3b6cf..894c76dafb 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -16,6 +16,7 @@ namespace Pinetime { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, + Shake = 3, }; enum class Colors : uint8_t { White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange @@ -128,12 +129,13 @@ namespace Pinetime { settings.wakeUpMode.set(static_cast(WakeUpMode::SingleTap), false); break; case WakeUpMode::RaiseWrist: + case WakeUpMode::Shake: break; } } }; - std::bitset<3> getWakeUpModes() const { + std::bitset<4> getWakeUpModes() const { return settings.wakeUpMode; } @@ -163,7 +165,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x0002; + static constexpr uint32_t settingsVersion = 0x0003; struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; @@ -176,7 +178,7 @@ namespace Pinetime { PineTimeStyle PTS; - std::bitset<3> wakeUpMode {0}; + std::bitset<4> wakeUpMode {0}; 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 d999004b5d..c6ff0dc9cd 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.cpp +++ b/src/displayapp/screens/settings/SettingWakeUp.cpp @@ -65,6 +65,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], " Shake Wake"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + optionsTotal++; } SettingWakeUp::~SettingWakeUp() { diff --git a/src/displayapp/screens/settings/SettingWakeUp.h b/src/displayapp/screens/settings/SettingWakeUp.h index b9a31dc9e5..cd244ae51f 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.h +++ b/src/displayapp/screens/settings/SettingWakeUp.h @@ -20,7 +20,7 @@ namespace Pinetime { private: Controllers::Settings& settingsController; uint8_t optionsTotal; - lv_obj_t* cbOption[4]; + lv_obj_t* cbOption[5]; // When UpdateSelected is called, it uses lv_checkbox_set_checked, // which can cause extra events to be fired, // which might trigger UpdateSelected again, causing a loop. diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 5441c16245..b0503d9ff2 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -24,7 +24,6 @@ #include "drivers/PinMap.h" #include "main.h" - #include using namespace Pinetime::System; @@ -389,9 +388,10 @@ void SystemTask::UpdateMotion() { if (isGoingToSleep or isWakingUp) return; - if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) + if (isSleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) || + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) { return; - + } if (stepCounterMustBeReset) { motionSensor.ResetStepCounter(); stepCounterMustBeReset = false; @@ -401,7 +401,12 @@ void SystemTask::UpdateMotion() { motionController.IsSensorOk(motionSensor.IsOk()); motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps); - if (motionController.ShouldWakeUp(isSleeping)) { + // TODO add modes arg + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) && + motionController.Should_RaiseWake(isSleeping)) { + GoToRunning(); + } + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && motionController.Should_ShakeWake()) { GoToRunning(); } } From 0ba6b9d3944c4709204619f8e8dbb222e084d2ee Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 27 Sep 2021 01:27:08 +0000 Subject: [PATCH 02/17] Cleanup --- src/components/motion/MotionController.h | 4 ---- src/systemtask/SystemTask.cpp | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index c6e976d5d3..e2725a4924 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -12,10 +12,6 @@ namespace Pinetime { BMA421, BMA425, }; - enum class WakeUpMode : uint8_t { - RaiseWrist = 0, - Shake, - }; void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index b0503d9ff2..8f79c0aeb2 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -401,7 +401,7 @@ void SystemTask::UpdateMotion() { motionController.IsSensorOk(motionSensor.IsOk()); motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps); - // TODO add modes arg + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) && motionController.Should_RaiseWake(isSleeping)) { GoToRunning(); From 94193eda167204c84bfae277fdfc7776e37ac172 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 27 Sep 2021 02:52:02 +0000 Subject: [PATCH 03/17] Add start of settings app for senstivity. really just debugging. I want to make it more configurable then high med low. Position of setting needs a new location...dynamicly adding it currently at the end. Which honestly im fine with. --- src/CMakeLists.txt | 1 + src/components/motion/MotionController.cpp | 4 +- src/components/motion/MotionController.h | 2 +- src/components/settings/Settings.h | 13 ++- src/displayapp/Apps.h | 3 +- src/displayapp/DisplayApp.cpp | 5 ++ .../settings/SettingShakeThreshold.cpp | 89 +++++++++++++++++++ .../screens/settings/SettingShakeThreshold.h | 27 ++++++ src/displayapp/screens/settings/Settings.cpp | 4 +- src/systemtask/SystemTask.cpp | 3 +- 10 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 src/displayapp/screens/settings/SettingShakeThreshold.cpp create mode 100644 src/displayapp/screens/settings/SettingShakeThreshold.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37ee0848bd..581738097b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -433,6 +433,7 @@ list(APPEND SOURCE_FILES displayapp/screens/settings/SettingDisplay.cpp displayapp/screens/settings/SettingSteps.cpp displayapp/screens/settings/SettingPineTimeStyle.cpp + displayapp/screens/settings/SettingShakeThreshold.cpp ## Watch faces displayapp/icons/bg_clock.c diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index e82e1b6b90..bd8f971eee 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -33,12 +33,12 @@ bool MotionController::Should_RaiseWake(bool isSleeping) { return false; } -bool MotionController::Should_ShakeWake() { +bool MotionController::Should_ShakeWake(uint16_t thresh) { bool wake = false; auto diff = xTaskGetTickCount() - lastShakeTime; lastShakeTime = xTaskGetTickCount(); int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10; - if (speed > 150) { // TODO move threshold to a setting + if (speed > thresh) { wake = true; } lastXForShake = x; diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index e2725a4924..9e1042db99 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -28,7 +28,7 @@ namespace Pinetime { return nbSteps; } - bool Should_ShakeWake(); + bool Should_ShakeWake(uint16_t thresh); bool Should_RaiseWake(bool isSleeping); void IsSensorOk(bool isOk); diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 894c76dafb..534832ebb5 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -110,10 +110,19 @@ namespace Pinetime { } settings.screenTimeOut = timeout; }; + uint32_t GetScreenTimeOut() const { return settings.screenTimeOut; }; + void SetShakeThreshold(uint16_t thresh){ + settings.shakeWakeThreshold = thresh; + } + + int16_t GetShakeThreshold() const{ + return settings.shakeWakeThreshold; + } + void setWakeUpMode(WakeUpMode wakeUp, bool enabled) { if (enabled != isWakeUpModeOn(wakeUp)) { settingsChanged = true; @@ -165,7 +174,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x0003; + static constexpr uint32_t settingsVersion = 0x0004; struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; @@ -179,7 +188,7 @@ namespace Pinetime { PineTimeStyle PTS; std::bitset<4> wakeUpMode {0}; - + uint16_t shakeWakeThreshold = 300; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; }; diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index e3aca8cf00..8cdb565b3a 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -32,7 +32,8 @@ namespace Pinetime { SettingDisplay, SettingWakeUp, SettingSteps, - SettingPineTimeStyle + SettingPineTimeStyle, + SettingShakeThreshold }; } } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 9d47310197..2199ba9484 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -44,6 +44,7 @@ #include "displayapp/screens/settings/SettingDisplay.h" #include "displayapp/screens/settings/SettingSteps.h" #include "displayapp/screens/settings/SettingPineTimeStyle.h" +#include "displayapp/screens/settings/SettingShakeThreshold.h" #include "libs/lv_conf.h" @@ -382,6 +383,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, settingsController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; + case Apps::SettingShakeThreshold: + currentScreen = std::make_unique(this, settingsController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; case Apps::BatteryInfo: currentScreen = std::make_unique(this, batteryController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp new file mode 100644 index 0000000000..6665e4b6e7 --- /dev/null +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -0,0 +1,89 @@ +#include "SettingShakeThreshold.h" +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t* obj, lv_event_t event) { + SettingShakeThreshold* screen = static_cast(obj->user_data); + screen->UpdateSelected(obj, event); + } +} + +SettingShakeThreshold::SettingShakeThreshold(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) + : Screen(app), settingsController {settingsController} { + + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); + + // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + 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_width(container1, LV_HOR_RES - 20); + lv_obj_set_height(container1, LV_VER_RES - 50); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, "Shake Threshold"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); + + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text_static(icon, Symbols::home); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + optionsTotal = 0; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " High"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetShakeThreshold() == 150) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Medium"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetShakeThreshold() == 300) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Low"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetShakeThreshold() == 450) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; +} + +SettingShakeThreshold::~SettingShakeThreshold() { + lv_obj_clean(lv_scr_act()); + settingsController.SaveSettings(); +} + +void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_VALUE_CHANGED) { + for (uint8_t i = 0; i < optionsTotal; i++) { + if (object == cbOption[i]) { + lv_checkbox_set_checked(cbOption[i], true); + settingsController.SetShakeThreshold((i+1)*150); + } else { + lv_checkbox_set_checked(cbOption[i], false); + } + } + } +} diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h new file mode 100644 index 0000000000..387f0b6f40 --- /dev/null +++ b/src/displayapp/screens/settings/SettingShakeThreshold.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include "components/settings/Settings.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingShakeThreshold : public Screen { + public: + SettingShakeThreshold(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); + ~SettingShakeThreshold() override; + + void UpdateSelected(lv_obj_t* object, lv_event_t event); + + private: + Controllers::Settings& settingsController; + uint8_t optionsTotal; + lv_obj_t* cbOption[2]; + }; + } + } +} diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index e3319f030a..3b6bb8aac2 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -65,6 +65,8 @@ std::unique_ptr Settings::CreateScreen3() { {Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None}, }}; - + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) { + applications[1] = {Symbols::list, "Shake Threshold", Apps::SettingShakeThreshold}; + } return std::make_unique(2, 3, app, settingsController, applications); } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 8f79c0aeb2..071fe90000 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -406,7 +406,8 @@ void SystemTask::UpdateMotion() { motionController.Should_RaiseWake(isSleeping)) { GoToRunning(); } - if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && motionController.Should_ShakeWake()) { + if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && + motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) { GoToRunning(); } } From 61c1713cbb5415549a53177aecd2efdab6b818bb Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 27 Sep 2021 03:30:49 +0000 Subject: [PATCH 04/17] Add averaging to wake threshold. Makes it take more then just a "flick" to turn on --- src/components/motion/MotionController.cpp | 5 ++++- src/components/motion/MotionController.h | 1 + src/components/settings/Settings.h | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index bd8f971eee..8eb2ba7966 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -38,7 +38,10 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) { auto diff = xTaskGetTickCount() - lastShakeTime; lastShakeTime = xTaskGetTickCount(); int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10; - if (speed > thresh) { + //(.2 * speed) + ((1 - .2) * accumulatedspeed); + //implemented without floats as .25Alpha + accumulatedspeed = (speed/4) + ((accumulatedspeed/4)*3); + if (accumulatedspeed > thresh) { wake = true; } lastXForShake = x; diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index 9e1042db99..889388901a 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -54,6 +54,7 @@ namespace Pinetime { int16_t lastXForShake = 0; int16_t lastYForShake = 0; int16_t lastZForShake = 0; + int32_t accumulatedspeed = 0; uint32_t lastShakeTime = 0; }; } diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 534832ebb5..0c9e1633f3 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -174,7 +174,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x0004; + static constexpr uint32_t settingsVersion = 0x0003; struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; @@ -188,7 +188,7 @@ namespace Pinetime { PineTimeStyle PTS; std::bitset<4> wakeUpMode {0}; - uint16_t shakeWakeThreshold = 300; + uint16_t shakeWakeThreshold = 150; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; }; From 2e95671a0eaeacda21f4f71b7546df224ff74022 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 28 Sep 2021 03:50:08 +0000 Subject: [PATCH 05/17] Better Sensitivity UI, Calibration button added --- src/components/motion/MotionController.cpp | 13 +- src/components/motion/MotionController.h | 2 +- src/components/settings/Settings.h | 3 +- src/displayapp/DisplayApp.cpp | 2 +- .../settings/SettingShakeThreshold.cpp | 118 +++++++++--------- .../screens/settings/SettingShakeThreshold.h | 20 ++- src/systemtask/SystemTask.cpp | 4 +- 7 files changed, 91 insertions(+), 71 deletions(-) diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index 8eb2ba7966..1445cbc41d 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -1,6 +1,5 @@ #include "MotionController.h" #include "os/os_cputime.h" - using namespace Pinetime::Controllers; void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) { @@ -37,18 +36,22 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) { bool wake = false; auto diff = xTaskGetTickCount() - lastShakeTime; lastShakeTime = xTaskGetTickCount(); - int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10; + int32_t speed = std::abs(z + (y/2) + (x/4)- lastYForShake - lastZForShake) / diff * 100; //(.2 * speed) + ((1 - .2) * accumulatedspeed); //implemented without floats as .25Alpha - accumulatedspeed = (speed/4) + ((accumulatedspeed/4)*3); + accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4); + if (accumulatedspeed > thresh) { wake = true; } - lastXForShake = x; - lastYForShake = y; + lastXForShake = x/4; + lastYForShake = y/2; lastZForShake = z; return wake; } +int32_t MotionController::currentShakeSpeed(){ + return accumulatedspeed; +} void MotionController::IsSensorOk(bool isOk) { isSensorOk = isOk; diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index 889388901a..66b875a5db 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -30,7 +30,7 @@ namespace Pinetime { bool Should_ShakeWake(uint16_t thresh); bool Should_RaiseWake(bool isSleeping); - + int32_t currentShakeSpeed(); void IsSensorOk(bool isOk); bool IsSensorOk() const { return isSensorOk; diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 0c9e1633f3..016954ef61 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -137,8 +137,7 @@ namespace Pinetime { case WakeUpMode::DoubleTap: settings.wakeUpMode.set(static_cast(WakeUpMode::SingleTap), false); break; - case WakeUpMode::RaiseWrist: - case WakeUpMode::Shake: + default: break; } } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 2199ba9484..af5762b1eb 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -384,7 +384,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::SettingShakeThreshold: - currentScreen = std::make_unique(this, settingsController); + currentScreen = std::make_unique(this, settingsController,motionController,*systemTask); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::BatteryInfo: diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index 6665e4b6e7..19afa24fd5 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -4,6 +4,7 @@ #include "displayapp/screens/Screen.h" #include "displayapp/screens/Symbols.h" + using namespace Pinetime::Applications::Screens; namespace { @@ -13,77 +14,82 @@ namespace { } } -SettingShakeThreshold::SettingShakeThreshold(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) - : Screen(app), settingsController {settingsController} { - - lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); - - // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); - lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); - lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); - 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_width(container1, LV_HOR_RES - 20); - lv_obj_set_height(container1, LV_VER_RES - 50); - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); +SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, + Controllers::Settings& settingsController, + Controllers::MotionController& motionController, + System::SystemTask& systemTask) + : Screen(app), + settingsController {settingsController}, + motionController {motionController}, + systemTask {systemTask} { lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title, "Shake Threshold"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); - - lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); - lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); - lv_label_set_text_static(icon, Symbols::home); - lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); - lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); - - optionsTotal = 0; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " High"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetShakeThreshold() == 150) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Medium"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetShakeThreshold() == 300) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; - cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Low"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.GetShakeThreshold() == 450) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } + positionArc = lv_arc_create(lv_scr_act(), nullptr); + // Why do this? + positionArc->user_data = this; - optionsTotal++; -} + lv_obj_set_event_cb(positionArc, event_handler); + // lv_arc_set_start_angle(positionArc,270); + lv_arc_set_angles(positionArc, 180, 360); + lv_arc_set_bg_angles(positionArc, 180, 360); + + // lv_arc_set_rotation(positionArc, 135); + lv_arc_set_range(positionArc, 10, 4095); + lv_arc_set_value(positionArc, settingsController.GetShakeThreshold()); + lv_obj_set_size(positionArc, 240, 180); + lv_arc_set_adjustable(positionArc, false); + lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10); + + calButton = lv_btn_create(lv_scr_act(), nullptr); + calButton->user_data = this; + lv_obj_set_event_cb(calButton, event_handler); + lv_btn_set_fit(calButton, LV_FIT_TIGHT); + + // lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_height(calButton, 80); + lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + calLabel = lv_label_create(calButton, NULL); + lv_label_set_text(calLabel, "Calibrate"); + + } SettingShakeThreshold::~SettingShakeThreshold() { lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } +void SettingShakeThreshold::Refresh() { + + taskCount++; //100ms Update time so finish @100 + if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){ + lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200); + } + if(taskCount >= 100){ + lv_label_set_text(calLabel, "Calibrate"); + lv_task_del(refreshTask); + } + +} + void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { - if (event == LV_EVENT_VALUE_CHANGED) { - for (uint8_t i = 0; i < optionsTotal; i++) { - if (object == cbOption[i]) { - lv_checkbox_set_checked(cbOption[i], true); - settingsController.SetShakeThreshold((i+1)*150); - } else { - lv_checkbox_set_checked(cbOption[i], false); + + switch (event) { + case LV_EVENT_PRESSED: { + taskCount = 0; + refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); + lv_label_set_text(calLabel, "Shake!!!"); + break; + } + case LV_EVENT_VALUE_CHANGED: { + if (object == positionArc) { + settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); } + break; } } } diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h index 387f0b6f40..f6918f4d0f 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.h +++ b/src/displayapp/screens/settings/SettingShakeThreshold.h @@ -4,7 +4,7 @@ #include #include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" - +#include namespace Pinetime { namespace Applications { @@ -12,15 +12,27 @@ namespace Pinetime { class SettingShakeThreshold : public Screen { public: - SettingShakeThreshold(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); - ~SettingShakeThreshold() override; + SettingShakeThreshold(DisplayApp* app, + Pinetime::Controllers::Settings& settingsController, + Controllers::MotionController& motionController, + System::SystemTask& systemTask); + ~SettingShakeThreshold() override; + void Refresh() override; void UpdateSelected(lv_obj_t* object, lv_event_t event); private: Controllers::Settings& settingsController; - uint8_t optionsTotal; + Controllers::MotionController& motionController; + System::SystemTask& systemTask; + + + + + uint8_t taskCount; lv_obj_t* cbOption[2]; + lv_obj_t *positionArc, *calButton, *calLabel; + lv_task_t* refreshTask; }; } } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 071fe90000..eba908b00d 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -389,9 +389,9 @@ void SystemTask::UpdateMotion() { return; if (isSleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) || - settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) { + settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) return; - } + if (stepCounterMustBeReset) { motionSensor.ResetStepCounter(); stepCounterMustBeReset = false; From cb061bfebbb46c87300242c083870a397344a75b Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 28 Sep 2021 04:21:47 +0000 Subject: [PATCH 06/17] Actually save the threshold Prevent a few crashes due to an LV task being active when it shouldnt be. --- src/components/settings/Settings.h | 6 ++++- .../settings/SettingShakeThreshold.cpp | 23 ++++++++++++++----- src/displayapp/screens/settings/Settings.cpp | 2 +- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 016954ef61..79fa958f80 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -116,7 +116,11 @@ namespace Pinetime { }; void SetShakeThreshold(uint16_t thresh){ - settings.shakeWakeThreshold = thresh; + if(settings.shakeWakeThreshold != thresh){ + settings.shakeWakeThreshold = thresh; + settingsChanged = true; + } + } int16_t GetShakeThreshold() const{ diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index 19afa24fd5..dc0812a7c7 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -24,13 +24,14 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, systemTask {systemTask} { lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Shake Threshold"); + lv_label_set_text_static(title, "Wake Sensitivity"); lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); + taskCount = 0; positionArc = lv_arc_create(lv_scr_act(), nullptr); - // Why do this? + positionArc->user_data = this; lv_obj_set_event_cb(positionArc, event_handler); @@ -59,6 +60,8 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, } SettingShakeThreshold::~SettingShakeThreshold() { + settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); + lv_task_del(refreshTask); lv_obj_clean(lv_scr_act()); settingsController.SaveSettings(); } @@ -69,8 +72,9 @@ void SettingShakeThreshold::Refresh() { if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){ lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200); } - if(taskCount >= 100){ + if(taskCount >= 50){ lv_label_set_text(calLabel, "Calibrate"); + taskCount=0; lv_task_del(refreshTask); } @@ -80,11 +84,18 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { switch (event) { case LV_EVENT_PRESSED: { - taskCount = 0; - refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); - lv_label_set_text(calLabel, "Shake!!!"); + if(taskCount == 0){ + refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); + lv_label_set_text(calLabel, "Shake!!!"); + }else{ + + lv_task_del(refreshTask); + taskCount=0; + lv_label_set_text(calLabel, "Calibrate"); + } break; } + case LV_EVENT_VALUE_CHANGED: { if (object == positionArc) { settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index 3b6bb8aac2..0cf20a9bea 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -66,7 +66,7 @@ std::unique_ptr Settings::CreateScreen3() { {Symbols::none, "None", Apps::None}, }}; if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) { - applications[1] = {Symbols::list, "Shake Threshold", Apps::SettingShakeThreshold}; + applications[1] = {Symbols::list, "Wake Sense", Apps::SettingShakeThreshold}; } return std::make_unique(2, 3, app, settingsController, applications); } From e99361abc5e0e5d60302a92792b387bd4c4b92cb Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 28 Sep 2021 04:33:00 +0000 Subject: [PATCH 07/17] Make arc moveable, and clear previous setting on calibrate --- src/displayapp/screens/settings/SettingShakeThreshold.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index dc0812a7c7..cc67687ae4 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -40,10 +40,10 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, lv_arc_set_bg_angles(positionArc, 180, 360); // lv_arc_set_rotation(positionArc, 135); - lv_arc_set_range(positionArc, 10, 4095); + lv_arc_set_range(positionArc, 0, 4095); lv_arc_set_value(positionArc, settingsController.GetShakeThreshold()); lv_obj_set_size(positionArc, 240, 180); - lv_arc_set_adjustable(positionArc, false); + lv_arc_set_adjustable(positionArc, true); lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10); calButton = lv_btn_create(lv_scr_act(), nullptr); @@ -84,7 +84,9 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { switch (event) { case LV_EVENT_PRESSED: { + if (object == calButton) { if(taskCount == 0){ + lv_arc_set_value(positionArc,0); refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); lv_label_set_text(calLabel, "Shake!!!"); }else{ @@ -93,6 +95,7 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { taskCount=0; lv_label_set_text(calLabel, "Calibrate"); } + } break; } From 530439da7d7b86f0e643012c96959ee17f77826a Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Thu, 30 Sep 2021 00:04:51 +0000 Subject: [PATCH 08/17] Fix crash upon leaving app. Code formatting --- src/components/motion/MotionController.cpp | 29 +++++++----- .../settings/SettingShakeThreshold.cpp | 44 +++++++++---------- .../screens/settings/SettingShakeThreshold.h | 3 -- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index 1445cbc41d..ac5c67d6fe 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -36,20 +36,21 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) { bool wake = false; auto diff = xTaskGetTickCount() - lastShakeTime; lastShakeTime = xTaskGetTickCount(); - int32_t speed = std::abs(z + (y/2) + (x/4)- lastYForShake - lastZForShake) / diff * 100; + /* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */ + int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100; //(.2 * speed) + ((1 - .2) * accumulatedspeed); - //implemented without floats as .25Alpha - accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4); + // implemented without floats as .25Alpha + accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4); - if (accumulatedspeed > thresh) { + if (accumulatedspeed > thresh) { wake = true; } - lastXForShake = x/4; - lastYForShake = y/2; + lastXForShake = x / 4; + lastYForShake = y / 2; lastZForShake = z; return wake; } -int32_t MotionController::currentShakeSpeed(){ +int32_t MotionController::currentShakeSpeed() { return accumulatedspeed; } @@ -57,9 +58,15 @@ void MotionController::IsSensorOk(bool isOk) { isSensorOk = isOk; } void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) { - switch(types){ - case Drivers::Bma421::DeviceTypes::BMA421: this->deviceType = DeviceTypes::BMA421; break; - case Drivers::Bma421::DeviceTypes::BMA425: this->deviceType = DeviceTypes::BMA425; break; - default: this->deviceType = DeviceTypes::Unknown; break; + switch (types) { + case Drivers::Bma421::DeviceTypes::BMA421: + this->deviceType = DeviceTypes::BMA421; + break; + case Drivers::Bma421::DeviceTypes::BMA425: + this->deviceType = DeviceTypes::BMA425; + break; + default: + this->deviceType = DeviceTypes::Unknown; + break; } } diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index cc67687ae4..cc59bb6fa5 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -4,7 +4,6 @@ #include "displayapp/screens/Screen.h" #include "displayapp/screens/Symbols.h" - using namespace Pinetime::Applications::Screens; namespace { @@ -16,12 +15,9 @@ namespace { SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, Controllers::Settings& settingsController, - Controllers::MotionController& motionController, + Controllers::MotionController& motionController, System::SystemTask& systemTask) - : Screen(app), - settingsController {settingsController}, - motionController {motionController}, - systemTask {systemTask} { + : Screen(app), settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} { lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(title, "Wake Sensitivity"); @@ -31,7 +27,7 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, taskCount = 0; positionArc = lv_arc_create(lv_scr_act(), nullptr); - + positionArc->user_data = this; lv_obj_set_event_cb(positionArc, event_handler); @@ -56,28 +52,28 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); calLabel = lv_label_create(calButton, NULL); lv_label_set_text(calLabel, "Calibrate"); - - } +} SettingShakeThreshold::~SettingShakeThreshold() { settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); - lv_task_del(refreshTask); - lv_obj_clean(lv_scr_act()); + if (taskCount > 0) { + lv_task_del(refreshTask); + } settingsController.SaveSettings(); + lv_obj_clean(lv_scr_act()); } void SettingShakeThreshold::Refresh() { - - taskCount++; //100ms Update time so finish @100 - if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){ - lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200); + + taskCount++; // 100ms Update time so finish @100 + if ((motionController.currentShakeSpeed() - 200) > lv_arc_get_value(positionArc)) { + lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200); } - if(taskCount >= 50){ + if (taskCount >= 50) { lv_label_set_text(calLabel, "Calibrate"); - taskCount=0; + taskCount = 0; lv_task_del(refreshTask); } - } void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { @@ -85,14 +81,14 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { switch (event) { case LV_EVENT_PRESSED: { if (object == calButton) { - if(taskCount == 0){ - lv_arc_set_value(positionArc,0); - refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this); + if (taskCount == 0) { + lv_arc_set_value(positionArc, 0); + refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); lv_label_set_text(calLabel, "Shake!!!"); - }else{ - + } else { + lv_task_del(refreshTask); - taskCount=0; + taskCount = 0; lv_label_set_text(calLabel, "Calibrate"); } } diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h index f6918f4d0f..36c59569f1 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.h +++ b/src/displayapp/screens/settings/SettingShakeThreshold.h @@ -26,9 +26,6 @@ namespace Pinetime { Controllers::MotionController& motionController; System::SystemTask& systemTask; - - - uint8_t taskCount; lv_obj_t* cbOption[2]; lv_obj_t *positionArc, *calButton, *calLabel; From f346f9194bd8c9c048a0297d49991803ec80d358 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sun, 3 Oct 2021 21:06:31 +0000 Subject: [PATCH 09/17] Raise calibration timeout to 7.5 seconds Added button toggle state for cleaner user interaction --- .../settings/SettingShakeThreshold.cpp | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index cc59bb6fa5..89f6322e13 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -50,6 +50,7 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, // lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_obj_set_height(calButton, 80); lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); + lv_btn_set_checkable(calButton, true); calLabel = lv_label_create(calButton, NULL); lv_label_set_text(calLabel, "Calibrate"); } @@ -65,12 +66,13 @@ SettingShakeThreshold::~SettingShakeThreshold() { void SettingShakeThreshold::Refresh() { - taskCount++; // 100ms Update time so finish @100 - if ((motionController.currentShakeSpeed() - 200) > lv_arc_get_value(positionArc)) { + taskCount++; // 100ms Per update + if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) { lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200); } - if (taskCount >= 50) { - lv_label_set_text(calLabel, "Calibrate"); + if (taskCount >= 75) { + lv_btn_set_state(calButton,LV_STATE_DEFAULT); + lv_event_send(calButton,LV_EVENT_VALUE_CHANGED,NULL); taskCount = 0; lv_task_del(refreshTask); } @@ -79,27 +81,25 @@ void SettingShakeThreshold::Refresh() { void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { switch (event) { - case LV_EVENT_PRESSED: { + case LV_EVENT_VALUE_CHANGED: { + if (object == positionArc) { + settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); + break; + } if (object == calButton) { - if (taskCount == 0) { + if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED) { lv_arc_set_value(positionArc, 0); refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); lv_label_set_text(calLabel, "Shake!!!"); - } else { + + } else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) { lv_task_del(refreshTask); taskCount = 0; lv_label_set_text(calLabel, "Calibrate"); } + break; } - break; - } - - case LV_EVENT_VALUE_CHANGED: { - if (object == positionArc) { - settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); - } - break; } } } From 437aa3b0c95e5a80fdf1c50d84cf79578e92936c Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 4 Oct 2021 02:36:51 +0000 Subject: [PATCH 10/17] Added visual aide for shake strength Added delay to starting calibration --- .../settings/SettingShakeThreshold.cpp | 91 ++++++++++++------- .../screens/settings/SettingShakeThreshold.h | 6 +- 2 files changed, 60 insertions(+), 37 deletions(-) diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index 89f6322e13..aaabce02dc 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -24,57 +24,82 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); - taskCount = 0; - positionArc = lv_arc_create(lv_scr_act(), nullptr); - positionArc->user_data = this; lv_obj_set_event_cb(positionArc, event_handler); - // lv_arc_set_start_angle(positionArc,270); - lv_arc_set_angles(positionArc, 180, 360); lv_arc_set_bg_angles(positionArc, 180, 360); - - // lv_arc_set_rotation(positionArc, 135); lv_arc_set_range(positionArc, 0, 4095); - lv_arc_set_value(positionArc, settingsController.GetShakeThreshold()); - lv_obj_set_size(positionArc, 240, 180); lv_arc_set_adjustable(positionArc, true); - lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10); + lv_obj_set_width(positionArc, lv_obj_get_width(lv_scr_act()) - 10); + lv_obj_set_height(positionArc, 240); + lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + + animArc = lv_arc_create(positionArc, positionArc); + lv_arc_set_adjustable(animArc, false); + lv_obj_set_width(animArc, lv_obj_get_width(positionArc)); + lv_obj_set_height(animArc, lv_obj_get_height(positionArc)); + lv_obj_align_mid(animArc, positionArc, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); + lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_60); + lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_KNOB, LV_STATE_DEFAULT, LV_OPA_0); + lv_obj_set_style_local_line_color(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_obj_set_style_local_bg_color(animArc, LV_ARC_PART_BG, LV_STATE_CHECKED, LV_COLOR_TRANSP); + animArc->user_data = this; + lv_obj_set_click(animArc, false); calButton = lv_btn_create(lv_scr_act(), nullptr); calButton->user_data = this; lv_obj_set_event_cb(calButton, event_handler); - lv_btn_set_fit(calButton, LV_FIT_TIGHT); - - // lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); lv_obj_set_height(calButton, 80); + lv_obj_set_width(calButton, 200); lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_btn_set_checkable(calButton, true); calLabel = lv_label_create(calButton, NULL); lv_label_set_text(calLabel, "Calibrate"); + + lv_arc_set_value(positionArc, settingsController.GetShakeThreshold()); + + vDecay = xTaskGetTickCount(); + calibrating = false; + + refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } SettingShakeThreshold::~SettingShakeThreshold() { settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); - if (taskCount > 0) { - lv_task_del(refreshTask); - } + + lv_task_del(refreshTask); settingsController.SaveSettings(); lv_obj_clean(lv_scr_act()); } void SettingShakeThreshold::Refresh() { - taskCount++; // 100ms Per update - if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) { - lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200); + if (calibrating == 1) { + if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(2000)) { + vCalTime = xTaskGetTickCount(); + calibrating = 2; + lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_RELEASED, LV_COLOR_RED); + lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_PRESSED, LV_COLOR_RED); + lv_label_set_text(calLabel, "Shake!!"); + } + } + if (calibrating == 2) { + + if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) { + lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 300); + } + if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(7500)) { + lv_btn_set_state(calButton, LV_STATE_DEFAULT); + lv_event_send(calButton, LV_EVENT_VALUE_CHANGED, NULL); + } } - if (taskCount >= 75) { - lv_btn_set_state(calButton,LV_STATE_DEFAULT); - lv_event_send(calButton,LV_EVENT_VALUE_CHANGED,NULL); - taskCount = 0; - lv_task_del(refreshTask); + if (motionController.currentShakeSpeed() - 300 > lv_arc_get_value(animArc)) { + lv_arc_set_value(animArc, (uint16_t) motionController.currentShakeSpeed() - 300); + vDecay = xTaskGetTickCount(); + } else if ((xTaskGetTickCount() - vDecay) > pdMS_TO_TICKS(1500)) { + lv_arc_set_value(animArc, lv_arc_get_value(animArc) - 25); } } @@ -82,20 +107,18 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { switch (event) { case LV_EVENT_VALUE_CHANGED: { - if (object == positionArc) { - settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); - break; - } if (object == calButton) { - if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED) { - lv_arc_set_value(positionArc, 0); - refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); - lv_label_set_text(calLabel, "Shake!!!"); + if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED && calibrating == 0) { + lv_arc_set_value(positionArc, 0); + calibrating = 1; + vCalTime = xTaskGetTickCount(); + lv_label_set_text(calLabel, "Ready!"); + lv_obj_set_click(calButton,false); } else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) { - lv_task_del(refreshTask); - taskCount = 0; + calibrating = 0; + lv_obj_set_click(calButton,true); lv_label_set_text(calLabel, "Calibrate"); } break; diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h index 36c59569f1..ed5658923b 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.h +++ b/src/displayapp/screens/settings/SettingShakeThreshold.h @@ -25,10 +25,10 @@ namespace Pinetime { Controllers::Settings& settingsController; Controllers::MotionController& motionController; System::SystemTask& systemTask; - - uint8_t taskCount; + uint8_t calibrating; + uint32_t vDecay,vCalTime; lv_obj_t* cbOption[2]; - lv_obj_t *positionArc, *calButton, *calLabel; + lv_obj_t *positionArc, *animArc,*calButton, *calLabel; lv_task_t* refreshTask; }; } From 290cd692b288591c49f195ec9b145169ce955d6e Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Mon, 4 Oct 2021 17:11:27 +0000 Subject: [PATCH 11/17] Fixed button color changing --- .../screens/settings/SettingShakeThreshold.cpp | 17 +++++++++-------- .../screens/settings/SettingShakeThreshold.h | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index aaabce02dc..c42bb9ae1f 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -7,7 +7,7 @@ using namespace Pinetime::Applications::Screens; namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { + void event_handler(lv_obj_t* obj, lv_event_t event) { SettingShakeThreshold* screen = static_cast(obj->user_data); screen->UpdateSelected(obj, event); } @@ -41,10 +41,11 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, lv_obj_set_height(animArc, lv_obj_get_height(positionArc)); lv_obj_align_mid(animArc, positionArc, LV_ALIGN_CENTER, 0, 0); lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); - lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_60); + lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_70); lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_KNOB, LV_STATE_DEFAULT, LV_OPA_0); lv_obj_set_style_local_line_color(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); lv_obj_set_style_local_bg_color(animArc, LV_ARC_PART_BG, LV_STATE_CHECKED, LV_COLOR_TRANSP); + animArc->user_data = this; lv_obj_set_click(animArc, false); @@ -80,8 +81,8 @@ void SettingShakeThreshold::Refresh() { if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(2000)) { vCalTime = xTaskGetTickCount(); calibrating = 2; - lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_RELEASED, LV_COLOR_RED); - lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_PRESSED, LV_COLOR_RED); + lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED); + lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED); lv_label_set_text(calLabel, "Shake!!"); } } @@ -108,17 +109,17 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { switch (event) { case LV_EVENT_VALUE_CHANGED: { if (object == calButton) { - if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED && calibrating == 0) { lv_arc_set_value(positionArc, 0); calibrating = 1; vCalTime = xTaskGetTickCount(); lv_label_set_text(calLabel, "Ready!"); - lv_obj_set_click(calButton,false); + lv_obj_set_click(positionArc, false); + lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN); + lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN); } else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) { - calibrating = 0; - lv_obj_set_click(calButton,true); + lv_obj_set_click(positionArc, true); lv_label_set_text(calLabel, "Calibrate"); } break; diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h index ed5658923b..6d4ccf6688 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.h +++ b/src/displayapp/screens/settings/SettingShakeThreshold.h @@ -27,7 +27,6 @@ namespace Pinetime { System::SystemTask& systemTask; uint8_t calibrating; uint32_t vDecay,vCalTime; - lv_obj_t* cbOption[2]; lv_obj_t *positionArc, *animArc,*calButton, *calLabel; lv_task_t* refreshTask; }; From 46f3f8e6db2e3a9a5c5bbde8d2b1d5ff293cdaec Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 5 Oct 2021 03:29:49 +0000 Subject: [PATCH 12/17] Remove "fancy" settings display and always show ShakeWakeThresholdSetting --- src/displayapp/screens/settings/Settings.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index 0cf20a9bea..050f2ce698 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -61,12 +61,10 @@ std::unique_ptr Settings::CreateScreen3() { std::array applications {{ {Symbols::list, "About", Apps::SysInfo}, - {Symbols::none, "None", Apps::None}, + {Symbols::none, "Wake Sense", Apps::SettingShakeThreshold}, {Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None}, }}; - if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) { - applications[1] = {Symbols::list, "Wake Sense", Apps::SettingShakeThreshold}; - } + return std::make_unique(2, 3, app, settingsController, applications); } From 9ae2818cdba961d05ef00b72061cd36efa5b8f2a Mon Sep 17 00:00:00 2001 From: coxtor Date: Fri, 8 Oct 2021 22:30:50 +0200 Subject: [PATCH 13/17] make colors generic and usable for all apps --- src/components/settings/Settings.h | 25 ++++---- src/displayapp/Colors.cpp | 57 ++++++++++++------- src/displayapp/Colors.h | 25 +++++++- src/displayapp/screens/PineTimeStyle.cpp | 4 +- .../screens/settings/SettingPineTimeStyle.cpp | 52 ++++++++--------- .../screens/settings/SettingPineTimeStyle.h | 4 +- 6 files changed, 102 insertions(+), 65 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 79fa958f80..5b2fa6cc57 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -5,7 +5,7 @@ #include "components/brightness/BrightnessController.h" #include "components/fs/FS.h" #include "drivers/Cst816s.h" - +#include namespace Pinetime { namespace Controllers { class Settings { @@ -18,13 +18,12 @@ namespace Pinetime { RaiseWrist = 2, Shake = 3, }; - enum class Colors : uint8_t { - White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange - }; + struct PineTimeStyle { - Colors ColorTime = Colors::Teal; - Colors ColorBar = Colors::Teal; - Colors ColorBG = Colors::Black; +// Applications::Colors ColorTime = Applications::Colors::Black; + Applications::Colors ColorTime = Applications::Colors::Teal; + Applications::Colors ColorBar = Applications::Colors::Teal; + Applications::Colors ColorBG = Applications::Colors::Black; }; Settings(Pinetime::Controllers::FS& fs); @@ -42,30 +41,30 @@ namespace Pinetime { return settings.clockFace; }; - void SetPTSColorTime(Colors colorTime) { + void SetPTSColorTime(Applications::Colors colorTime) { if (colorTime != settings.PTS.ColorTime) settingsChanged = true; settings.PTS.ColorTime = colorTime; }; - Colors GetPTSColorTime() const { + Applications::Colors GetPTSColorTime() const { return settings.PTS.ColorTime; }; - void SetPTSColorBar(Colors colorBar) { + void SetPTSColorBar(Applications::Colors colorBar) { if (colorBar != settings.PTS.ColorBar) settingsChanged = true; settings.PTS.ColorBar = colorBar; }; - Colors GetPTSColorBar() const { + Applications::Colors GetPTSColorBar() const { return settings.PTS.ColorBar; }; - void SetPTSColorBG(Colors colorBG) { + void SetPTSColorBG(Applications::Colors colorBG) { if (colorBG != settings.PTS.ColorBG) settingsChanged = true; settings.PTS.ColorBG = colorBG; }; - Colors GetPTSColorBG() const { + Applications::Colors GetPTSColorBG() const { return settings.PTS.ColorBG; }; diff --git a/src/displayapp/Colors.cpp b/src/displayapp/Colors.cpp index f45f072257..35a840dc43 100644 --- a/src/displayapp/Colors.cpp +++ b/src/displayapp/Colors.cpp @@ -1,27 +1,44 @@ #include "Colors.h" using namespace Pinetime::Applications; -using namespace Pinetime::Controllers; -lv_color_t Pinetime::Applications::Convert(Pinetime::Controllers::Settings::Colors color) { +lv_color_t Pinetime::Applications::Convert(Colors color) { switch (color) { - case Pinetime::Controllers::Settings::Colors::White: return LV_COLOR_WHITE; - case Pinetime::Controllers::Settings::Colors::Silver: return LV_COLOR_SILVER; - case Pinetime::Controllers::Settings::Colors::Gray: return LV_COLOR_GRAY; - case Pinetime::Controllers::Settings::Colors::Black: return LV_COLOR_BLACK; - case Pinetime::Controllers::Settings::Colors::Red: return LV_COLOR_RED; - case Pinetime::Controllers::Settings::Colors::Maroon: return LV_COLOR_MAROON; - case Pinetime::Controllers::Settings::Colors::Yellow: return LV_COLOR_YELLOW; - case Pinetime::Controllers::Settings::Colors::Olive: return LV_COLOR_OLIVE; - case Pinetime::Controllers::Settings::Colors::Lime: return LV_COLOR_LIME; - case Pinetime::Controllers::Settings::Colors::Green: return LV_COLOR_GREEN; - case Pinetime::Controllers::Settings::Colors::Cyan: return LV_COLOR_CYAN; - case Pinetime::Controllers::Settings::Colors::Teal: return LV_COLOR_TEAL; - case Pinetime::Controllers::Settings::Colors::Blue: return LV_COLOR_BLUE; - case Pinetime::Controllers::Settings::Colors::Navy: return LV_COLOR_NAVY; - case Pinetime::Controllers::Settings::Colors::Magenta: return LV_COLOR_MAGENTA; - case Pinetime::Controllers::Settings::Colors::Purple: return LV_COLOR_PURPLE; - case Pinetime::Controllers::Settings::Colors::Orange: return LV_COLOR_ORANGE; - default: return LV_COLOR_WHITE; + case Colors::White: + return LV_COLOR_WHITE; + case Colors::Silver: + return LV_COLOR_SILVER; + case Colors::Gray: + return LV_COLOR_GRAY; + case Colors::Black: + return LV_COLOR_BLACK; + case Colors::Red: + return LV_COLOR_RED; + case Colors::Maroon: + return LV_COLOR_MAROON; + case Colors::Yellow: + return LV_COLOR_YELLOW; + case Colors::Olive: + return LV_COLOR_OLIVE; + case Colors::Lime: + return LV_COLOR_LIME; + case Colors::Green: + return LV_COLOR_GREEN; + case Colors::Cyan: + return LV_COLOR_CYAN; + case Colors::Teal: + return LV_COLOR_TEAL; + case Colors::Blue: + return LV_COLOR_BLUE; + case Colors::Navy: + return LV_COLOR_NAVY; + case Colors::Magenta: + return LV_COLOR_MAGENTA; + case Colors::Purple: + return LV_COLOR_PURPLE; + case Colors::Orange: + return LV_COLOR_ORANGE; + default: + return LV_COLOR_WHITE; } } diff --git a/src/displayapp/Colors.h b/src/displayapp/Colors.h index 9db7dd20ca..c09b398589 100644 --- a/src/displayapp/Colors.h +++ b/src/displayapp/Colors.h @@ -1,10 +1,31 @@ #pragma once #include -#include +//#include namespace Pinetime { namespace Applications { - lv_color_t Convert(Controllers::Settings::Colors color); + + enum class Colors : uint8_t { + White, + Silver, + Gray, + Black, + Red, + Maroon, + Yellow, + Olive, + Lime, + Green, + Cyan, + Teal, + Blue, + Navy, + Magenta, + Purple, + Orange + }; + + lv_color_t Convert(Colors color); } } \ No newline at end of file diff --git a/src/displayapp/screens/PineTimeStyle.cpp b/src/displayapp/screens/PineTimeStyle.cpp index 6766ecb04f..831c2d4cad 100644 --- a/src/displayapp/screens/PineTimeStyle.cpp +++ b/src/displayapp/screens/PineTimeStyle.cpp @@ -62,7 +62,7 @@ PineTimeStyle::PineTimeStyle(DisplayApp* app, displayedChar[3] = 0; displayedChar[4] = 0; - //Create a 200px wide background rectangle + // Create a 200px wide background rectangle timebar = lv_obj_create(lv_scr_act(), nullptr); lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetPTSColorBG())); lv_obj_set_style_local_radius(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 0); @@ -257,7 +257,7 @@ void PineTimeStyle::Refresh() { char hoursChar[3]; char ampmChar[5]; if (settingsController.GetClockType() == Controllers::Settings::ClockType::H24) { - sprintf(hoursChar, "%02d", hour); + sprintf(hoursChar, "%02d", hour); } else { if (hour == 0 && hour != 12) { hour = 12; diff --git a/src/displayapp/screens/settings/SettingPineTimeStyle.cpp b/src/displayapp/screens/settings/SettingPineTimeStyle.cpp index c9af19b628..dde4174dce 100644 --- a/src/displayapp/screens/settings/SettingPineTimeStyle.cpp +++ b/src/displayapp/screens/settings/SettingPineTimeStyle.cpp @@ -239,14 +239,14 @@ void SettingPineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event) { } if (object == btnNextBar) { valueBar = GetNext(valueBar); - if(valueBar == Controllers::Settings::Colors::Black) + if(valueBar == Applications::Colors::Black) valueBar = GetNext(valueBar); settingsController.SetPTSColorBar(valueBar); lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(valueBar)); } if (object == btnPrevBar) { valueBar = GetPrevious(valueBar); - if(valueBar == Controllers::Settings::Colors::Black) + if(valueBar == Applications::Colors::Black) valueBar = GetPrevious(valueBar); settingsController.SetPTSColorBar(valueBar); lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(valueBar)); @@ -262,14 +262,14 @@ void SettingPineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event) { lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(valueBG)); } if (object == btnReset) { - settingsController.SetPTSColorTime(Controllers::Settings::Colors::Teal); - lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(Controllers::Settings::Colors::Teal)); - lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(Controllers::Settings::Colors::Teal)); - lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(Controllers::Settings::Colors::Teal)); - settingsController.SetPTSColorBar(Controllers::Settings::Colors::Teal); - lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(Controllers::Settings::Colors::Teal)); - settingsController.SetPTSColorBG(Controllers::Settings::Colors::Black); - lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(Controllers::Settings::Colors::Black)); + settingsController.SetPTSColorTime(Applications::Colors::Teal); + lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Teal)); + lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Teal)); + lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Teal)); + settingsController.SetPTSColorBar(Applications::Colors::Teal); + lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Teal)); + settingsController.SetPTSColorBG(Applications::Colors::Black); + lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Black)); } if (object == btnRandom) { uint8_t randTime = rand() % 17; @@ -282,37 +282,37 @@ void SettingPineTimeStyle::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (randBar == 3) { randBar -= 1; } - settingsController.SetPTSColorTime(static_cast(randTime)); - lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randTime))); - lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randTime))); - lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randTime))); - settingsController.SetPTSColorBar(static_cast(randBar)); - lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randBar))); - settingsController.SetPTSColorBG(static_cast(randBG)); - lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randBG))); + settingsController.SetPTSColorTime(static_cast(randTime)); + lv_obj_set_style_local_text_color(timeDD1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randTime))); + lv_obj_set_style_local_text_color(timeDD2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randTime))); + lv_obj_set_style_local_text_color(timeAMPM, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randTime))); + settingsController.SetPTSColorBar(static_cast(randBar)); + lv_obj_set_style_local_bg_color(sidebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randBar))); + settingsController.SetPTSColorBG(static_cast(randBG)); + lv_obj_set_style_local_bg_color(timebar, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(static_cast(randBG))); } } } -Pinetime::Controllers::Settings::Colors SettingPineTimeStyle::GetNext(Pinetime::Controllers::Settings::Colors color) { +Pinetime::Applications::Colors SettingPineTimeStyle::GetNext(Pinetime::Applications::Colors color) { auto colorAsInt = static_cast(color); - Pinetime::Controllers::Settings::Colors nextColor; + Pinetime::Applications::Colors nextColor; if (colorAsInt < 16) { - nextColor = static_cast(colorAsInt + 1); + nextColor = static_cast(colorAsInt + 1); } else { - nextColor = static_cast(0); + nextColor = static_cast(0); } return nextColor; } -Pinetime::Controllers::Settings::Colors SettingPineTimeStyle::GetPrevious(Pinetime::Controllers::Settings::Colors color) { +Pinetime::Applications::Colors SettingPineTimeStyle::GetPrevious(Pinetime::Applications::Colors color) { auto colorAsInt = static_cast(color); - Pinetime::Controllers::Settings::Colors prevColor; + Pinetime::Applications::Colors prevColor; if (colorAsInt > 0) { - prevColor = static_cast(colorAsInt - 1); + prevColor = static_cast(colorAsInt - 1); } else { - prevColor = static_cast(16); + prevColor = static_cast(16); } return prevColor; } diff --git a/src/displayapp/screens/settings/SettingPineTimeStyle.h b/src/displayapp/screens/settings/SettingPineTimeStyle.h index 397bd86d46..3b3f6a1e8e 100644 --- a/src/displayapp/screens/settings/SettingPineTimeStyle.h +++ b/src/displayapp/screens/settings/SettingPineTimeStyle.h @@ -20,8 +20,8 @@ namespace Pinetime { private: Controllers::Settings& settingsController; - Pinetime::Controllers::Settings::Colors GetNext(Controllers::Settings::Colors color); - Pinetime::Controllers::Settings::Colors GetPrevious(Controllers::Settings::Colors color); + Applications::Colors GetNext(Applications::Colors color); + Applications::Colors GetPrevious(Applications::Colors color); lv_obj_t * btnNextTime; lv_obj_t * btnPrevTime; From 13f294eb24020ebc6e0c4a0474a960bca4d1c7a2 Mon Sep 17 00:00:00 2001 From: coxtor Date: Fri, 8 Oct 2021 22:31:45 +0200 Subject: [PATCH 14/17] enhance torch features --- src/displayapp/screens/FlashLight.cpp | 62 +++++++++++++-------------- src/displayapp/screens/FlashLight.h | 17 ++++++-- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 4bc5b558c2..36712628fb 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -4,13 +4,6 @@ using namespace Pinetime::Applications::Screens; -namespace { - static void event_handler(lv_obj_t* obj, lv_event_t event) { - FlashLight* screen = static_cast(obj->user_data); - screen->OnClickEvent(obj, event); - } -} - FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness) @@ -21,14 +14,7 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, { brightness.Backup(); brightness.Set(Controllers::BrightnessController::Levels::High); - // Set the background - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); - - flashLight = lv_label_create(lv_scr_act(), NULL); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); - lv_label_set_text_static(flashLight, Symbols::highlight); - lv_obj_align(flashLight, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex])); backgroundAction = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP); @@ -37,34 +23,48 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, lv_label_set_text(backgroundAction, ""); lv_obj_set_click(backgroundAction, true); backgroundAction->user_data = this; - lv_obj_set_event_cb(backgroundAction, event_handler); systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); } FlashLight::~FlashLight() { lv_obj_clean(lv_scr_act()); - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Black)); brightness.Restore(); systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); } -void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { - if (obj == backgroundAction) { - if (event == LV_EVENT_CLICKED) { - isOn = !isOn; - - if (isOn) { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); +bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + switch (event) { + case TouchEvents::SwipeLeft: + currentColorIndex--; + if (currentColorIndex <= 0) { + currentColorIndex = 11; + } + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex])); + break; + case TouchEvents::SwipeRight: + currentColorIndex++; + if (currentColorIndex >= 11) { + currentColorIndex = 0; + } + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex])); + break; + case TouchEvents::SwipeUp: + brightness.Higher(); + break; + case TouchEvents::SwipeDown: + brightness.Lower(); + break; + case TouchEvents::DoubleTap: + if (brightness.Level() == Pinetime::Controllers::BrightnessController::Levels::Off) { + brightness.Set(Pinetime::Controllers::BrightnessController::Levels::Medium); } else { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + brightness.Set(Pinetime::Controllers::BrightnessController::Levels::Off); } - } + break; + default: + break; } -} - -bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return false; } diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 7f5ca6c5dc..8a5b5acdc4 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -5,7 +5,7 @@ #include #include "systemtask/SystemTask.h" #include "components/brightness/BrightnessController.h" - +#include namespace Pinetime { namespace Applications { @@ -17,15 +17,24 @@ namespace Pinetime { ~FlashLight() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; - void OnClickEvent(lv_obj_t* obj, lv_event_t event); private: Pinetime::System::SystemTask& systemTask; Controllers::BrightnessController& brightness; - lv_obj_t* flashLight; lv_obj_t* backgroundAction; - bool isOn = true; + Colors torchColors[11] = {Colors::Black, + Colors::White, + Colors::Gray, + Colors::Red, + Colors::Yellow, + Colors::Green, + Colors::Cyan, + Colors::Teal, + Colors::Navy, + Colors::Magenta, + Colors::Orange}; + int8_t currentColorIndex = 0; }; } } From e6ff370cfcd27f93c353872fdcd71a3afbedff54 Mon Sep 17 00:00:00 2001 From: coxtor Date: Fri, 8 Oct 2021 22:38:55 +0200 Subject: [PATCH 15/17] Remove comment --- src/components/settings/Settings.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 5b2fa6cc57..4582dfd28f 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -20,7 +20,6 @@ namespace Pinetime { }; struct PineTimeStyle { -// Applications::Colors ColorTime = Applications::Colors::Black; Applications::Colors ColorTime = Applications::Colors::Teal; Applications::Colors ColorBar = Applications::Colors::Teal; Applications::Colors ColorBG = Applications::Colors::Black; From 05a4fb45a1907a809665a07a66824c2d58e97c77 Mon Sep 17 00:00:00 2001 From: coxtor Date: Fri, 8 Oct 2021 23:25:28 +0200 Subject: [PATCH 16/17] Save last color, longpress to go back to first color --- src/components/settings/Settings.h | 35 ++++++++++++++++++--------- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/FlashLight.cpp | 13 +++++++--- src/displayapp/screens/FlashLight.h | 11 +++++---- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 4582dfd28f..b783222505 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -40,6 +40,16 @@ namespace Pinetime { return settings.clockFace; }; + void setLastTorchColorIndex(uint8_t lastTorchColorIndex) { + if (lastTorchColorIndex != settings.lastTourchColorIndex) { + settingsChanged = true; + } + settings.lastTourchColorIndex = lastTorchColorIndex; + }; + uint8_t getLastTorchColorIndex() { + return settings.lastTourchColorIndex; + }; + void SetPTSColorTime(Applications::Colors colorTime) { if (colorTime != settings.PTS.ColorTime) settingsChanged = true; @@ -113,15 +123,14 @@ namespace Pinetime { return settings.screenTimeOut; }; - void SetShakeThreshold(uint16_t thresh){ - if(settings.shakeWakeThreshold != thresh){ - settings.shakeWakeThreshold = thresh; - settingsChanged = true; + void SetShakeThreshold(uint16_t thresh) { + if (settings.shakeWakeThreshold != thresh) { + settings.shakeWakeThreshold = thresh; + settingsChanged = true; } - } - int16_t GetShakeThreshold() const{ + int16_t GetShakeThreshold() const { return settings.shakeWakeThreshold; } @@ -163,14 +172,16 @@ namespace Pinetime { return settings.brightLevel; }; - void SetStepsGoal( uint32_t goal ) { - if ( goal != settings.stepsGoal ) { + void SetStepsGoal(uint32_t goal) { + if (goal != settings.stepsGoal) { settingsChanged = true; } - settings.stepsGoal = goal; + settings.stepsGoal = goal; + }; + + uint32_t GetStepsGoal() const { + return settings.stepsGoal; }; - - uint32_t GetStepsGoal() const { return settings.stepsGoal; }; private: Pinetime::Controllers::FS& fs; @@ -191,6 +202,8 @@ namespace Pinetime { std::bitset<4> wakeUpMode {0}; uint16_t shakeWakeThreshold = 150; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; + + u_int8_t lastTourchColorIndex = 0; }; SettingsData settings; diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 2267c8bc2f..dcf80991ab 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -384,7 +384,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::FlashLight: - currentScreen = std::make_unique(this, *systemTask, brightnessController); + currentScreen = std::make_unique(this, *systemTask, brightnessController, settingsController); ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); break; case Apps::StopWatch: diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 36712628fb..a03febffec 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -6,16 +6,18 @@ using namespace Pinetime::Applications::Screens; FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, System::SystemTask& systemTask, - Controllers::BrightnessController& brightness) + Controllers::BrightnessController& brightness, + Pinetime::Controllers::Settings &settingsController) : Screen(app), systemTask {systemTask}, - brightness {brightness} + brightness {brightness}, + settingsController {settingsController} { brightness.Backup(); brightness.Set(Controllers::BrightnessController::Levels::High); + currentColorIndex = settingsController.getLastTorchColorIndex(); lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex])); - backgroundAction = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP); lv_obj_set_size(backgroundAction, 240, 240); @@ -28,6 +30,7 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, } FlashLight::~FlashLight() { + settingsController.setLastTorchColorIndex(currentColorIndex); lv_obj_clean(lv_scr_act()); lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(Applications::Colors::Black)); brightness.Restore(); @@ -63,6 +66,10 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { brightness.Set(Pinetime::Controllers::BrightnessController::Levels::Off); } break; + case TouchEvents::LongTap: + currentColorIndex = 0; + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_BTN_PART_MAIN, LV_STATE_DEFAULT, Convert(torchColors[currentColorIndex])); + break; default: break; } diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 8a5b5acdc4..36a9bdb542 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -13,7 +13,7 @@ namespace Pinetime { class FlashLight : public Screen { public: - FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness); + FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness, Controllers::Settings &settingsController); ~FlashLight() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; @@ -21,10 +21,10 @@ namespace Pinetime { private: Pinetime::System::SystemTask& systemTask; Controllers::BrightnessController& brightness; + Controllers::Settings& settingsController; lv_obj_t* backgroundAction; - Colors torchColors[11] = {Colors::Black, - Colors::White, + Colors torchColors[11] = {Colors::White, Colors::Gray, Colors::Red, Colors::Yellow, @@ -33,8 +33,9 @@ namespace Pinetime { Colors::Teal, Colors::Navy, Colors::Magenta, - Colors::Orange}; - int8_t currentColorIndex = 0; + Colors::Orange, + Colors::Black}; + int8_t currentColorIndex; }; } } From c7d2749bdc49b66112bad5a61be0be95e9e8372c Mon Sep 17 00:00:00 2001 From: coxtor Date: Fri, 8 Oct 2021 23:43:25 +0200 Subject: [PATCH 17/17] revert merge shake to wake --- src/CMakeLists.txt | 1 - src/components/motion/MotionController.cpp | 41 +----- src/components/motion/MotionController.h | 12 +- src/components/settings/Settings.h | 23 +--- src/displayapp/Apps.h | 3 +- src/displayapp/DisplayApp.cpp | 5 - .../settings/SettingShakeThreshold.cpp | 129 ------------------ .../screens/settings/SettingShakeThreshold.h | 35 ----- .../screens/settings/SettingWakeUp.cpp | 8 -- .../screens/settings/SettingWakeUp.h | 2 +- src/displayapp/screens/settings/Settings.cpp | 4 +- src/systemtask/SystemTask.cpp | 14 +- 12 files changed, 21 insertions(+), 256 deletions(-) delete mode 100644 src/displayapp/screens/settings/SettingShakeThreshold.cpp delete mode 100644 src/displayapp/screens/settings/SettingShakeThreshold.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 581738097b..37ee0848bd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -433,7 +433,6 @@ list(APPEND SOURCE_FILES displayapp/screens/settings/SettingDisplay.cpp displayapp/screens/settings/SettingSteps.cpp displayapp/screens/settings/SettingPineTimeStyle.cpp - displayapp/screens/settings/SettingShakeThreshold.cpp ## Watch faces displayapp/icons/bg_clock.c diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index ac5c67d6fe..b0dbada47f 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -1,5 +1,5 @@ #include "MotionController.h" -#include "os/os_cputime.h" + using namespace Pinetime::Controllers; void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) { @@ -9,7 +9,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) this->nbSteps = nbSteps; } -bool MotionController::Should_RaiseWake(bool isSleeping) { +bool MotionController::ShouldWakeUp(bool isSleeping) { if ((x + 335) <= 670 && z < 0) { if (not isSleeping) { if (y <= 0) { @@ -31,42 +31,13 @@ bool MotionController::Should_RaiseWake(bool isSleeping) { } return false; } - -bool MotionController::Should_ShakeWake(uint16_t thresh) { - bool wake = false; - auto diff = xTaskGetTickCount() - lastShakeTime; - lastShakeTime = xTaskGetTickCount(); - /* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */ - int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100; - //(.2 * speed) + ((1 - .2) * accumulatedspeed); - // implemented without floats as .25Alpha - accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4); - - if (accumulatedspeed > thresh) { - wake = true; - } - lastXForShake = x / 4; - lastYForShake = y / 2; - lastZForShake = z; - return wake; -} -int32_t MotionController::currentShakeSpeed() { - return accumulatedspeed; -} - void MotionController::IsSensorOk(bool isOk) { isSensorOk = isOk; } void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) { - switch (types) { - case Drivers::Bma421::DeviceTypes::BMA421: - this->deviceType = DeviceTypes::BMA421; - break; - case Drivers::Bma421::DeviceTypes::BMA425: - this->deviceType = DeviceTypes::BMA425; - break; - default: - this->deviceType = DeviceTypes::Unknown; - break; + switch(types){ + case Drivers::Bma421::DeviceTypes::BMA421: this->deviceType = DeviceTypes::BMA421; break; + case Drivers::Bma421::DeviceTypes::BMA425: this->deviceType = DeviceTypes::BMA425; break; + default: this->deviceType = DeviceTypes::Unknown; break; } } diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index 66b875a5db..ff715093f4 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -27,10 +27,8 @@ namespace Pinetime { uint32_t NbSteps() const { return nbSteps; } - - bool Should_ShakeWake(uint16_t thresh); - bool Should_RaiseWake(bool isSleeping); - int32_t currentShakeSpeed(); + bool ShouldWakeUp(bool isSleeping); + void IsSensorOk(bool isOk); bool IsSensorOk() const { return isSensorOk; @@ -50,12 +48,6 @@ namespace Pinetime { int16_t lastYForWakeUp = 0; bool isSensorOk = false; DeviceTypes deviceType = DeviceTypes::Unknown; - - int16_t lastXForShake = 0; - int16_t lastYForShake = 0; - int16_t lastZForShake = 0; - int32_t accumulatedspeed = 0; - 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 b783222505..b561f0be33 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -16,7 +16,6 @@ namespace Pinetime { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, - Shake = 3, }; struct PineTimeStyle { @@ -118,22 +117,10 @@ namespace Pinetime { } settings.screenTimeOut = timeout; }; - uint32_t GetScreenTimeOut() const { return settings.screenTimeOut; }; - void SetShakeThreshold(uint16_t thresh) { - if (settings.shakeWakeThreshold != thresh) { - settings.shakeWakeThreshold = thresh; - settingsChanged = true; - } - } - - int16_t GetShakeThreshold() const { - return settings.shakeWakeThreshold; - } - void setWakeUpMode(WakeUpMode wakeUp, bool enabled) { if (enabled != isWakeUpModeOn(wakeUp)) { settingsChanged = true; @@ -148,13 +135,13 @@ namespace Pinetime { case WakeUpMode::DoubleTap: settings.wakeUpMode.set(static_cast(WakeUpMode::SingleTap), false); break; - default: + case WakeUpMode::RaiseWrist: break; } } }; - std::bitset<4> getWakeUpModes() const { + std::bitset<3> getWakeUpModes() const { return settings.wakeUpMode; } @@ -186,7 +173,7 @@ namespace Pinetime { private: Pinetime::Controllers::FS& fs; - static constexpr uint32_t settingsVersion = 0x0003; + static constexpr uint32_t settingsVersion = 0x0002; struct SettingsData { uint32_t version = settingsVersion; uint32_t stepsGoal = 10000; @@ -199,8 +186,8 @@ namespace Pinetime { PineTimeStyle PTS; - std::bitset<4> wakeUpMode {0}; - uint16_t shakeWakeThreshold = 150; + std::bitset<3> wakeUpMode {0}; + Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; u_int8_t lastTourchColorIndex = 0; diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 8cdb565b3a..e3aca8cf00 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -32,8 +32,7 @@ namespace Pinetime { SettingDisplay, SettingWakeUp, SettingSteps, - SettingPineTimeStyle, - SettingShakeThreshold + SettingPineTimeStyle }; } } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index dcf80991ab..93bf84c880 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -44,7 +44,6 @@ #include "displayapp/screens/settings/SettingDisplay.h" #include "displayapp/screens/settings/SettingSteps.h" #include "displayapp/screens/settings/SettingPineTimeStyle.h" -#include "displayapp/screens/settings/SettingShakeThreshold.h" #include "libs/lv_conf.h" @@ -370,10 +369,6 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, settingsController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; - case Apps::SettingShakeThreshold: - currentScreen = std::make_unique(this, settingsController,motionController,*systemTask); - ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); - break; case Apps::BatteryInfo: currentScreen = std::make_unique(this, batteryController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp deleted file mode 100644 index c42bb9ae1f..0000000000 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include "SettingShakeThreshold.h" -#include -#include "displayapp/DisplayApp.h" -#include "displayapp/screens/Screen.h" -#include "displayapp/screens/Symbols.h" - -using namespace Pinetime::Applications::Screens; - -namespace { - void event_handler(lv_obj_t* obj, lv_event_t event) { - SettingShakeThreshold* screen = static_cast(obj->user_data); - screen->UpdateSelected(obj, event); - } -} - -SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app, - Controllers::Settings& settingsController, - Controllers::MotionController& motionController, - System::SystemTask& systemTask) - : Screen(app), settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} { - - lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(title, "Wake Sensitivity"); - lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); - lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); - - positionArc = lv_arc_create(lv_scr_act(), nullptr); - positionArc->user_data = this; - - lv_obj_set_event_cb(positionArc, event_handler); - lv_arc_set_bg_angles(positionArc, 180, 360); - lv_arc_set_range(positionArc, 0, 4095); - lv_arc_set_adjustable(positionArc, true); - lv_obj_set_width(positionArc, lv_obj_get_width(lv_scr_act()) - 10); - lv_obj_set_height(positionArc, 240); - lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); - - animArc = lv_arc_create(positionArc, positionArc); - lv_arc_set_adjustable(animArc, false); - lv_obj_set_width(animArc, lv_obj_get_width(positionArc)); - lv_obj_set_height(animArc, lv_obj_get_height(positionArc)); - lv_obj_align_mid(animArc, positionArc, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0); - lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_70); - lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_KNOB, LV_STATE_DEFAULT, LV_OPA_0); - lv_obj_set_style_local_line_color(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); - lv_obj_set_style_local_bg_color(animArc, LV_ARC_PART_BG, LV_STATE_CHECKED, LV_COLOR_TRANSP); - - animArc->user_data = this; - lv_obj_set_click(animArc, false); - - calButton = lv_btn_create(lv_scr_act(), nullptr); - calButton->user_data = this; - lv_obj_set_event_cb(calButton, event_handler); - lv_obj_set_height(calButton, 80); - lv_obj_set_width(calButton, 200); - lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0); - lv_btn_set_checkable(calButton, true); - calLabel = lv_label_create(calButton, NULL); - lv_label_set_text(calLabel, "Calibrate"); - - lv_arc_set_value(positionArc, settingsController.GetShakeThreshold()); - - vDecay = xTaskGetTickCount(); - calibrating = false; - - refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); -} - -SettingShakeThreshold::~SettingShakeThreshold() { - settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); - - lv_task_del(refreshTask); - settingsController.SaveSettings(); - lv_obj_clean(lv_scr_act()); -} - -void SettingShakeThreshold::Refresh() { - - if (calibrating == 1) { - if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(2000)) { - vCalTime = xTaskGetTickCount(); - calibrating = 2; - lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED); - lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED); - lv_label_set_text(calLabel, "Shake!!"); - } - } - if (calibrating == 2) { - - if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) { - lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 300); - } - if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(7500)) { - lv_btn_set_state(calButton, LV_STATE_DEFAULT); - lv_event_send(calButton, LV_EVENT_VALUE_CHANGED, NULL); - } - } - if (motionController.currentShakeSpeed() - 300 > lv_arc_get_value(animArc)) { - lv_arc_set_value(animArc, (uint16_t) motionController.currentShakeSpeed() - 300); - vDecay = xTaskGetTickCount(); - } else if ((xTaskGetTickCount() - vDecay) > pdMS_TO_TICKS(1500)) { - lv_arc_set_value(animArc, lv_arc_get_value(animArc) - 25); - } -} - -void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) { - - switch (event) { - case LV_EVENT_VALUE_CHANGED: { - if (object == calButton) { - if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED && calibrating == 0) { - lv_arc_set_value(positionArc, 0); - calibrating = 1; - vCalTime = xTaskGetTickCount(); - lv_label_set_text(calLabel, "Ready!"); - lv_obj_set_click(positionArc, false); - lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN); - lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN); - } else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) { - calibrating = 0; - lv_obj_set_click(positionArc, true); - lv_label_set_text(calLabel, "Calibrate"); - } - break; - } - } - } -} diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h deleted file mode 100644 index 6d4ccf6688..0000000000 --- a/src/displayapp/screens/settings/SettingShakeThreshold.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include -#include -#include "components/settings/Settings.h" -#include "displayapp/screens/Screen.h" -#include -namespace Pinetime { - - namespace Applications { - namespace Screens { - - class SettingShakeThreshold : public Screen { - public: - SettingShakeThreshold(DisplayApp* app, - Pinetime::Controllers::Settings& settingsController, - Controllers::MotionController& motionController, - System::SystemTask& systemTask); - - ~SettingShakeThreshold() override; - void Refresh() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); - - private: - Controllers::Settings& settingsController; - Controllers::MotionController& motionController; - System::SystemTask& systemTask; - uint8_t calibrating; - uint32_t vDecay,vCalTime; - lv_obj_t *positionArc, *animArc,*calButton, *calLabel; - lv_task_t* refreshTask; - }; - } - } -} diff --git a/src/displayapp/screens/settings/SettingWakeUp.cpp b/src/displayapp/screens/settings/SettingWakeUp.cpp index c6ff0dc9cd..d999004b5d 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.cpp +++ b/src/displayapp/screens/settings/SettingWakeUp.cpp @@ -65,14 +65,6 @@ 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], " Shake Wake"); - cbOption[optionsTotal]->user_data = this; - lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); - if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) { - lv_checkbox_set_checked(cbOption[optionsTotal], true); - } - optionsTotal++; } SettingWakeUp::~SettingWakeUp() { diff --git a/src/displayapp/screens/settings/SettingWakeUp.h b/src/displayapp/screens/settings/SettingWakeUp.h index cd244ae51f..b9a31dc9e5 100644 --- a/src/displayapp/screens/settings/SettingWakeUp.h +++ b/src/displayapp/screens/settings/SettingWakeUp.h @@ -20,7 +20,7 @@ namespace Pinetime { private: Controllers::Settings& settingsController; uint8_t optionsTotal; - lv_obj_t* cbOption[5]; + lv_obj_t* cbOption[4]; // When UpdateSelected is called, it uses lv_checkbox_set_checked, // which can cause extra events to be fired, // which might trigger UpdateSelected again, causing a loop. diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index 050f2ce698..e3319f030a 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -61,10 +61,10 @@ std::unique_ptr Settings::CreateScreen3() { std::array applications {{ {Symbols::list, "About", Apps::SysInfo}, - {Symbols::none, "Wake Sense", Apps::SettingShakeThreshold}, + {Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None}, }}; - + return std::make_unique(2, 3, app, settingsController, applications); } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index eba908b00d..5441c16245 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -24,6 +24,7 @@ #include "drivers/PinMap.h" #include "main.h" + #include using namespace Pinetime::System; @@ -388,10 +389,9 @@ void SystemTask::UpdateMotion() { if (isGoingToSleep or isWakingUp) return; - if (isSleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) || - settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) + if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) return; - + if (stepCounterMustBeReset) { motionSensor.ResetStepCounter(); stepCounterMustBeReset = false; @@ -401,13 +401,7 @@ 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)) { - GoToRunning(); - } - if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && - motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) { + if (motionController.ShouldWakeUp(isSleeping)) { GoToRunning(); } }