Skip to content

Commit b9c4010

Browse files
committed
Added visual aide for shake strength
Added delay to starting calibration
1 parent 8f38bd9 commit b9c4010

2 files changed

Lines changed: 60 additions & 37 deletions

File tree

src/displayapp/screens/settings/SettingShakeThreshold.cpp

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,78 +24,101 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
2424
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
2525
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
2626

27-
taskCount = 0;
28-
2927
positionArc = lv_arc_create(lv_scr_act(), nullptr);
30-
3128
positionArc->user_data = this;
3229

3330
lv_obj_set_event_cb(positionArc, event_handler);
34-
// lv_arc_set_start_angle(positionArc,270);
35-
lv_arc_set_angles(positionArc, 180, 360);
3631
lv_arc_set_bg_angles(positionArc, 180, 360);
37-
38-
// lv_arc_set_rotation(positionArc, 135);
3932
lv_arc_set_range(positionArc, 0, 4095);
40-
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
41-
lv_obj_set_size(positionArc, 240, 180);
4233
lv_arc_set_adjustable(positionArc, true);
43-
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
34+
lv_obj_set_width(positionArc, lv_obj_get_width(lv_scr_act()) - 10);
35+
lv_obj_set_height(positionArc, 240);
36+
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
37+
38+
animArc = lv_arc_create(positionArc, positionArc);
39+
lv_arc_set_adjustable(animArc, false);
40+
lv_obj_set_width(animArc, lv_obj_get_width(positionArc));
41+
lv_obj_set_height(animArc, lv_obj_get_height(positionArc));
42+
lv_obj_align_mid(animArc, positionArc, LV_ALIGN_CENTER, 0, 0);
43+
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0);
44+
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_60);
45+
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_KNOB, LV_STATE_DEFAULT, LV_OPA_0);
46+
lv_obj_set_style_local_line_color(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
47+
lv_obj_set_style_local_bg_color(animArc, LV_ARC_PART_BG, LV_STATE_CHECKED, LV_COLOR_TRANSP);
48+
animArc->user_data = this;
49+
lv_obj_set_click(animArc, false);
4450

4551
calButton = lv_btn_create(lv_scr_act(), nullptr);
4652
calButton->user_data = this;
4753
lv_obj_set_event_cb(calButton, event_handler);
48-
lv_btn_set_fit(calButton, LV_FIT_TIGHT);
49-
50-
// lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
5154
lv_obj_set_height(calButton, 80);
55+
lv_obj_set_width(calButton, 200);
5256
lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
5357
lv_btn_set_checkable(calButton, true);
5458
calLabel = lv_label_create(calButton, NULL);
5559
lv_label_set_text(calLabel, "Calibrate");
60+
61+
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
62+
63+
vDecay = xTaskGetTickCount();
64+
calibrating = false;
65+
66+
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
5667
}
5768

5869
SettingShakeThreshold::~SettingShakeThreshold() {
5970
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
60-
if (taskCount > 0) {
61-
lv_task_del(refreshTask);
62-
}
71+
72+
lv_task_del(refreshTask);
6373
settingsController.SaveSettings();
6474
lv_obj_clean(lv_scr_act());
6575
}
6676

6777
void SettingShakeThreshold::Refresh() {
6878

69-
taskCount++; // 100ms Per update
70-
if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) {
71-
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200);
79+
if (calibrating == 1) {
80+
if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(2000)) {
81+
vCalTime = xTaskGetTickCount();
82+
calibrating = 2;
83+
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_RELEASED, LV_COLOR_RED);
84+
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_PRESSED, LV_COLOR_RED);
85+
lv_label_set_text(calLabel, "Shake!!");
86+
}
87+
}
88+
if (calibrating == 2) {
89+
90+
if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) {
91+
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 300);
92+
}
93+
if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(7500)) {
94+
lv_btn_set_state(calButton, LV_STATE_DEFAULT);
95+
lv_event_send(calButton, LV_EVENT_VALUE_CHANGED, NULL);
96+
}
7297
}
73-
if (taskCount >= 75) {
74-
lv_btn_set_state(calButton,LV_STATE_DEFAULT);
75-
lv_event_send(calButton,LV_EVENT_VALUE_CHANGED,NULL);
76-
taskCount = 0;
77-
lv_task_del(refreshTask);
98+
if (motionController.currentShakeSpeed() - 300 > lv_arc_get_value(animArc)) {
99+
lv_arc_set_value(animArc, (uint16_t) motionController.currentShakeSpeed() - 300);
100+
vDecay = xTaskGetTickCount();
101+
} else if ((xTaskGetTickCount() - vDecay) > pdMS_TO_TICKS(1500)) {
102+
lv_arc_set_value(animArc, lv_arc_get_value(animArc) - 25);
78103
}
79104
}
80105

81106
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
82107

83108
switch (event) {
84109
case LV_EVENT_VALUE_CHANGED: {
85-
if (object == positionArc) {
86-
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
87-
break;
88-
}
89110
if (object == calButton) {
90-
if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED) {
91-
lv_arc_set_value(positionArc, 0);
92-
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
93-
lv_label_set_text(calLabel, "Shake!!!");
94111

112+
if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED && calibrating == 0) {
113+
lv_arc_set_value(positionArc, 0);
114+
calibrating = 1;
115+
vCalTime = xTaskGetTickCount();
116+
lv_label_set_text(calLabel, "Ready!");
117+
lv_obj_set_click(calButton,false);
95118
} else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) {
96119

97-
lv_task_del(refreshTask);
98-
taskCount = 0;
120+
calibrating = 0;
121+
lv_obj_set_click(calButton,true);
99122
lv_label_set_text(calLabel, "Calibrate");
100123
}
101124
break;

src/displayapp/screens/settings/SettingShakeThreshold.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ namespace Pinetime {
2525
Controllers::Settings& settingsController;
2626
Controllers::MotionController& motionController;
2727
System::SystemTask& systemTask;
28-
29-
uint8_t taskCount;
28+
uint8_t calibrating;
29+
uint32_t vDecay,vCalTime;
3030
lv_obj_t* cbOption[2];
31-
lv_obj_t *positionArc, *calButton, *calLabel;
31+
lv_obj_t *positionArc, *animArc,*calButton, *calLabel;
3232
lv_task_t* refreshTask;
3333
};
3434
}

0 commit comments

Comments
 (0)