Skip to content

Commit

Permalink
PR InfiniTimeOrg#827: Implement Lower to Sleep functionality
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit fab8269
Author: Finlay Davidson <finlay.davidson@coderclass.nl>
Date:   Sun Nov 14 01:31:29 2021 +0100

    Have isSleeping be checked by SystemTask, and fix incorrect array size

commit 7d50102
Author: Finlay Davidson <finlay.davidson@coderclass.nl>
Date:   Fri Nov 12 01:48:04 2021 +0100

    Add settings item

commit 5269885
Author: Finlay Davidson <finlay.davidson@coderclass.nl>
Date:   Fri Nov 12 00:48:04 2021 +0100

    Improve and simplify algorithm

commit c925c62
Author: Finlay Davidson <finlay.davidson@coderclass.nl>
Date:   Thu Nov 11 13:42:25 2021 +0100

    Initial lower to sleep implementation
  • Loading branch information
FintasticMan committed Dec 13, 2021
1 parent b5d9f01 commit 53788ed
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/components/motion/MotionController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
}
return false;
}
bool MotionController::ShouldSleep() {
bool ret = false;

if (y >= lastYForSleep + 192) {
ret = true;
}

lastYForSleep = (y > 320) ? y : 320;

return ret;
}

void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/motion/MotionController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Pinetime {
return nbSteps;
}
bool ShouldWakeUp(bool isSleeping);
bool ShouldSleep();

void IsSensorOk(bool isOk);
bool IsSensorOk() const {
Expand All @@ -48,9 +49,10 @@ namespace Pinetime {
int16_t y;
int16_t z;
int16_t lastYForWakeUp = 0;
int16_t lastYForSleep = 0;
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
Pinetime::Controllers::MotionService* service = nullptr;
};
}
}
}
7 changes: 4 additions & 3 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Pinetime {
SingleTap = 0,
DoubleTap = 1,
RaiseWrist = 2,
LowerWrist = 3
};
enum class Colors : uint8_t {
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
Expand Down Expand Up @@ -126,13 +127,13 @@ namespace Pinetime {
case WakeUpMode::DoubleTap:
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
break;
case WakeUpMode::RaiseWrist:
default:
break;
}
}
};

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

Expand Down Expand Up @@ -175,7 +176,7 @@ namespace Pinetime {

PineTimeStyle PTS;

std::bitset<3> wakeUpMode {0};
std::bitset<4> wakeUpMode {0};

Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
};
Expand Down
8 changes: 8 additions & 0 deletions src/displayapp/screens/settings/SettingWakeUp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ SettingWakeUp::SettingWakeUp(Pinetime::Applications::DisplayApp* app, Pinetime::
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Lower Wrist");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist)) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
}

SettingWakeUp::~SettingWakeUp() {
Expand Down
4 changes: 4 additions & 0 deletions src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ void SystemTask::UpdateMotion() {
if (motionController.ShouldWakeUp(isSleeping)) {
GoToRunning();
}
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::LowerWrist)) {
if (motionController.ShouldSleep() && !isSleeping)
PushMessage(Messages::GoToSleep);
}
}

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

0 comments on commit 53788ed

Please sign in to comment.