Skip to content

Commit

Permalink
Remove y variable and replace at() with brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
FintasticMan committed May 9, 2022
1 parent 9c375be commit b32a22e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
23 changes: 11 additions & 12 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ 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 || lastYs[lastYIndex] != y || this->z != z)) {
service->OnNewMotionValues(x, y, z);
}

lastYIndex++;
lastYIndex %= lastYs.size();
lastYs.at(lastYIndex) = this->y;
lastYs[lastYIndex] = y;
this->x = x;
this->y = y;
this->z = z;
int32_t deltaSteps = nbSteps - this->nbSteps;
this->nbSteps = nbSteps;
Expand All @@ -27,20 +26,20 @@ 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) {
if (lastYs[lastYIndex] <= 0) {
return false;
} else {
lastYForWakeUp = 0;
return false;
}
}

if (y >= 0) {
if (lastYs[lastYIndex] >= 0) {
lastYForWakeUp = 0;
return false;
}
if (y + 230 < lastYForWakeUp) {
lastYForWakeUp = y;
if (lastYs[lastYIndex] + 230 < lastYForWakeUp) {
lastYForWakeUp = lastYs[lastYIndex];
return true;
}
}
Expand All @@ -52,7 +51,7 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
auto diff = xTaskGetTickCount() - lastShakeTime;
lastShakeTime = xTaskGetTickCount();
/* 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;
int32_t speed = std::abs(z + (lastYs[lastYIndex] / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100;
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
// implemented without floats as .25Alpha
accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4);
Expand All @@ -61,7 +60,7 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
wake = true;
}
lastXForShake = x / 4;
lastYForShake = y / 2;
lastYForShake = lastYs[lastYIndex] / 2;
lastZForShake = z;
return wake;
}
Expand All @@ -70,13 +69,13 @@ int32_t MotionController::currentShakeSpeed() {
}

bool MotionController::ShouldLowerSleep() const {
if (lastYs.at((lastYIndex + 2) % lastYs.size()) < lastYs.at((lastYIndex + 1) % lastYs.size()) + 192 ||
lastYs.at((lastYIndex + 2) % lastYs.size()) < 512) {
if (lastYs[(lastYIndex + 2) % lastYs.size()] < lastYs[(lastYIndex + 1) % lastYs.size()] + 192 ||
lastYs[(lastYIndex + 2) % lastYs.size()] < 512) {
return false;
}

for (uint8_t i = 3; i < lastYs.size(); i++) {
if (lastYs.at((lastYIndex + i) % lastYs.size()) < 0) {
if (lastYs[(lastYIndex + i) % lastYs.size()] < 0) {
return false;
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Pinetime {
return x;
}
int16_t Y() const {
return y;
return lastYs[lastYIndex];
}
int16_t Z() const {
return z;
Expand Down Expand Up @@ -57,7 +57,6 @@ namespace Pinetime {
uint32_t nbSteps;
uint32_t currentTripSteps = 0;
int16_t x = 0;
int16_t y = 0;
int16_t z = 0;
std::array<int16_t, 8> lastYs = {};
uint8_t lastYIndex = 0;
Expand Down
35 changes: 14 additions & 21 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ namespace Pinetime {
enum class ClockType : uint8_t { H24, H12 };
enum class Notification : uint8_t { ON, OFF };
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
enum class WakeUpMode : uint8_t {
SingleTap = 0,
DoubleTap = 1,
RaiseWrist = 2,
Shake = 3,
LowerWrist = 4
};
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
enum class Colors : uint8_t {
White,
Silver,
Expand Down Expand Up @@ -141,15 +135,14 @@ namespace Pinetime {
return settings.screenTimeOut;
};

void SetShakeThreshold(uint16_t thresh){
if(settings.shakeWakeThreshold != thresh){
settings.shakeWakeThreshold = thresh;
settingsChanged = true;
void SetShakeThreshold(uint16_t thresh) {
if (settings.shakeWakeThreshold != thresh) {
settings.shakeWakeThreshold = thresh;
settingsChanged = true;
}

}

int16_t GetShakeThreshold() const{
int16_t GetShakeThreshold() const {
return settings.shakeWakeThreshold;
}

Expand Down Expand Up @@ -196,20 +189,20 @@ namespace Pinetime {
if (goal != settings.stepsGoal) {
settingsChanged = true;
}
settings.stepsGoal = goal;
settings.stepsGoal = goal;
};

uint32_t GetStepsGoal() const {
return settings.stepsGoal;
};

void SetBleRadioEnabled(bool enabled) {
bleRadioEnabled = enabled;
};
void SetBleRadioEnabled(bool enabled) {
bleRadioEnabled = enabled;
};

bool GetBleRadioEnabled() const {
return bleRadioEnabled;
};
bool GetBleRadioEnabled() const {
return bleRadioEnabled;
};

private:
Pinetime::Controllers::FS& fs;
Expand Down

0 comments on commit b32a22e

Please sign in to comment.