Skip to content

Commit

Permalink
lowersleep: Implement Lower to Sleep functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
FintasticMan committed Jun 18, 2023
1 parent 3fbe193 commit 27f6fd8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "components/motion/MotionController.h"

#include <cstdint>
#include <task.h>

#include "utility/Math.h"
Expand Down Expand Up @@ -119,6 +120,17 @@ bool MotionController::ShouldShakeWake(uint16_t thresh) {
return accumulatedSpeed > thresh;
}

bool MotionController::ShouldLowerSleep() const {
constexpr int16_t yThresh = 724;
constexpr int16_t rollDegreesThresh = 30;

if (stats.yMean < yThresh) {
return false;
}

return DegreesRolled(stats.yMean, stats.zMean, stats.prevYMean, stats.prevZMean) > rollDegreesThresh;
}

void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) {
switch (types) {
case Drivers::Bma421::DeviceTypes::BMA421:
Expand Down
1 change: 1 addition & 0 deletions src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace Pinetime {

bool ShouldShakeWake(uint16_t thresh);
bool ShouldRaiseWake(bool isSleeping);
bool ShouldLowerSleep() const;

int32_t CurrentShakeSpeed() const {
return accumulatedSpeed;
Expand Down
12 changes: 4 additions & 8 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ namespace Pinetime {
enum class ClockType : uint8_t { H24, H12 };
enum class Notification : uint8_t { On, Off, Sleep };
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
enum class WakeUpMode : uint8_t {
SingleTap = 0,
DoubleTap = 1,
RaiseWrist = 2,
Shake = 3,
};
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 @@ -238,7 +233,7 @@ namespace Pinetime {
}
};

std::bitset<4> getWakeUpModes() const {
std::bitset<5> getWakeUpModes() const {
return settings.wakeUpMode;
}

Expand Down Expand Up @@ -296,8 +291,9 @@ namespace Pinetime {

WatchFaceInfineat watchFaceInfineat;

std::bitset<4> wakeUpMode {0};
std::bitset<5> wakeUpMode {0};
uint16_t shakeWakeThreshold = 150;

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

Expand Down
6 changes: 3 additions & 3 deletions src/displayapp/screens/settings/SettingWakeUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace Pinetime::Applications::Screens;

constexpr std::array<SettingWakeUp::Option, 4> SettingWakeUp::options;
constexpr std::array<SettingWakeUp::Option, 5> SettingWakeUp::options;

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

lv_obj_set_pos(container1, 10, 60);
lv_obj_set_pos(container1, 10, 35);
lv_obj_set_width(container1, LV_HOR_RES - 20);
lv_obj_set_height(container1, LV_VER_RES - 50);
lv_obj_set_height(container1, LV_VER_RES - 20);
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);

lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
Expand Down
3 changes: 2 additions & 1 deletion src/displayapp/screens/settings/SettingWakeUp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ namespace Pinetime {
};

Controllers::Settings& settingsController;
static constexpr std::array<Option, 4> options = {{
static constexpr std::array<Option, 5> options = {{
{Controllers::Settings::WakeUpMode::SingleTap, "Single Tap"},
{Controllers::Settings::WakeUpMode::DoubleTap, "Double Tap"},
{Controllers::Settings::WakeUpMode::RaiseWrist, "Raise Wrist"},
{Controllers::Settings::WakeUpMode::Shake, "Shake Wake"},
{Controllers::Settings::WakeUpMode::LowerWrist, "Lower Wrist"},
}};

lv_obj_t* cbOption[options.size()];
Expand Down
4 changes: 4 additions & 0 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ void SystemTask::UpdateMotion() {
GoToRunning();
}
}
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist) && state == SystemTaskState::Running &&
motionController.ShouldLowerSleep()) {
PushMessage(Messages::GoToSleep);
}
}

void SystemTask::HandleButtonAction(Controllers::ButtonActions action) {
Expand Down

0 comments on commit 27f6fd8

Please sign in to comment.