Skip to content

Commit d270275

Browse files
committed
Added Shake to wake
1 parent e0013e7 commit d270275

6 files changed

Lines changed: 55 additions & 14 deletions

File tree

src/components/motion/MotionController.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "components/motion/MotionController.h"
2+
#include "os/os_cputime.h"
23

34
using namespace Pinetime::Controllers;
45

@@ -7,7 +8,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
78
service->OnNewStepCountValue(nbSteps);
89
}
910

10-
if(service != nullptr && (this->x != x || this->y != y || this->z != z)) {
11+
if (service != nullptr && (this->x != x || this->y != y || this->z != z)) {
1112
service->OnNewMotionValues(x, y, z);
1213
}
1314

@@ -21,7 +22,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps)
2122
}
2223
}
2324

24-
bool MotionController::ShouldWakeUp(bool isSleeping) {
25+
bool MotionController::Should_RaiseWake(bool isSleeping) {
2526
if ((x + 335) <= 670 && z < 0) {
2627
if (not isSleeping) {
2728
if (y <= 0) {
@@ -43,6 +44,21 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
4344
}
4445
return false;
4546
}
47+
48+
bool MotionController::Should_ShakeWake() {
49+
bool wake = false;
50+
auto diff = xTaskGetTickCount() - lastShakeTime;
51+
lastShakeTime = xTaskGetTickCount();
52+
int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10;
53+
if (speed > 150) { // TODO move threshold to a setting
54+
wake = true;
55+
}
56+
lastXForShake = x;
57+
lastYForShake = y;
58+
lastZForShake = z;
59+
return wake;
60+
}
61+
4662
void MotionController::IsSensorOk(bool isOk) {
4763
isSensorOk = isOk;
4864
}

src/components/motion/MotionController.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ namespace Pinetime {
1313
BMA421,
1414
BMA425,
1515
};
16+
enum class WakeUpMode : uint8_t {
17+
RaiseWrist = 0,
18+
Shake,
19+
};
1620

1721
void Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps);
1822

@@ -35,7 +39,8 @@ namespace Pinetime {
3539
uint32_t GetTripSteps() const {
3640
return currentTripSteps;
3741
}
38-
bool ShouldWakeUp(bool isSleeping);
42+
bool Should_ShakeWake();
43+
bool Should_RaiseWake(bool isSleeping);
3944

4045
void IsSensorOk(bool isOk);
4146
bool IsSensorOk() const {
@@ -59,6 +64,11 @@ namespace Pinetime {
5964
bool isSensorOk = false;
6065
DeviceTypes deviceType = DeviceTypes::Unknown;
6166
Pinetime::Controllers::MotionService* service = nullptr;
67+
68+
int16_t lastXForShake = 0;
69+
int16_t lastYForShake = 0;
70+
int16_t lastZForShake = 0;
71+
uint32_t lastShakeTime = 0;
6272
};
6373
}
6474
}

src/components/settings/Settings.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Pinetime {
1515
SingleTap = 0,
1616
DoubleTap = 1,
1717
RaiseWrist = 2,
18+
Shake = 3,
1819
};
1920
enum class Colors : uint8_t {
2021
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
@@ -127,12 +128,13 @@ namespace Pinetime {
127128
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
128129
break;
129130
case WakeUpMode::RaiseWrist:
131+
case WakeUpMode::Shake:
130132
break;
131133
}
132134
}
133135
};
134136

135-
std::bitset<3> getWakeUpModes() const {
137+
std::bitset<4> getWakeUpModes() const {
136138
return settings.wakeUpMode;
137139
}
138140

@@ -162,7 +164,7 @@ namespace Pinetime {
162164
private:
163165
Pinetime::Controllers::FS& fs;
164166

165-
static constexpr uint32_t settingsVersion = 0x0002;
167+
static constexpr uint32_t settingsVersion = 0x0003;
166168
struct SettingsData {
167169
uint32_t version = settingsVersion;
168170
uint32_t stepsGoal = 10000;
@@ -175,7 +177,7 @@ namespace Pinetime {
175177

176178
PineTimeStyle PTS;
177179

178-
std::bitset<3> wakeUpMode {0};
180+
std::bitset<4> wakeUpMode {0};
179181

180182
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
181183
};

src/displayapp/screens/settings/SettingWakeUp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
6565
lv_checkbox_set_checked(cbOption[optionsTotal], true);
6666
}
6767
optionsTotal++;
68+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
69+
lv_checkbox_set_text_static(cbOption[optionsTotal], " Shake Wake");
70+
cbOption[optionsTotal]->user_data = this;
71+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
72+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) {
73+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
74+
}
75+
optionsTotal++;
6876
}
6977

7078
SettingWakeUp::~SettingWakeUp() {

src/displayapp/screens/settings/SettingWakeUp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Pinetime {
2020
private:
2121
Controllers::Settings& settingsController;
2222
uint8_t optionsTotal;
23-
lv_obj_t* cbOption[4];
23+
lv_obj_t* cbOption[5];
2424
// When UpdateSelected is called, it uses lv_checkbox_set_checked,
2525
// which can cause extra events to be fired,
2626
// which might trigger UpdateSelected again, causing a loop.

src/systemtask/SystemTask.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,18 @@ void SystemTask::Work() {
343343
xTimerStart(dimTimer, 0);
344344
break;
345345
case Messages::StartFileTransfer:
346-
NRF_LOG_INFO("[systemtask] FS Started");
346+
NRF_LOG_INFO("[systemtask] FS Started");
347347
doNotGoToSleep = true;
348348
if (isSleeping && !isWakingUp)
349349
GoToRunning();
350-
//TODO add intent of fs access icon or something
350+
// TODO add intent of fs access icon or something
351351
break;
352352
case Messages::StopFileTransfer:
353353
NRF_LOG_INFO("[systemtask] FS Stopped");
354354
doNotGoToSleep = false;
355355
xTimerStart(dimTimer, 0);
356-
//TODO add intent of fs access icon or something
357-
break;
356+
// TODO add intent of fs access icon or something
357+
break;
358358
case Messages::OnTouchEvent:
359359
if (touchHandler.GetNewTouchInfo()) {
360360
touchHandler.UpdateLvglTouchPoint();
@@ -457,10 +457,10 @@ void SystemTask::UpdateMotion() {
457457
return;
458458
}
459459

460-
if (isSleeping && !settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist)) {
460+
if (isSleeping && !(settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) ||
461+
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake))) {
461462
return;
462463
}
463-
464464
if (stepCounterMustBeReset) {
465465
motionSensor.ResetStepCounter();
466466
stepCounterMustBeReset = false;
@@ -470,7 +470,12 @@ void SystemTask::UpdateMotion() {
470470

471471
motionController.IsSensorOk(motionSensor.IsOk());
472472
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
473-
if (motionController.ShouldWakeUp(isSleeping)) {
473+
// TODO add modes arg
474+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
475+
motionController.Should_RaiseWake(isSleeping)) {
476+
GoToRunning();
477+
}
478+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && motionController.Should_ShakeWake()) {
474479
GoToRunning();
475480
}
476481
}

0 commit comments

Comments
 (0)