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"
|
|
|
|
|
2021-09-27 23:50:08 -04:00
|
|
|
|
2021-09-26 22:52:02 -04:00
|
|
|
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,
|
|
|
|
Controllers::MotionController& motionController,
|
|
|
|
System::SystemTask& systemTask)
|
|
|
|
: 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);
|
|
|
|
lv_label_set_text_static(title, "Shake Threshold");
|
|
|
|
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-27 23:50:08 -04:00
|
|
|
positionArc = lv_arc_create(lv_scr_act(), nullptr);
|
|
|
|
// Why do this?
|
|
|
|
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);
|
|
|
|
lv_arc_set_range(positionArc, 10, 4095);
|
|
|
|
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
|
|
|
|
lv_obj_set_size(positionArc, 240, 180);
|
|
|
|
lv_arc_set_adjustable(positionArc, false);
|
|
|
|
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);
|
|
|
|
calLabel = lv_label_create(calButton, NULL);
|
|
|
|
lv_label_set_text(calLabel, "Calibrate");
|
|
|
|
|
|
|
|
}
|
2021-09-26 22:52:02 -04:00
|
|
|
|
|
|
|
SettingShakeThreshold::~SettingShakeThreshold() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
settingsController.SaveSettings();
|
|
|
|
}
|
|
|
|
|
2021-09-27 23:50:08 -04:00
|
|
|
void SettingShakeThreshold::Refresh() {
|
|
|
|
|
|
|
|
taskCount++; //100ms Update time so finish @100
|
|
|
|
if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){
|
|
|
|
lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200);
|
|
|
|
}
|
|
|
|
if(taskCount >= 100){
|
|
|
|
lv_label_set_text(calLabel, "Calibrate");
|
|
|
|
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) {
|
|
|
|
case LV_EVENT_PRESSED: {
|
|
|
|
taskCount = 0;
|
|
|
|
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
|
|
|
|
lv_label_set_text(calLabel, "Shake!!!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LV_EVENT_VALUE_CHANGED: {
|
|
|
|
if (object == positionArc) {
|
|
|
|
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
2021-09-26 22:52:02 -04:00
|
|
|
}
|
2021-09-27 23:50:08 -04:00
|
|
|
break;
|
2021-09-26 22:52:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|