2021-09-26 22:52:02 -04:00
|
|
|
#include "SettingShakeThreshold.h"
|
|
|
|
#include <lvgl/lvgl.h>
|
|
|
|
#include "displayapp/DisplayApp.h"
|
|
|
|
#include "displayapp/screens/Screen.h"
|
|
|
|
#include "displayapp/screens/Symbols.h"
|
|
|
|
|
|
|
|
using namespace Pinetime::Applications::Screens;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
static void event_handler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
SettingShakeThreshold* screen = static_cast<SettingShakeThreshold*>(obj->user_data);
|
|
|
|
screen->UpdateSelected(obj, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-27 23:50:08 -04:00
|
|
|
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
|
|
|
Controllers::Settings& settingsController,
|
2021-09-29 20:04:51 -04:00
|
|
|
Controllers::MotionController& motionController,
|
2021-09-27 23:50:08 -04:00
|
|
|
System::SystemTask& systemTask)
|
2021-09-29 20:04:51 -04:00
|
|
|
: Screen(app), settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} {
|
2021-09-26 22:52:02 -04:00
|
|
|
|
|
|
|
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
2021-09-28 00:21:47 -04:00
|
|
|
lv_label_set_text_static(title, "Wake Sensitivity");
|
2021-09-26 22:52:02 -04:00
|
|
|
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
2021-09-27 23:50:08 -04:00
|
|
|
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
|
2021-09-26 22:52:02 -04:00
|
|
|
|
2021-09-28 00:21:47 -04:00
|
|
|
taskCount = 0;
|
2021-09-26 22:52:02 -04:00
|
|
|
|
2021-09-27 23:50:08 -04:00
|
|
|
positionArc = lv_arc_create(lv_scr_act(), nullptr);
|
2021-09-29 20:04:51 -04:00
|
|
|
|
2021-09-27 23:50:08 -04:00
|
|
|
positionArc->user_data = this;
|
2021-09-26 22:52:02 -04:00
|
|
|
|
2021-09-27 23:50:08 -04:00
|
|
|
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_rotation(positionArc, 135);
|
2021-09-28 00:33:00 -04:00
|
|
|
lv_arc_set_range(positionArc, 0, 4095);
|
2021-09-27 23:50:08 -04:00
|
|
|
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
|
|
|
|
lv_obj_set_size(positionArc, 240, 180);
|
2021-09-28 00:33:00 -04:00
|
|
|
lv_arc_set_adjustable(positionArc, true);
|
2021-09-27 23:50:08 -04:00
|
|
|
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
|
|
|
|
|
|
|
calButton = lv_btn_create(lv_scr_act(), nullptr);
|
|
|
|
calButton->user_data = this;
|
|
|
|
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_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
2021-10-03 17:06:31 -04:00
|
|
|
lv_btn_set_checkable(calButton, true);
|
2021-09-27 23:50:08 -04:00
|
|
|
calLabel = lv_label_create(calButton, NULL);
|
|
|
|
lv_label_set_text(calLabel, "Calibrate");
|
2021-09-29 20:04:51 -04:00
|
|
|
}
|
2021-09-26 22:52:02 -04:00
|
|
|
|
|
|
|
SettingShakeThreshold::~SettingShakeThreshold() {
|
2021-09-28 00:21:47 -04:00
|
|
|
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
2021-09-29 20:04:51 -04:00
|
|
|
if (taskCount > 0) {
|
|
|
|
lv_task_del(refreshTask);
|
|
|
|
}
|
2021-09-26 22:52:02 -04:00
|
|
|
settingsController.SaveSettings();
|
2021-09-29 20:04:51 -04:00
|
|
|
lv_obj_clean(lv_scr_act());
|
2021-09-26 22:52:02 -04:00
|
|
|
}
|
|
|
|
|
2021-09-27 23:50:08 -04:00
|
|
|
void SettingShakeThreshold::Refresh() {
|
2021-09-29 20:04:51 -04:00
|
|
|
|
2021-10-03 17:06:31 -04:00
|
|
|
taskCount++; // 100ms Per update
|
|
|
|
if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) {
|
2021-09-29 20:04:51 -04:00
|
|
|
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200);
|
2021-09-27 23:50:08 -04:00
|
|
|
}
|
2021-10-03 17:06:31 -04:00
|
|
|
if (taskCount >= 75) {
|
|
|
|
lv_btn_set_state(calButton,LV_STATE_DEFAULT);
|
|
|
|
lv_event_send(calButton,LV_EVENT_VALUE_CHANGED,NULL);
|
2021-09-29 20:04:51 -04:00
|
|
|
taskCount = 0;
|
2021-09-27 23:50:08 -04:00
|
|
|
lv_task_del(refreshTask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-26 22:52:02 -04:00
|
|
|
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
2021-09-27 23:50:08 -04:00
|
|
|
|
|
|
|
switch (event) {
|
2021-10-03 17:06:31 -04:00
|
|
|
case LV_EVENT_VALUE_CHANGED: {
|
|
|
|
if (object == positionArc) {
|
|
|
|
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
|
|
|
break;
|
|
|
|
}
|
2021-09-28 00:33:00 -04:00
|
|
|
if (object == calButton) {
|
2021-10-03 17:06:31 -04:00
|
|
|
if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED) {
|
2021-09-29 20:04:51 -04:00
|
|
|
lv_arc_set_value(positionArc, 0);
|
|
|
|
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
2021-09-28 00:21:47 -04:00
|
|
|
lv_label_set_text(calLabel, "Shake!!!");
|
2021-10-03 17:06:31 -04:00
|
|
|
|
|
|
|
} else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) {
|
2021-09-29 20:04:51 -04:00
|
|
|
|
2021-09-28 00:21:47 -04:00
|
|
|
lv_task_del(refreshTask);
|
2021-09-29 20:04:51 -04:00
|
|
|
taskCount = 0;
|
2021-09-28 00:21:47 -04:00
|
|
|
lv_label_set_text(calLabel, "Calibrate");
|
|
|
|
}
|
2021-10-03 17:06:31 -04:00
|
|
|
break;
|
2021-09-28 00:33:00 -04:00
|
|
|
}
|
2021-09-26 22:52:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|