Skip to content

Commit 5c13200

Browse files
committed
Fix crash upon leaving app.
Code formatting
1 parent d6b2264 commit 5c13200

3 files changed

Lines changed: 28 additions & 34 deletions

File tree

src/components/motion/MotionController.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
4848
bool wake = false;
4949
auto diff = xTaskGetTickCount() - lastShakeTime;
5050
lastShakeTime = xTaskGetTickCount();
51-
int32_t speed = std::abs(z + (y/2) + (x/4)- lastYForShake - lastZForShake) / diff * 100;
51+
/* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
52+
int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100;
5253
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
53-
//implemented without floats as .25Alpha
54-
accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4);
54+
// implemented without floats as .25Alpha
55+
accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4);
5556

56-
if (accumulatedspeed > thresh) {
57+
if (accumulatedspeed > thresh) {
5758
wake = true;
5859
}
59-
lastXForShake = x/4;
60-
lastYForShake = y/2;
60+
lastXForShake = x / 4;
61+
lastYForShake = y / 2;
6162
lastZForShake = z;
6263
return wake;
6364
}
64-
int32_t MotionController::currentShakeSpeed(){
65+
int32_t MotionController::currentShakeSpeed() {
6566
return accumulatedspeed;
6667
}
6768

src/displayapp/screens/settings/SettingShakeThreshold.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "displayapp/screens/Screen.h"
55
#include "displayapp/screens/Symbols.h"
66

7-
87
using namespace Pinetime::Applications::Screens;
98

109
namespace {
@@ -16,12 +15,9 @@ namespace {
1615

1716
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
1817
Controllers::Settings& settingsController,
19-
Controllers::MotionController& motionController,
18+
Controllers::MotionController& motionController,
2019
System::SystemTask& systemTask)
21-
: Screen(app),
22-
settingsController {settingsController},
23-
motionController {motionController},
24-
systemTask {systemTask} {
20+
: Screen(app), settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} {
2521

2622
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
2723
lv_label_set_text_static(title, "Wake Sensitivity");
@@ -31,7 +27,7 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
3127
taskCount = 0;
3228

3329
positionArc = lv_arc_create(lv_scr_act(), nullptr);
34-
30+
3531
positionArc->user_data = this;
3632

3733
lv_obj_set_event_cb(positionArc, event_handler);
@@ -56,43 +52,43 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
5652
lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
5753
calLabel = lv_label_create(calButton, NULL);
5854
lv_label_set_text(calLabel, "Calibrate");
59-
60-
}
55+
}
6156

6257
SettingShakeThreshold::~SettingShakeThreshold() {
6358
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
64-
lv_task_del(refreshTask);
65-
lv_obj_clean(lv_scr_act());
59+
if (taskCount > 0) {
60+
lv_task_del(refreshTask);
61+
}
6662
settingsController.SaveSettings();
63+
lv_obj_clean(lv_scr_act());
6764
}
6865

6966
void SettingShakeThreshold::Refresh() {
70-
71-
taskCount++; //100ms Update time so finish @100
72-
if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){
73-
lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200);
67+
68+
taskCount++; // 100ms Update time so finish @100
69+
if ((motionController.currentShakeSpeed() - 200) > lv_arc_get_value(positionArc)) {
70+
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 200);
7471
}
75-
if(taskCount >= 50){
72+
if (taskCount >= 50) {
7673
lv_label_set_text(calLabel, "Calibrate");
77-
taskCount=0;
74+
taskCount = 0;
7875
lv_task_del(refreshTask);
7976
}
80-
8177
}
8278

8379
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
8480

8581
switch (event) {
8682
case LV_EVENT_PRESSED: {
8783
if (object == calButton) {
88-
if(taskCount == 0){
89-
lv_arc_set_value(positionArc,0);
90-
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
84+
if (taskCount == 0) {
85+
lv_arc_set_value(positionArc, 0);
86+
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
9187
lv_label_set_text(calLabel, "Shake!!!");
92-
}else{
93-
88+
} else {
89+
9490
lv_task_del(refreshTask);
95-
taskCount=0;
91+
taskCount = 0;
9692
lv_label_set_text(calLabel, "Calibrate");
9793
}
9894
}

src/displayapp/screens/settings/SettingShakeThreshold.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ namespace Pinetime {
2626
Controllers::MotionController& motionController;
2727
System::SystemTask& systemTask;
2828

29-
30-
31-
3229
uint8_t taskCount;
3330
lv_obj_t* cbOption[2];
3431
lv_obj_t *positionArc, *calButton, *calLabel;

0 commit comments

Comments
 (0)