22#include < lvgl/lvgl.h>
33#include " displayapp/DisplayApp.h"
44#include " displayapp/screens/Screen.h"
5- #include " displayapp/screens/Symbols.h"
65#include " displayapp/InfiniTimeTheme.h"
6+ #include < components/motion/MotionController.h>
7+ #include < components/settings/Settings.h>
8+ #include " systemtask/SystemTask.h"
79
810using namespace Pinetime ::Applications::Screens;
911
@@ -18,7 +20,6 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont
1820 Controllers::MotionController& motionController,
1921 System::SystemTask& systemTask)
2022 : settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} {
21-
2223 lv_obj_t * title = lv_label_create (lv_scr_act (), nullptr );
2324 lv_label_set_text_static (title, " Wake Sensitivity" );
2425 lv_label_set_align (title, LV_LABEL_ALIGN_CENTER);
@@ -32,7 +33,7 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont
3233 lv_label_set_text_static (
3334 explanation,
3435 " \n Shake detector is disabled in sleep mode, and will neither wake up the watch nor calibrate.\n Disable sleep mode to calibrate." );
35- calibrating = 255 ;
36+ currentCalibrationStep = CalibrationStep::Disabled ;
3637 lv_obj_align (explanation, title, LV_ALIGN_OUT_BOTTOM_MID, 0 , 0 );
3738 return ;
3839 }
@@ -75,42 +76,36 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont
7576 lv_arc_set_value (positionArc, settingsController.GetShakeThreshold ());
7677
7778 vDecay = xTaskGetTickCount ();
78- calibrating = false ;
79- EnableForCal = false ;
80- if (!settingsController.isWakeUpModeOn (Pinetime::Controllers::Settings::WakeUpMode::Shake)) {
81- EnableForCal = true ;
82- settingsController.setWakeUpMode (Pinetime::Controllers::Settings::WakeUpMode::Shake, true );
83- }
79+ oldWakeupModeShake = settingsController.isWakeUpModeOn (Pinetime::Controllers::Settings::WakeUpMode::Shake);
80+ // Enable shake to wake for the calibration
81+ settingsController.setWakeUpMode (Pinetime::Controllers::Settings::WakeUpMode::Shake, true );
8482 refreshTask = lv_task_create (RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this );
8583}
8684
8785SettingShakeThreshold::~SettingShakeThreshold () {
88- if (calibrating == 255 )
89- return ;
90-
91- settingsController.SetShakeThreshold (lv_arc_get_value (positionArc));
92-
93- if (EnableForCal) {
94- settingsController.setWakeUpMode (Pinetime::Controllers::Settings::WakeUpMode::Shake, false );
95- EnableForCal = false ;
86+ if (currentCalibrationStep != CalibrationStep::Disabled) {
87+ // Don't set new threshold if calibration is disabled due to sleep mode
88+ settingsController.SetShakeThreshold (lv_arc_get_value (positionArc));
89+ // Restore previous wakeup mode which is only changed if calibration is not disabled due to sleep mode
90+ settingsController.setWakeUpMode (Pinetime::Controllers::Settings::WakeUpMode::Shake, oldWakeupModeShake);
91+ settingsController.SaveSettings ();
92+ lv_task_del (refreshTask);
9693 }
97- lv_task_del (refreshTask);
98- settingsController.SaveSettings ();
94+
9995 lv_obj_clean (lv_scr_act ());
10096}
10197
10298void SettingShakeThreshold::Refresh () {
103-
104- if (calibrating == 1 ) {
99+ if (currentCalibrationStep == CalibrationStep::GettingReady) {
105100 if (xTaskGetTickCount () - vCalTime > pdMS_TO_TICKS (2000 )) {
106101 vCalTime = xTaskGetTickCount ();
107- calibrating = 2 ;
102+ currentCalibrationStep = CalibrationStep::Calibrating ;
108103 lv_obj_set_style_local_bg_color (calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED);
109104 lv_obj_set_style_local_bg_color (calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED);
110105 lv_label_set_text_static (calLabel, " Shake!" );
111106 }
112107 }
113- if (calibrating == 2 ) {
108+ if (currentCalibrationStep == CalibrationStep::Calibrating ) {
114109
115110 if ((motionController.CurrentShakeSpeed () - 300 ) > lv_arc_get_value (positionArc)) {
116111 lv_arc_set_value (positionArc, (int16_t ) motionController.CurrentShakeSpeed () - 300 );
@@ -129,19 +124,19 @@ void SettingShakeThreshold::Refresh() {
129124}
130125
131126void SettingShakeThreshold::UpdateSelected (lv_obj_t * object, lv_event_t event) {
132-
133127 switch (event) {
134128 case LV_EVENT_VALUE_CHANGED: {
135129 if (object == calButton) {
136- if (lv_btn_get_state (calButton) == LV_BTN_STATE_CHECKED_RELEASED && calibrating == 0 ) {
130+ if (lv_btn_get_state (calButton) == LV_BTN_STATE_CHECKED_RELEASED
131+ && currentCalibrationStep == CalibrationStep::NotCalibrated) {
137132 lv_arc_set_value (positionArc, 0 );
138- calibrating = 1 ;
133+ currentCalibrationStep = CalibrationStep::GettingReady ;
139134 vCalTime = xTaskGetTickCount ();
140135 lv_label_set_text_static (calLabel, " Ready!" );
141136 lv_obj_set_click (positionArc, false );
142137 lv_obj_set_style_local_bg_color (calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, Colors::highlight);
143138 } else if (lv_btn_get_state (calButton) == LV_BTN_STATE_RELEASED) {
144- calibrating = 0 ;
139+ currentCalibrationStep = CalibrationStep::NotCalibrated ;
145140 lv_obj_set_click (positionArc, true );
146141 lv_label_set_text_static (calLabel, " Calibrate" );
147142 }
0 commit comments