Fix crash upon leaving app.

Code formatting
This commit is contained in:
Tim Keller 2021-09-30 00:04:51 +00:00
parent d6b22645e3
commit 5c13200238
3 changed files with 28 additions and 34 deletions

View file

@ -48,20 +48,21 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
bool wake = false;
auto diff = xTaskGetTickCount() - lastShakeTime;
lastShakeTime = xTaskGetTickCount();
int32_t speed = std::abs(z + (y/2) + (x/4)- lastYForShake - lastZForShake) / diff * 100;
/* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100;
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
//implemented without floats as .25Alpha
accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4);
// implemented without floats as .25Alpha
accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4);
if (accumulatedspeed > thresh) {
wake = true;
}
lastXForShake = x/4;
lastYForShake = y/2;
lastXForShake = x / 4;
lastYForShake = y / 2;
lastZForShake = z;
return wake;
}
int32_t MotionController::currentShakeSpeed(){
int32_t MotionController::currentShakeSpeed() {
return accumulatedspeed;
}

View file

@ -4,7 +4,6 @@
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"
using namespace Pinetime::Applications::Screens;
namespace {
@ -18,10 +17,7 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
Controllers::Settings& settingsController,
Controllers::MotionController& motionController,
System::SystemTask& systemTask)
: Screen(app),
settingsController {settingsController},
motionController {motionController},
systemTask {systemTask} {
: Screen(app), settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} {
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Wake Sensitivity");
@ -56,28 +52,28 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
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");
}
}
SettingShakeThreshold::~SettingShakeThreshold() {
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
lv_task_del(refreshTask);
lv_obj_clean(lv_scr_act());
if (taskCount > 0) {
lv_task_del(refreshTask);
}
settingsController.SaveSettings();
lv_obj_clean(lv_scr_act());
}
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);
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 >= 50){
if (taskCount >= 50) {
lv_label_set_text(calLabel, "Calibrate");
taskCount=0;
taskCount = 0;
lv_task_del(refreshTask);
}
}
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
@ -85,14 +81,14 @@ void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
switch (event) {
case LV_EVENT_PRESSED: {
if (object == calButton) {
if(taskCount == 0){
lv_arc_set_value(positionArc,0);
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
if (taskCount == 0) {
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!!!");
}else{
} else {
lv_task_del(refreshTask);
taskCount=0;
taskCount = 0;
lv_label_set_text(calLabel, "Calibrate");
}
}

View file

@ -26,9 +26,6 @@ namespace Pinetime {
Controllers::MotionController& motionController;
System::SystemTask& systemTask;
uint8_t taskCount;
lv_obj_t* cbOption[2];
lv_obj_t *positionArc, *calButton, *calLabel;