summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/components/motion/MotionController.cpp15
-rw-r--r--src/displayapp/screens/settings/SettingShakeThreshold.cpp44
-rw-r--r--src/displayapp/screens/settings/SettingShakeThreshold.h3
3 files changed, 28 insertions, 34 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index d26fffd0..7dd32127 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -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) {
+ 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;
}
diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.cpp b/src/displayapp/screens/settings/SettingShakeThreshold.cpp
index cc67687a..cc59bb6f 100644
--- a/src/displayapp/screens/settings/SettingShakeThreshold.cpp
+++ b/src/displayapp/screens/settings/SettingShakeThreshold.cpp
@@ -4,7 +4,6 @@
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"
-
using namespace Pinetime::Applications::Screens;
namespace {
@@ -16,12 +15,9 @@ namespace {
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
Controllers::Settings& settingsController,
- Controllers::MotionController& motionController,
+ 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");
@@ -31,7 +27,7 @@ SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
taskCount = 0;
positionArc = lv_arc_create(lv_scr_act(), nullptr);
-
+
positionArc->user_data = this;
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);
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");
}
}
diff --git a/src/displayapp/screens/settings/SettingShakeThreshold.h b/src/displayapp/screens/settings/SettingShakeThreshold.h
index f6918f4d..36c59569 100644
--- a/src/displayapp/screens/settings/SettingShakeThreshold.h
+++ b/src/displayapp/screens/settings/SettingShakeThreshold.h
@@ -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;