summaryrefslogtreecommitdiff
path: root/src/components/motion
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/motion')
-rw-r--r--src/components/motion/MotionController.cpp28
-rw-r--r--src/components/motion/MotionController.h15
2 files changed, 17 insertions, 26 deletions
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index 7dd3212..c57d8aa 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -11,6 +11,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
service->OnNewMotionValues(x, y, z);
}
+ lastY = this->y;
this->x = x;
this->y = y;
this->z = z;
@@ -21,27 +22,8 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
}
}
-bool MotionController::Should_RaiseWake(bool isSleeping) {
- if ((x + 335) <= 670 && z < 0) {
- if (not isSleeping) {
- if (y <= 0) {
- return false;
- } else {
- lastYForWakeUp = 0;
- return false;
- }
- }
-
- if (y >= 0) {
- lastYForWakeUp = 0;
- return false;
- }
- if (y + 230 < lastYForWakeUp) {
- lastYForWakeUp = y;
- return true;
- }
- }
- return false;
+bool MotionController::ShouldRaiseWake() const {
+ return x >= -384 && x <= 384 && z <= 0 && y <= -160 && y <= lastY - 160;
}
bool MotionController::Should_ShakeWake(uint16_t thresh) {
@@ -66,6 +48,10 @@ int32_t MotionController::currentShakeSpeed() {
return accumulatedspeed;
}
+bool MotionController::ShouldLowerSleep() const {
+ return y >= 512 && y >= lastY + 192;
+}
+
void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;
}
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index f80b11b..297db59 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -25,6 +25,9 @@ namespace Pinetime {
int16_t Z() const {
return z;
}
+ int16_t LastY() const {
+ return lastY;
+ }
uint32_t NbSteps() const {
return nbSteps;
}
@@ -36,9 +39,10 @@ namespace Pinetime {
return currentTripSteps;
}
+ bool ShouldRaiseWake() const;
bool Should_ShakeWake(uint16_t thresh);
- bool Should_RaiseWake(bool isSleeping);
int32_t currentShakeSpeed();
+ bool ShouldLowerSleep() const;
void IsSensorOk(bool isOk);
bool IsSensorOk() const {
return isSensorOk;
@@ -54,9 +58,10 @@ namespace Pinetime {
private:
uint32_t nbSteps;
uint32_t currentTripSteps = 0;
- int16_t x;
- int16_t y;
- int16_t z;
+ int16_t x = 0;
+ int16_t y = 0;
+ int16_t z = 0;
+ int16_t lastY = 0;
int16_t lastYForWakeUp = 0;
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
@@ -69,4 +74,4 @@ namespace Pinetime {
uint32_t lastShakeTime = 0;
};
}
-} \ No newline at end of file
+}