2
2
#include < lvgl/lvgl.h>
3
3
#include " displayapp/DisplayApp.h"
4
4
#include " displayapp/screens/Screen.h"
5
- #include " displayapp/screens/Symbols.h"
6
5
#include " displayapp/InfiniTimeTheme.h"
6
+ #include < components/motion/MotionController.h>
7
+ #include < components/settings/Settings.h>
8
+ #include " systemtask/SystemTask.h"
7
9
8
10
using namespace Pinetime ::Applications::Screens;
9
11
@@ -18,7 +20,6 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont
18
20
Controllers::MotionController& motionController,
19
21
System::SystemTask& systemTask)
20
22
: settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} {
21
-
22
23
lv_obj_t * title = lv_label_create (lv_scr_act (), nullptr );
23
24
lv_label_set_text_static (title, " Wake Sensitivity" );
24
25
lv_label_set_align (title, LV_LABEL_ALIGN_CENTER);
@@ -32,7 +33,7 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont
32
33
lv_label_set_text_static (
33
34
explanation,
34
35
" \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 ;
36
37
lv_obj_align (explanation, title, LV_ALIGN_OUT_BOTTOM_MID, 0 , 0 );
37
38
return ;
38
39
}
@@ -75,42 +76,36 @@ SettingShakeThreshold::SettingShakeThreshold(Controllers::Settings& settingsCont
75
76
lv_arc_set_value (positionArc, settingsController.GetShakeThreshold ());
76
77
77
78
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 );
84
82
refreshTask = lv_task_create (RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this );
85
83
}
86
84
87
85
SettingShakeThreshold::~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);
96
93
}
97
- lv_task_del (refreshTask);
98
- settingsController.SaveSettings ();
94
+
99
95
lv_obj_clean (lv_scr_act ());
100
96
}
101
97
102
98
void SettingShakeThreshold::Refresh () {
103
-
104
- if (calibrating == 1 ) {
99
+ if (currentCalibrationStep == CalibrationStep::GettingReady) {
105
100
if (xTaskGetTickCount () - vCalTime > pdMS_TO_TICKS (2000 )) {
106
101
vCalTime = xTaskGetTickCount ();
107
- calibrating = 2 ;
102
+ currentCalibrationStep = CalibrationStep::Calibrating ;
108
103
lv_obj_set_style_local_bg_color (calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED);
109
104
lv_obj_set_style_local_bg_color (calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED);
110
105
lv_label_set_text_static (calLabel, " Shake!" );
111
106
}
112
107
}
113
- if (calibrating == 2 ) {
108
+ if (currentCalibrationStep == CalibrationStep::Calibrating ) {
114
109
115
110
if ((motionController.CurrentShakeSpeed () - 300 ) > lv_arc_get_value (positionArc)) {
116
111
lv_arc_set_value (positionArc, (int16_t ) motionController.CurrentShakeSpeed () - 300 );
@@ -129,19 +124,19 @@ void SettingShakeThreshold::Refresh() {
129
124
}
130
125
131
126
void SettingShakeThreshold::UpdateSelected (lv_obj_t * object, lv_event_t event) {
132
-
133
127
switch (event) {
134
128
case LV_EVENT_VALUE_CHANGED: {
135
129
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) {
137
132
lv_arc_set_value (positionArc, 0 );
138
- calibrating = 1 ;
133
+ currentCalibrationStep = CalibrationStep::GettingReady ;
139
134
vCalTime = xTaskGetTickCount ();
140
135
lv_label_set_text_static (calLabel, " Ready!" );
141
136
lv_obj_set_click (positionArc, false );
142
137
lv_obj_set_style_local_bg_color (calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, Colors::highlight);
143
138
} else if (lv_btn_get_state (calButton) == LV_BTN_STATE_RELEASED) {
144
- calibrating = 0 ;
139
+ currentCalibrationStep = CalibrationStep::NotCalibrated ;
145
140
lv_obj_set_click (positionArc, true );
146
141
lv_label_set_text_static (calLabel, " Calibrate" );
147
142
}
0 commit comments