Actually save the threshold

Prevent a few crashes due to an LV task being active when it shouldnt be.
This commit is contained in:
Tim Keller 2021-09-28 04:21:47 +00:00
parent d2510d7926
commit f780ac999a
3 changed files with 23 additions and 8 deletions

View file

@ -115,7 +115,11 @@ namespace Pinetime {
};
void SetShakeThreshold(uint16_t thresh){
if(settings.shakeWakeThreshold != thresh){
settings.shakeWakeThreshold = thresh;
settingsChanged = true;
}
}
int16_t GetShakeThreshold() const{

View file

@ -24,13 +24,14 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
systemTask {systemTask} {
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Shake Threshold");
lv_label_set_text_static(title, "Wake Sensitivity");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
taskCount = 0;
positionArc = lv_arc_create(lv_scr_act(), nullptr);
// Why do this?
positionArc->user_data = this;
lv_obj_set_event_cb(positionArc, event_handler);
@ -59,6 +60,8 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
}
SettingShakeThreshold::~SettingShakeThreshold() {
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
lv_task_del(refreshTask);
lv_obj_clean(lv_scr_act());
settingsController.SaveSettings();
}
@ -69,8 +72,9 @@ void SettingShakeThreshold::Refresh() {
if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){
lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200);
}
if(taskCount >= 100){
if(taskCount >= 50){
lv_label_set_text(calLabel, "Calibrate");
taskCount=0;
lv_task_del(refreshTask);
}
@ -80,11 +84,18 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
switch (event) {
case LV_EVENT_PRESSED: {
taskCount = 0;
if(taskCount == 0){
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
lv_label_set_text(calLabel, "Shake!!!");
}else{
lv_task_del(refreshTask);
taskCount=0;
lv_label_set_text(calLabel, "Calibrate");
}
break;
}
case LV_EVENT_VALUE_CHANGED: {
if (object == positionArc) {
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));

View file

@ -66,7 +66,7 @@ std::unique_ptr<Screen> Settings::CreateScreen3() {
{Symbols::none, "None", Apps::None}
}};
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) {
applications[1] = {Symbols::list, "Shake Threshold", Apps::SettingShakeThreshold};
applications[1] = {Symbols::list, "Wake Sense", Apps::SettingShakeThreshold};
}
return std::make_unique<Screens::List>(2, 3, app, settingsController, applications);
}