Added visual aide for shake strength
Added delay to starting calibration
This commit is contained in:
parent
8f38bd911b
commit
b9c40100f6
2 changed files with 60 additions and 37 deletions
|
@ -24,57 +24,82 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
||||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
|
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
|
||||||
|
|
||||||
taskCount = 0;
|
|
||||||
|
|
||||||
positionArc = lv_arc_create(lv_scr_act(), nullptr);
|
positionArc = lv_arc_create(lv_scr_act(), nullptr);
|
||||||
|
|
||||||
positionArc->user_data = this;
|
positionArc->user_data = this;
|
||||||
|
|
||||||
lv_obj_set_event_cb(positionArc, event_handler);
|
lv_obj_set_event_cb(positionArc, event_handler);
|
||||||
// lv_arc_set_start_angle(positionArc,270);
|
|
||||||
lv_arc_set_angles(positionArc, 180, 360);
|
|
||||||
lv_arc_set_bg_angles(positionArc, 180, 360);
|
lv_arc_set_bg_angles(positionArc, 180, 360);
|
||||||
|
|
||||||
// lv_arc_set_rotation(positionArc, 135);
|
|
||||||
lv_arc_set_range(positionArc, 0, 4095);
|
lv_arc_set_range(positionArc, 0, 4095);
|
||||||
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
|
|
||||||
lv_obj_set_size(positionArc, 240, 180);
|
|
||||||
lv_arc_set_adjustable(positionArc, true);
|
lv_arc_set_adjustable(positionArc, true);
|
||||||
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
lv_obj_set_width(positionArc, lv_obj_get_width(lv_scr_act()) - 10);
|
||||||
|
lv_obj_set_height(positionArc, 240);
|
||||||
|
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||||
|
|
||||||
|
animArc = lv_arc_create(positionArc, positionArc);
|
||||||
|
lv_arc_set_adjustable(animArc, false);
|
||||||
|
lv_obj_set_width(animArc, lv_obj_get_width(positionArc));
|
||||||
|
lv_obj_set_height(animArc, lv_obj_get_height(positionArc));
|
||||||
|
lv_obj_align_mid(animArc, positionArc, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0);
|
||||||
|
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_60);
|
||||||
|
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_KNOB, LV_STATE_DEFAULT, LV_OPA_0);
|
||||||
|
lv_obj_set_style_local_line_color(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
|
||||||
|
lv_obj_set_style_local_bg_color(animArc, LV_ARC_PART_BG, LV_STATE_CHECKED, LV_COLOR_TRANSP);
|
||||||
|
animArc->user_data = this;
|
||||||
|
lv_obj_set_click(animArc, false);
|
||||||
|
|
||||||
calButton = lv_btn_create(lv_scr_act(), nullptr);
|
calButton = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
calButton->user_data = this;
|
calButton->user_data = this;
|
||||||
lv_obj_set_event_cb(calButton, event_handler);
|
lv_obj_set_event_cb(calButton, event_handler);
|
||||||
lv_btn_set_fit(calButton, LV_FIT_TIGHT);
|
|
||||||
|
|
||||||
// lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
|
||||||
lv_obj_set_height(calButton, 80);
|
lv_obj_set_height(calButton, 80);
|
||||||
|
lv_obj_set_width(calButton, 200);
|
||||||
lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||||
lv_btn_set_checkable(calButton, true);
|
lv_btn_set_checkable(calButton, true);
|
||||||
calLabel = lv_label_create(calButton, NULL);
|
calLabel = lv_label_create(calButton, NULL);
|
||||||
lv_label_set_text(calLabel, "Calibrate");
|
lv_label_set_text(calLabel, "Calibrate");
|
||||||
|
|
||||||
|
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
|
||||||
|
|
||||||
|
vDecay = xTaskGetTickCount();
|
||||||
|
calibrating = false;
|
||||||
|
|
||||||
|
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingShakeThreshold::~SettingShakeThreshold() {
|
SettingShakeThreshold::~SettingShakeThreshold() {
|
||||||
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
||||||
if (taskCount > 0) {
|
|
||||||
lv_task_del(refreshTask);
|
lv_task_del(refreshTask);
|
||||||
}
|
|
||||||
settingsController.SaveSettings();
|
settingsController.SaveSettings();
|
||||||
lv_obj_clean(lv_scr_act());
|
lv_obj_clean(lv_scr_act());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingShakeThreshold::Refresh() {
|
void SettingShakeThreshold::Refresh() {
|
||||||
|
|
||||||
taskCount++; // 100ms Per update
|
if (calibrating == 1) {
|
||||||
if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) {
|
if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(2000)) {
|
||||||
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200);
|
vCalTime = xTaskGetTickCount();
|
||||||
|
calibrating = 2;
|
||||||
|
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_RELEASED, LV_COLOR_RED);
|
||||||
|
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_BTN_STATE_CHECKED_PRESSED, LV_COLOR_RED);
|
||||||
|
lv_label_set_text(calLabel, "Shake!!");
|
||||||
}
|
}
|
||||||
if (taskCount >= 75) {
|
}
|
||||||
lv_btn_set_state(calButton,LV_STATE_DEFAULT);
|
if (calibrating == 2) {
|
||||||
lv_event_send(calButton,LV_EVENT_VALUE_CHANGED,NULL);
|
|
||||||
taskCount = 0;
|
if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) {
|
||||||
lv_task_del(refreshTask);
|
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 300);
|
||||||
|
}
|
||||||
|
if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(7500)) {
|
||||||
|
lv_btn_set_state(calButton, LV_STATE_DEFAULT);
|
||||||
|
lv_event_send(calButton, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (motionController.currentShakeSpeed() - 300 > lv_arc_get_value(animArc)) {
|
||||||
|
lv_arc_set_value(animArc, (uint16_t) motionController.currentShakeSpeed() - 300);
|
||||||
|
vDecay = xTaskGetTickCount();
|
||||||
|
} else if ((xTaskGetTickCount() - vDecay) > pdMS_TO_TICKS(1500)) {
|
||||||
|
lv_arc_set_value(animArc, lv_arc_get_value(animArc) - 25);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,20 +107,18 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case LV_EVENT_VALUE_CHANGED: {
|
case LV_EVENT_VALUE_CHANGED: {
|
||||||
if (object == positionArc) {
|
|
||||||
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (object == calButton) {
|
if (object == calButton) {
|
||||||
if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED) {
|
|
||||||
lv_arc_set_value(positionArc, 0);
|
|
||||||
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
|
||||||
lv_label_set_text(calLabel, "Shake!!!");
|
|
||||||
|
|
||||||
|
if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED && calibrating == 0) {
|
||||||
|
lv_arc_set_value(positionArc, 0);
|
||||||
|
calibrating = 1;
|
||||||
|
vCalTime = xTaskGetTickCount();
|
||||||
|
lv_label_set_text(calLabel, "Ready!");
|
||||||
|
lv_obj_set_click(calButton,false);
|
||||||
} else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) {
|
} else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) {
|
||||||
|
|
||||||
lv_task_del(refreshTask);
|
calibrating = 0;
|
||||||
taskCount = 0;
|
lv_obj_set_click(calButton,true);
|
||||||
lv_label_set_text(calLabel, "Calibrate");
|
lv_label_set_text(calLabel, "Calibrate");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -25,10 +25,10 @@ namespace Pinetime {
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
Controllers::MotionController& motionController;
|
Controllers::MotionController& motionController;
|
||||||
System::SystemTask& systemTask;
|
System::SystemTask& systemTask;
|
||||||
|
uint8_t calibrating;
|
||||||
uint8_t taskCount;
|
uint32_t vDecay,vCalTime;
|
||||||
lv_obj_t* cbOption[2];
|
lv_obj_t* cbOption[2];
|
||||||
lv_obj_t *positionArc, *calButton, *calLabel;
|
lv_obj_t *positionArc, *animArc,*calButton, *calLabel;
|
||||||
lv_task_t* refreshTask;
|
lv_task_t* refreshTask;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue