44#include " displayapp/screens/Screen.h"
55#include " displayapp/screens/Symbols.h"
66
7+
78using namespace Pinetime ::Applications::Screens;
89
910namespace {
@@ -13,77 +14,82 @@ namespace {
1314 }
1415}
1516
16- SettingShakeThreshold::SettingShakeThreshold (Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
17- : Screen(app), settingsController {settingsController} {
18-
19- lv_obj_t * container1 = lv_cont_create (lv_scr_act (), nullptr );
20-
21- // lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
22- lv_obj_set_style_local_bg_opa (container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
23- lv_obj_set_style_local_pad_all (container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10 );
24- lv_obj_set_style_local_pad_inner (container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5 );
25- lv_obj_set_style_local_border_width (container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0 );
26-
27- lv_obj_set_pos (container1, 10 , 60 );
28- lv_obj_set_width (container1, LV_HOR_RES - 20 );
29- lv_obj_set_height (container1, LV_VER_RES - 50 );
30- lv_cont_set_layout (container1, LV_LAYOUT_COLUMN_LEFT);
17+ SettingShakeThreshold::SettingShakeThreshold (DisplayApp* app,
18+ Controllers::Settings& settingsController,
19+ Controllers::MotionController& motionController,
20+ System::SystemTask& systemTask)
21+ : Screen(app),
22+ settingsController {settingsController},
23+ motionController {motionController},
24+ systemTask {systemTask} {
3125
3226 lv_obj_t * title = lv_label_create (lv_scr_act (), nullptr );
3327 lv_label_set_text_static (title, " Shake Threshold" );
3428 lv_label_set_align (title, LV_LABEL_ALIGN_CENTER);
35- lv_obj_align (title, lv_scr_act (), LV_ALIGN_IN_TOP_MID, 10 , 15 );
36-
37- lv_obj_t * icon = lv_label_create (lv_scr_act (), nullptr );
38- lv_obj_set_style_local_text_color (icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
39- lv_label_set_text_static (icon, Symbols::home);
40- lv_label_set_align (icon, LV_LABEL_ALIGN_CENTER);
41- lv_obj_align (icon, title, LV_ALIGN_OUT_LEFT_MID, -10 , 0 );
42-
43- optionsTotal = 0 ;
44- cbOption[optionsTotal] = lv_checkbox_create (container1, nullptr );
45- lv_checkbox_set_text_static (cbOption[optionsTotal], " High" );
46- cbOption[optionsTotal]->user_data = this ;
47- lv_obj_set_event_cb (cbOption[optionsTotal], event_handler);
48- if (settingsController.GetShakeThreshold () == 150 ) {
49- lv_checkbox_set_checked (cbOption[optionsTotal], true );
50- }
29+ lv_obj_align (title, lv_scr_act (), LV_ALIGN_IN_TOP_MID, 0 , 0 );
5130
52- optionsTotal++;
53- cbOption[optionsTotal] = lv_checkbox_create (container1, nullptr );
54- lv_checkbox_set_text_static (cbOption[optionsTotal], " Medium" );
55- cbOption[optionsTotal]->user_data = this ;
56- lv_obj_set_event_cb (cbOption[optionsTotal], event_handler);
57- if (settingsController.GetShakeThreshold () == 300 ) {
58- lv_checkbox_set_checked (cbOption[optionsTotal], true );
59- }
6031
61- optionsTotal++;
62- cbOption[optionsTotal] = lv_checkbox_create (container1, nullptr );
63- lv_checkbox_set_text_static (cbOption[optionsTotal], " Low" );
64- cbOption[optionsTotal]->user_data = this ;
65- lv_obj_set_event_cb (cbOption[optionsTotal], event_handler);
66- if (settingsController.GetShakeThreshold () == 450 ) {
67- lv_checkbox_set_checked (cbOption[optionsTotal], true );
68- }
32+ positionArc = lv_arc_create (lv_scr_act (), nullptr );
33+ // Why do this?
34+ positionArc->user_data = this ;
6935
70- optionsTotal++;
71- }
36+ lv_obj_set_event_cb (positionArc, event_handler);
37+ // lv_arc_set_start_angle(positionArc,270);
38+ lv_arc_set_angles (positionArc, 180 , 360 );
39+ lv_arc_set_bg_angles (positionArc, 180 , 360 );
40+
41+ // lv_arc_set_rotation(positionArc, 135);
42+ lv_arc_set_range (positionArc, 10 , 4095 );
43+ lv_arc_set_value (positionArc, settingsController.GetShakeThreshold ());
44+ lv_obj_set_size (positionArc, 240 , 180 );
45+ lv_arc_set_adjustable (positionArc, false );
46+ lv_obj_align (positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0 , 10 );
47+
48+ calButton = lv_btn_create (lv_scr_act (), nullptr );
49+ calButton->user_data = this ;
50+ lv_obj_set_event_cb (calButton, event_handler);
51+ lv_btn_set_fit (calButton, LV_FIT_TIGHT);
52+
53+ // lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
54+ lv_obj_set_height (calButton, 80 );
55+ lv_obj_align (calButton, lv_scr_act (), LV_ALIGN_IN_BOTTOM_MID, 0 , 0 );
56+ calLabel = lv_label_create (calButton, NULL );
57+ lv_label_set_text (calLabel, " Calibrate" );
58+
59+ }
7260
7361SettingShakeThreshold::~SettingShakeThreshold () {
7462 lv_obj_clean (lv_scr_act ());
7563 settingsController.SaveSettings ();
7664}
7765
66+ void SettingShakeThreshold::Refresh () {
67+
68+ taskCount++; // 100ms Update time so finish @100
69+ if ((motionController.currentShakeSpeed ()-200 ) > lv_arc_get_value (positionArc)){
70+ lv_arc_set_value (positionArc,(int16_t )motionController.currentShakeSpeed ()-200 );
71+ }
72+ if (taskCount >= 100 ){
73+ lv_label_set_text (calLabel, " Calibrate" );
74+ lv_task_del (refreshTask);
75+ }
76+
77+ }
78+
7879void SettingShakeThreshold::UpdateSelected (lv_obj_t * object, lv_event_t event) {
79- if (event == LV_EVENT_VALUE_CHANGED) {
80- for (uint8_t i = 0 ; i < optionsTotal; i++) {
81- if (object == cbOption[i]) {
82- lv_checkbox_set_checked (cbOption[i], true );
83- settingsController.SetShakeThreshold ((i+1 )*150 );
84- } else {
85- lv_checkbox_set_checked (cbOption[i], false );
80+
81+ switch (event) {
82+ case LV_EVENT_PRESSED: {
83+ taskCount = 0 ;
84+ refreshTask = lv_task_create (RefreshTaskCallback, 100 , LV_TASK_PRIO_MID, this );
85+ lv_label_set_text (calLabel, " Shake!!!" );
86+ break ;
87+ }
88+ case LV_EVENT_VALUE_CHANGED: {
89+ if (object == positionArc) {
90+ settingsController.SetShakeThreshold (lv_arc_get_value (positionArc));
8691 }
92+ break ;
8793 }
8894 }
8995}
0 commit comments