Skip to content

Commit 0f9f606

Browse files
authored
lowersleep: Implement Lower to Sleep functionality (InfiniTimeOrg#827)
1 parent 2b1eae7 commit 0f9f606

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

src/components/motion/MotionController.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ bool MotionController::ShouldShakeWake(uint16_t thresh) {
115115
return accumulatedSpeed > thresh;
116116
}
117117

118+
bool MotionController::ShouldLowerSleep() const {
119+
if (stats.yMean < 724 || DegreesRolled(stats.yMean, stats.zMean, stats.prevYMean, stats.prevZMean) < 30) {
120+
return false;
121+
}
122+
123+
for (uint8_t i = AccelStats::numHistory + 1; i < yHistory.Size(); i++) {
124+
if (yHistory[i] < 265) {
125+
return false;
126+
}
127+
}
128+
129+
return true;
130+
}
131+
118132
void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) {
119133
switch (types) {
120134
case Drivers::Bma421::DeviceTypes::BMA421:

src/components/motion/MotionController.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace Pinetime {
4646

4747
bool ShouldShakeWake(uint16_t thresh);
4848
bool ShouldRaiseWake() const;
49+
bool ShouldLowerSleep() const;
4950

5051
int32_t CurrentShakeSpeed() const {
5152
return accumulatedSpeed;

src/components/settings/Settings.h

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ namespace Pinetime {
1212
enum class ClockType : uint8_t { H24, H12 };
1313
enum class Notification : uint8_t { On, Off, Sleep };
1414
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
15-
enum class WakeUpMode : uint8_t {
16-
SingleTap = 0,
17-
DoubleTap = 1,
18-
RaiseWrist = 2,
19-
Shake = 3,
20-
};
15+
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
2116
enum class Colors : uint8_t {
2217
White,
2318
Silver,
@@ -238,7 +233,7 @@ namespace Pinetime {
238233
}
239234
};
240235

241-
std::bitset<4> getWakeUpModes() const {
236+
std::bitset<5> getWakeUpModes() const {
242237
return settings.wakeUpMode;
243238
}
244239

@@ -279,7 +274,7 @@ namespace Pinetime {
279274
private:
280275
Pinetime::Controllers::FS& fs;
281276

282-
static constexpr uint32_t settingsVersion = 0x0005;
277+
static constexpr uint32_t settingsVersion = 0x0006;
283278

284279
struct SettingsData {
285280
uint32_t version = settingsVersion;
@@ -296,8 +291,9 @@ namespace Pinetime {
296291

297292
WatchFaceInfineat watchFaceInfineat;
298293

299-
std::bitset<4> wakeUpMode {0};
294+
std::bitset<5> wakeUpMode {0};
300295
uint16_t shakeWakeThreshold = 150;
296+
301297
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
302298
};
303299

src/displayapp/screens/settings/SettingWakeUp.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using namespace Pinetime::Applications::Screens;
1010

11-
constexpr std::array<SettingWakeUp::Option, 4> SettingWakeUp::options;
11+
constexpr std::array<SettingWakeUp::Option, 5> SettingWakeUp::options;
1212

1313
namespace {
1414
void event_handler(lv_obj_t* obj, lv_event_t event) {
@@ -27,9 +27,9 @@ SettingWakeUp::SettingWakeUp(Pinetime::Controllers::Settings& settingsController
2727
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
2828
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
2929

30-
lv_obj_set_pos(container1, 10, 60);
30+
lv_obj_set_pos(container1, 10, 35);
3131
lv_obj_set_width(container1, LV_HOR_RES - 20);
32-
lv_obj_set_height(container1, LV_VER_RES - 50);
32+
lv_obj_set_height(container1, LV_VER_RES - 20);
3333
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
3434

3535
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);

src/displayapp/screens/settings/SettingWakeUp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ namespace Pinetime {
2525
};
2626

2727
Controllers::Settings& settingsController;
28-
static constexpr std::array<Option, 4> options = {{
28+
static constexpr std::array<Option, 5> options = {{
2929
{Controllers::Settings::WakeUpMode::SingleTap, "Single Tap"},
3030
{Controllers::Settings::WakeUpMode::DoubleTap, "Double Tap"},
3131
{Controllers::Settings::WakeUpMode::RaiseWrist, "Raise Wrist"},
3232
{Controllers::Settings::WakeUpMode::Shake, "Shake Wake"},
33+
{Controllers::Settings::WakeUpMode::LowerWrist, "Lower Wrist"},
3334
}};
3435

3536
lv_obj_t* cbOption[options.size()];

src/systemtask/SystemTask.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ void SystemTask::UpdateMotion() {
436436
GoToRunning();
437437
}
438438
}
439+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist) && state == SystemTaskState::Running &&
440+
motionController.ShouldLowerSleep()) {
441+
PushMessage(Messages::GoToSleep);
442+
}
439443
}
440444

441445
void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {

0 commit comments

Comments
 (0)