From 145a755312bb410b8e5fb311a8fa67540250569a Mon Sep 17 00:00:00 2001 From: Lionel Elie Mamane Date: Wed, 6 Nov 2024 21:44:42 +0100 Subject: [PATCH 1/3] Settings; refuse to (fail to) calibrate shake sensitivity while in sleep mode (cherry picked from commit 1d25b7b9d09ff41b4310a4ccdcec5aab3a4d9579) --- .../screens/settings/SettingShakeThreshold.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index be67cc9563..88f54d5185 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -24,6 +24,19 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0); + if (settingsController.GetNotificationStatus() == Controllers::Settings::Notification::Sleep) { + lv_obj_t* explanation = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(explanation, LV_LABEL_LONG_BREAK); + lv_label_set_align(explanation, LV_LABEL_ALIGN_AUTO); + lv_obj_set_width(explanation, LV_HOR_RES_MAX); + lv_label_set_text_static( + explanation, + "\nShake detector is disabled in sleep mode, and will neither wake up the watch nor calibrate.\nDisable sleep mode to calibrate."); + calibrating = 255; + lv_obj_align(explanation, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); + return; + } + positionArc = lv_arc_create(lv_scr_act(), nullptr); positionArc->user_data = this; @@ -72,6 +85,9 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont } SettingShakeThreshold::~SettingShakeThreshold() { + if (calibrating == 255) + return; + settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); if (EnableForCal) { From 15886966ca65199df2d330f2464af7e2b2d8c70b Mon Sep 17 00:00:00 2001 From: Darius Arnold Date: Wed, 12 Mar 2025 20:10:46 +0000 Subject: [PATCH 2/3] Fix PR findings - Switch from bool EnableForCal to always saving and restoring shake wake mode to avoid to many conditionals in the constructor and destructor - Refactor calibrating into currentCalibrationStepEnum with descriptive names - Initialize variables with default values in the class body - Switch to forward declarations for references in the header and remove unused include - Fix issue where text would stay on screen due to not calling lv_obj_clean() in the destructor (cherry picked from commit af3039032b1ed2c6efea46cc2062bd3705e039b4) --- .../settings/SettingShakeThreshold.cpp | 49 +++++++++---------- .../screens/settings/SettingShakeThreshold.h | 30 +++++++++--- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index 88f54d5185..21677400ab 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -2,8 +2,10 @@ #include #include "displayapp/DisplayApp.h" #include "displayapp/screens/Screen.h" -#include "displayapp/screens/Symbols.h" #include "displayapp/InfiniTimeTheme.h" +#include +#include +#include "systemtask/SystemTask.h" using namespace Pinetime::Applications::Screens; @@ -18,7 +20,6 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont Controllers::MotionController& motionController, System::SystemTask& systemTask) : 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); @@ -32,7 +33,7 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont lv_label_set_text_static( explanation, "\nShake detector is disabled in sleep mode, and will neither wake up the watch nor calibrate.\nDisable sleep mode to calibrate."); - calibrating = 255; + currentCalibrationStep = CalibrationStep::Disabled; lv_obj_align(explanation, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); return; } @@ -75,42 +76,36 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont lv_arc_set_value(positionArc, settingsController.GetShakeThreshold()); vDecay = xTaskGetTickCount(); - calibrating = false; - EnableForCal = false; - if (!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) { - EnableForCal = true; - settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, true); - } + oldWakeupModeShake = settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake); + // Enable shake to wake for the calibration + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, true); refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } SettingShakeThreshold::~SettingShakeThreshold() { - if (calibrating == 255) - return; - - settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); - - if (EnableForCal) { - settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, false); - EnableForCal = false; + if (currentCalibrationStep != CalibrationStep::Disabled) { + // Don't set new threshold if calibration is disabled due to sleep mode + settingsController.SetShakeThreshold(lv_arc_get_value(positionArc)); + // Restore previous wakeup mode which is only changed if calibration is not disabled due to sleep mode + settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake, oldWakeupModeShake); + settingsController.SaveSettings(); + lv_task_del(refreshTask); } - lv_task_del(refreshTask); - settingsController.SaveSettings(); + lv_obj_clean(lv_scr_act()); } void SettingShakeThreshold::Refresh() { - - if (calibrating == 1) { + if (currentCalibrationStep == CalibrationStep::GettingReady) { if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(2000)) { vCalTime = xTaskGetTickCount(); - calibrating = 2; + currentCalibrationStep = CalibrationStep::Calibrating; 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_static(calLabel, "Shake!"); } } - if (calibrating == 2) { + if (currentCalibrationStep == CalibrationStep::Calibrating) { if ((motionController.CurrentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) { lv_arc_set_value(positionArc, (int16_t) motionController.CurrentShakeSpeed() - 300); @@ -129,19 +124,19 @@ void SettingShakeThreshold::Refresh() { } 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) { + if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED + && currentCalibrationStep == CalibrationStep::NotCalibrated) { lv_arc_set_value(positionArc, 0); - calibrating = 1; + currentCalibrationStep = CalibrationStep::GettingReady; vCalTime = xTaskGetTickCount(); lv_label_set_text_static(calLabel, "Ready!"); lv_obj_set_click(positionArc, false); lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, Colors::highlight); } else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) { - calibrating = 0; + currentCalibrationStep = CalibrationStep::NotCalibrated; lv_obj_set_click(positionArc, true); lv_label_set_text_static(calLabel, "Calibrate"); } diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h index 58bdb83a3e..d4459d250c 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.h +++ b/src/displayapp/screens/settings/SettingShakeThreshold.h @@ -2,10 +2,15 @@ #include #include -#include "components/settings/Settings.h" #include "displayapp/screens/Screen.h" -#include -#include "systemtask/SystemTask.h" + +namespace Pinetime::Controllers { + class Settings; + class MotionController; +} +namespace Pinetime::System { + class SystemTask; +} namespace Pinetime { @@ -26,11 +31,20 @@ namespace Pinetime { Controllers::Settings& settingsController; Controllers::MotionController& motionController; System::SystemTask& systemTask; - uint8_t calibrating; - bool EnableForCal; - uint32_t vDecay, vCalTime; - lv_obj_t *positionArc, *animArc, *calButton, *calLabel; - lv_task_t* refreshTask; + + enum class CalibrationStep { + NotCalibrated = 0, + GettingReady = 1, + Calibrating = 2, + // Special case for disabled calibration due to sleep mode + Disabled = 255, + }; + + CalibrationStep currentCalibrationStep = CalibrationStep::NotCalibrated; + bool oldWakeupModeShake = false; + uint32_t vDecay = 0, vCalTime = 0; + lv_obj_t *positionArc = nullptr, *animArc = nullptr, *calButton = nullptr, *calLabel = nullptr; + lv_task_t* refreshTask = nullptr; }; } } From 3203a11a88c051382290de6ba3a9f2fd978607d2 Mon Sep 17 00:00:00 2001 From: Darius Arnold Date: Thu, 13 Mar 2025 06:13:52 +0000 Subject: [PATCH 3/3] Formatting changes --- src/displayapp/screens/SystemInfo.cpp | 1 + src/displayapp/screens/settings/SettingShakeThreshold.cpp | 3 +-- src/displayapp/screens/settings/SettingShakeThreshold.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp index 886dacb6c6..f208a4fd86 100644 --- a/src/displayapp/screens/SystemInfo.cpp +++ b/src/displayapp/screens/SystemInfo.cpp @@ -180,6 +180,7 @@ std::unique_ptr SystemInfo::CreateScreen2() { extern int mallocFailedCount; extern int stackOverflowCount; + std::unique_ptr SystemInfo::CreateScreen3() { lv_mem_monitor_t mon; lv_mem_monitor(&mon); diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp index 21677400ab..d10c33a79a 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp +++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp @@ -127,8 +127,7 @@ 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 - && currentCalibrationStep == CalibrationStep::NotCalibrated) { + if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED && currentCalibrationStep == CalibrationStep::NotCalibrated) { lv_arc_set_value(positionArc, 0); currentCalibrationStep = CalibrationStep::GettingReady; vCalTime = xTaskGetTickCount(); diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h index d4459d250c..bb0d7ed387 100644 --- a/src/displayapp/screens/settings/SettingShakeThreshold.h +++ b/src/displayapp/screens/settings/SettingShakeThreshold.h @@ -8,6 +8,7 @@ namespace Pinetime::Controllers { class Settings; class MotionController; } + namespace Pinetime::System { class SystemTask; }