@@ -50,6 +50,7 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
5050 // lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
5151 lv_obj_set_height (calButton, 80 );
5252 lv_obj_align (calButton, lv_scr_act (), LV_ALIGN_IN_BOTTOM_MID, 0 , 0 );
53+ lv_btn_set_checkable (calButton, true );
5354 calLabel = lv_label_create (calButton, NULL );
5455 lv_label_set_text (calLabel, " Calibrate" );
5556}
@@ -65,12 +66,13 @@ SettingShakeThreshold::~SettingShakeThreshold() {
6566
6667void SettingShakeThreshold::Refresh () {
6768
68- taskCount++; // 100ms Update time so finish @100
69- if ((motionController.currentShakeSpeed () - 200 ) > lv_arc_get_value (positionArc)) {
69+ taskCount++; // 100ms Per update
70+ if ((motionController.currentShakeSpeed () - 300 ) > lv_arc_get_value (positionArc)) {
7071 lv_arc_set_value (positionArc, (int16_t ) motionController.currentShakeSpeed () - 200 );
7172 }
72- if (taskCount >= 50 ) {
73- lv_label_set_text (calLabel, " Calibrate" );
73+ if (taskCount >= 75 ) {
74+ lv_btn_set_state (calButton,LV_STATE_DEFAULT);
75+ lv_event_send (calButton,LV_EVENT_VALUE_CHANGED,NULL );
7476 taskCount = 0 ;
7577 lv_task_del (refreshTask);
7678 }
@@ -79,27 +81,25 @@ void SettingShakeThreshold::Refresh() {
7981void SettingShakeThreshold::UpdateSelected (lv_obj_t * object, lv_event_t event) {
8082
8183 switch (event) {
82- case LV_EVENT_PRESSED: {
84+ case LV_EVENT_VALUE_CHANGED: {
85+ if (object == positionArc) {
86+ settingsController.SetShakeThreshold (lv_arc_get_value (positionArc));
87+ break ;
88+ }
8389 if (object == calButton) {
84- if (taskCount == 0 ) {
90+ if (lv_btn_get_state (calButton) == LV_BTN_STATE_CHECKED_RELEASED ) {
8591 lv_arc_set_value (positionArc, 0 );
8692 refreshTask = lv_task_create (RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this );
8793 lv_label_set_text (calLabel, " Shake!!!" );
88- } else {
94+
95+ } else if (lv_btn_get_state (calButton) == LV_BTN_STATE_RELEASED) {
8996
9097 lv_task_del (refreshTask);
9198 taskCount = 0 ;
9299 lv_label_set_text (calLabel, " Calibrate" );
93100 }
101+ break ;
94102 }
95- break ;
96- }
97-
98- case LV_EVENT_VALUE_CHANGED: {
99- if (object == positionArc) {
100- settingsController.SetShakeThreshold (lv_arc_get_value (positionArc));
101- }
102- break ;
103103 }
104104 }
105105}
0 commit comments