Skip to content

Commit

Permalink
Improve and simplify Raise to Wake algorithm
Browse files Browse the repository at this point in the history
Squash commit of the following commits:

Adjust trigger values for Raise to Wake

Also handle isSleeping in SystemTask

Tweak the raise to wake values a bit more

Make lastY variable more generic and improve raise to wake more

Fix incorrect function call in SystemTask

Remove LastY from motion app

Overhaul raise wake to work more consistently

Also adds 2 new lines to the motion app, just for
testing purposes. White is deltaY and purple is
deltaZ.

Remove define statements and tweak values
  • Loading branch information
FintasticMan committed May 27, 2022
1 parent 87a69fe commit ef0a0c4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
34 changes: 18 additions & 16 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
service->OnNewMotionValues(x, y, z);
}

deltaY = y - this->y;
deltaZ = z - this->z;
this->x = x;
this->y = y;
this->z = z;
Expand All @@ -21,27 +23,27 @@ 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;
}
}
bool MotionController::ShouldRaiseWake() const {
if (x < -raiseWakeXThresh || x > raiseWakeXThresh || y > raiseWakeYThresh) {
return false;
}

if (y >= 0) {
lastYForWakeUp = 0;
if (std::abs(y) > std::abs(z)) {
if (deltaZ < raiseWakeSpeed) {
return false;
}
if (y + 230 < lastYForWakeUp) {
lastYForWakeUp = y;
return true;
return true;
}
if (z < 0) {
if (deltaY > -raiseWakeSpeed) {
return false;
}
return true;
}
if (deltaY < raiseWakeSpeed) {
return false;
}
return false;
return true;
}

bool MotionController::Should_ShakeWake(uint16_t thresh) {
Expand Down
22 changes: 16 additions & 6 deletions src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ namespace Pinetime {
int16_t Z() const {
return z;
}
int16_t DeltaY() const {
return deltaY;
}
int16_t DeltaZ() const {
return deltaZ;
}
uint32_t NbSteps() const {
return nbSteps;
}
Expand All @@ -36,8 +42,8 @@ namespace Pinetime {
return currentTripSteps;
}

bool ShouldRaiseWake() const;
bool Should_ShakeWake(uint16_t thresh);
bool Should_RaiseWake(bool isSleeping);
int32_t currentShakeSpeed();
void IsSensorOk(bool isOk);
bool IsSensorOk() const {
Expand All @@ -54,10 +60,14 @@ namespace Pinetime {
private:
uint32_t nbSteps;
uint32_t currentTripSteps = 0;
int16_t x;
int16_t y;
int16_t z;
int16_t lastYForWakeUp = 0;
int16_t x = 0;
int16_t y = 0;
int16_t z = 0;
int16_t deltaY = 0;
int16_t deltaZ = 0;
const int16_t raiseWakeXThresh = 512;
const int16_t raiseWakeYThresh = 0;
const int16_t raiseWakeSpeed = 192;
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
Pinetime::Controllers::MotionService* service = nullptr;
Expand All @@ -69,4 +79,4 @@ namespace Pinetime {
uint32_t lastShakeTime = 0;
};
}
}
}
4 changes: 2 additions & 2 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ void SystemTask::UpdateMotion() {
motionController.IsSensorOk(motionSensor.IsOk());
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);

if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
motionController.Should_RaiseWake(state == SystemTaskState::Sleeping)) {
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) && state == SystemTaskState::Sleeping &&
motionController.ShouldRaiseWake()) {
GoToRunning();
}
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
Expand Down

0 comments on commit ef0a0c4

Please sign in to comment.