Added Shake to wake

This commit is contained in:
Tim Keller 2021-09-27 01:20:44 +00:00
parent e0013e7304
commit d270275bd2
6 changed files with 55 additions and 14 deletions

View file

@ -1,4 +1,5 @@
#include "components/motion/MotionController.h" #include "components/motion/MotionController.h"
#include "os/os_cputime.h"
using namespace Pinetime::Controllers; 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); 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); 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 ((x + 335) <= 670 && z < 0) {
if (not isSleeping) { if (not isSleeping) {
if (y <= 0) { if (y <= 0) {
@ -43,6 +44,21 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
} }
return false; 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) { void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk; isSensorOk = isOk;
} }

View file

@ -13,6 +13,10 @@ namespace Pinetime {
BMA421, BMA421,
BMA425, BMA425,
}; };
enum class WakeUpMode : uint8_t {
RaiseWrist = 0,
Shake,
};
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps); void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
@ -35,7 +39,8 @@ namespace Pinetime {
uint32_t GetTripSteps() const { uint32_t GetTripSteps() const {
return currentTripSteps; return currentTripSteps;
} }
bool ShouldWakeUp(bool isSleeping); bool Should_ShakeWake();
bool Should_RaiseWake(bool isSleeping);
void IsSensorOk(bool isOk); void IsSensorOk(bool isOk);
bool IsSensorOk() const { bool IsSensorOk() const {
@ -59,6 +64,11 @@ namespace Pinetime {
bool isSensorOk = false; bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown; DeviceTypes deviceType = DeviceTypes::Unknown;
Pinetime::Controllers::MotionService* service = nullptr; Pinetime::Controllers::MotionService* service = nullptr;
int16_t lastXForShake = 0;
int16_t lastYForShake = 0;
int16_t lastZForShake = 0;
uint32_t lastShakeTime = 0;
}; };
} }
} }

View file

@ -15,6 +15,7 @@ namespace Pinetime {
SingleTap = 0, SingleTap = 0,
DoubleTap = 1, DoubleTap = 1,
RaiseWrist = 2, RaiseWrist = 2,
Shake = 3,
}; };
enum class Colors : uint8_t { enum class Colors : uint8_t {
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange 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); settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
break; break;
case WakeUpMode::RaiseWrist: case WakeUpMode::RaiseWrist:
case WakeUpMode::Shake:
break; break;
} }
} }
}; };
std::bitset<3> getWakeUpModes() const { std::bitset<4> getWakeUpModes() const {
return settings.wakeUpMode; return settings.wakeUpMode;
} }
@ -162,7 +164,7 @@ namespace Pinetime {
private: private:
Pinetime::Controllers::FS& fs; Pinetime::Controllers::FS& fs;
static constexpr uint32_t settingsVersion = 0x0002; static constexpr uint32_t settingsVersion = 0x0003;
struct SettingsData { struct SettingsData {
uint32_t version = settingsVersion; uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000; uint32_t stepsGoal = 10000;
@ -175,7 +177,7 @@ namespace Pinetime {
PineTimeStyle PTS; PineTimeStyle PTS;
std::bitset<3> wakeUpMode {0}; std::bitset<4> wakeUpMode {0};
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
}; };

View file

@ -65,6 +65,14 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
lv_checkbox_set_checked(cbOption[optionsTotal], true); lv_checkbox_set_checked(cbOption[optionsTotal], true);
} }
optionsTotal++; optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Shake Wake");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
} }
SettingWakeUp::~SettingWakeUp() { SettingWakeUp::~SettingWakeUp() {

View file

@ -20,7 +20,7 @@ namespace Pinetime {
private: private:
Controllers::Settings& settingsController; Controllers::Settings& settingsController;
uint8_t optionsTotal; uint8_t optionsTotal;
lv_obj_t* cbOption[4]; lv_obj_t* cbOption[5];
// When UpdateSelected is called, it uses lv_checkbox_set_checked, // When UpdateSelected is called, it uses lv_checkbox_set_checked,
// which can cause extra events to be fired, // which can cause extra events to be fired,
// which might trigger UpdateSelected again, causing a loop. // which might trigger UpdateSelected again, causing a loop.

View file

@ -347,13 +347,13 @@ void SystemTask::Work() {
doNotGoToSleep = true; doNotGoToSleep = true;
if (isSleeping && !isWakingUp) if (isSleeping && !isWakingUp)
GoToRunning(); GoToRunning();
//TODO add intent of fs access icon or something // TODO add intent of fs access icon or something
break; break;
case Messages::StopFileTransfer: case Messages::StopFileTransfer:
NRF_LOG_INFO("[systemtask] FS Stopped"); NRF_LOG_INFO("[systemtask] FS Stopped");
doNotGoToSleep = false; doNotGoToSleep = false;
xTimerStart(dimTimer, 0); xTimerStart(dimTimer, 0);
//TODO add intent of fs access icon or something // TODO add intent of fs access icon or something
break; break;
case Messages::OnTouchEvent: case Messages::OnTouchEvent:
if (touchHandler.GetNewTouchInfo()) { if (touchHandler.GetNewTouchInfo()) {
@ -457,10 +457,10 @@ void SystemTask::UpdateMotion() {
return; return;
} }
if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) { if (isSleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
return; return;
} }
if (stepCounterMustBeReset) { if (stepCounterMustBeReset) {
motionSensor.ResetStepCounter(); motionSensor.ResetStepCounter();
stepCounterMustBeReset = false; stepCounterMustBeReset = false;
@ -470,7 +470,12 @@ void SystemTask::UpdateMotion() {
motionController.IsSensorOk(motionSensor.IsOk()); motionController.IsSensorOk(motionSensor.IsOk());
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps); motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
if (motionController.ShouldWakeUp(isSleeping)) { // TODO add modes arg
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
motionController.Should_RaiseWake(isSleeping)) {
GoToRunning();
}
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && motionController.Should_ShakeWake()) {
GoToRunning(); GoToRunning();
} }
} }