summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/motion/MotionController.cpp20
-rw-r--r--src/components/motion/MotionController.h12
-rw-r--r--src/components/settings/Settings.h8
3 files changed, 34 insertions, 6 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index 97a8feb2..58a7f672 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -1,4 +1,5 @@
#include "components/motion/MotionController.h"
+#include "os/os_cputime.h"
using namespace Pinetime::Controllers;
@@ -7,7 +8,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
service->OnNewStepCountValue(nbSteps);
}
- if(service != nullptr && (this->x != x || this->y != y || this->z != z)) {
+ if (service != nullptr && (this->x != x || this->y != y || this->z != z)) {
service->OnNewMotionValues(x, y, z);
}
@@ -21,7 +22,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
}
}
-bool MotionController::ShouldWakeUp(bool isSleeping) {
+bool MotionController::Should_RaiseWake(bool isSleeping) {
if ((x + 335) <= 670 && z < 0) {
if (not isSleeping) {
if (y <= 0) {
@@ -43,6 +44,21 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
}
return false;
}
+
+bool MotionController::Should_ShakeWake() {
+ bool wake = false;
+ auto diff = xTaskGetTickCount() - lastShakeTime;
+ lastShakeTime = xTaskGetTickCount();
+ int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10;
+ if (speed > 150) { // TODO move threshold to a setting
+ wake = true;
+ }
+ lastXForShake = x;
+ lastYForShake = y;
+ lastZForShake = z;
+ return wake;
+}
+
void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;
}
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index 3eac7176..f9c285e8 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -13,6 +13,10 @@ namespace Pinetime {
BMA421,
BMA425,
};
+ enum class WakeUpMode : uint8_t {
+ RaiseWrist = 0,
+ Shake,
+ };
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
@@ -35,7 +39,8 @@ namespace Pinetime {
uint32_t GetTripSteps() const {
return currentTripSteps;
}
- bool ShouldWakeUp(bool isSleeping);
+ bool Should_ShakeWake();
+ bool Should_RaiseWake(bool isSleeping);
void IsSensorOk(bool isOk);
bool IsSensorOk() const {
@@ -59,6 +64,11 @@ namespace Pinetime {
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
Pinetime::Controllers::MotionService* service = nullptr;
+
+ int16_t lastXForShake = 0;
+ int16_t lastYForShake = 0;
+ int16_t lastZForShake = 0;
+ uint32_t lastShakeTime = 0;
};
}
} \ No newline at end of file
diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h
index 2d7973d8..928d04c8 100644
--- a/src/components/settings/Settings.h
+++ b/src/components/settings/Settings.h
@@ -15,6 +15,7 @@ namespace Pinetime {
SingleTap = 0,
DoubleTap = 1,
RaiseWrist = 2,
+ Shake = 3,
};
enum class Colors : uint8_t {
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
@@ -127,12 +128,13 @@ namespace Pinetime {
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
break;
case WakeUpMode::RaiseWrist:
+ case WakeUpMode::Shake:
break;
}
}
};
- std::bitset<3> getWakeUpModes() const {
+ std::bitset<4> getWakeUpModes() const {
return settings.wakeUpMode;
}
@@ -162,7 +164,7 @@ namespace Pinetime {
private:
Pinetime::Controllers::FS& fs;
- static constexpr uint32_t settingsVersion = 0x0002;
+ static constexpr uint32_t settingsVersion = 0x0003;
struct SettingsData {
uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000;
@@ -175,7 +177,7 @@ namespace Pinetime {
PineTimeStyle PTS;
- std::bitset<3> wakeUpMode {0};
+ std::bitset<4> wakeUpMode {0};
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
};