Fix crash upon leaving app.
Code formatting
This commit is contained in:
parent
d6b22645e3
commit
5c13200238
|
@ -48,20 +48,21 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
|
||||||
bool wake = false;
|
bool wake = false;
|
||||||
auto diff = xTaskGetTickCount() - lastShakeTime;
|
auto diff = xTaskGetTickCount() - lastShakeTime;
|
||||||
lastShakeTime = xTaskGetTickCount();
|
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);
|
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
|
||||||
//implemented without floats as .25Alpha
|
// implemented without floats as .25Alpha
|
||||||
accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4);
|
accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4);
|
||||||
|
|
||||||
if (accumulatedspeed > thresh) {
|
if (accumulatedspeed > thresh) {
|
||||||
wake = true;
|
wake = true;
|
||||||
}
|
}
|
||||||
lastXForShake = x/4;
|
lastXForShake = x / 4;
|
||||||
lastYForShake = y/2;
|
lastYForShake = y / 2;
|
||||||
lastZForShake = z;
|
lastZForShake = z;
|
||||||
return wake;
|
return wake;
|
||||||
}
|
}
|
||||||
int32_t MotionController::currentShakeSpeed(){
|
int32_t MotionController::currentShakeSpeed() {
|
||||||
return accumulatedspeed;
|
return accumulatedspeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "displayapp/screens/Symbols.h"
|
#include "displayapp/screens/Symbols.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -16,12 +15,9 @@ namespace {
|
||||||
|
|
||||||
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
||||||
Controllers::Settings& settingsController,
|
Controllers::Settings& settingsController,
|
||||||
Controllers::MotionController& motionController,
|
Controllers::MotionController& motionController,
|
||||||
System::SystemTask& systemTask)
|
System::SystemTask& systemTask)
|
||||||
: Screen(app),
|
: Screen(app), settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} {
|
||||||
settingsController {settingsController},
|
|
||||||
motionController {motionController},
|
|
||||||
systemTask {systemTask} {
|
|
||||||
|
|
||||||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
||||||
lv_label_set_text_static(title, "Wake Sensitivity");
|
lv_label_set_text_static(title, "Wake Sensitivity");
|
||||||
|
@ -31,7 +27,7 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
||||||
taskCount = 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);
|
||||||
|
@ -56,28 +52,28 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
||||||
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);
|
||||||
calLabel = lv_label_create(calButton, NULL);
|
calLabel = lv_label_create(calButton, NULL);
|
||||||
lv_label_set_text(calLabel, "Calibrate");
|
lv_label_set_text(calLabel, "Calibrate");
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SettingShakeThreshold::~SettingShakeThreshold() {
|
SettingShakeThreshold::~SettingShakeThreshold() {
|
||||||
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
||||||
lv_task_del(refreshTask);
|
if (taskCount > 0) {
|
||||||
lv_obj_clean(lv_scr_act());
|
lv_task_del(refreshTask);
|
||||||
|
}
|
||||||
settingsController.SaveSettings();
|
settingsController.SaveSettings();
|
||||||
|
lv_obj_clean(lv_scr_act());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingShakeThreshold::Refresh() {
|
void SettingShakeThreshold::Refresh() {
|
||||||
|
|
||||||
taskCount++; //100ms Update time so finish @100
|
taskCount++; // 100ms Update time so finish @100
|
||||||
if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){
|
if ((motionController.currentShakeSpeed() - 200) > lv_arc_get_value(positionArc)) {
|
||||||
lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200);
|
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200);
|
||||||
}
|
}
|
||||||
if(taskCount >= 50){
|
if (taskCount >= 50) {
|
||||||
lv_label_set_text(calLabel, "Calibrate");
|
lv_label_set_text(calLabel, "Calibrate");
|
||||||
taskCount=0;
|
taskCount = 0;
|
||||||
lv_task_del(refreshTask);
|
lv_task_del(refreshTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
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) {
|
switch (event) {
|
||||||
case LV_EVENT_PRESSED: {
|
case LV_EVENT_PRESSED: {
|
||||||
if (object == calButton) {
|
if (object == calButton) {
|
||||||
if(taskCount == 0){
|
if (taskCount == 0) {
|
||||||
lv_arc_set_value(positionArc,0);
|
lv_arc_set_value(positionArc, 0);
|
||||||
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
|
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
||||||
lv_label_set_text(calLabel, "Shake!!!");
|
lv_label_set_text(calLabel, "Shake!!!");
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
lv_task_del(refreshTask);
|
lv_task_del(refreshTask);
|
||||||
taskCount=0;
|
taskCount = 0;
|
||||||
lv_label_set_text(calLabel, "Calibrate");
|
lv_label_set_text(calLabel, "Calibrate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,6 @@ namespace Pinetime {
|
||||||
Controllers::MotionController& motionController;
|
Controllers::MotionController& motionController;
|
||||||
System::SystemTask& systemTask;
|
System::SystemTask& systemTask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t taskCount;
|
uint8_t taskCount;
|
||||||
lv_obj_t* cbOption[2];
|
lv_obj_t* cbOption[2];
|
||||||
lv_obj_t *positionArc, *calButton, *calLabel;
|
lv_obj_t *positionArc, *calButton, *calLabel;
|
||||||
|
|
Loading…
Reference in a new issue