Merge branch 'ShakeWake' of https://github.com/geekbozu/InfiniTime into geekbozu-ShakeWake
# Conflicts: # src/CMakeLists.txt # src/displayapp/Apps.h # src/displayapp/DisplayApp.cpp # src/displayapp/screens/settings/Settings.cpp
This commit is contained in:
commit
bef3e708f6
|
@ -448,6 +448,7 @@ list(APPEND SOURCE_FILES
|
|||
displayapp/screens/settings/SettingSetDate.cpp
|
||||
displayapp/screens/settings/SettingSetTime.cpp
|
||||
displayapp/screens/settings/SettingChimes.cpp
|
||||
displayapp/screens/settings/SettingShakeThreshold.cpp
|
||||
|
||||
## Watch faces
|
||||
displayapp/icons/bg_clock.c
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "components/motion/MotionController.h"
|
||||
|
||||
#include "os/os_cputime.h"
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
|
||||
|
@ -7,7 +7,7 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t 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);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,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 (not isSleeping) {
|
||||
if (y <= 0) {
|
||||
|
@ -43,6 +43,29 @@ bool MotionController::ShouldWakeUp(bool isSleeping) {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MotionController::Should_ShakeWake(uint16_t thresh) {
|
||||
bool wake = false;
|
||||
auto diff = xTaskGetTickCount() - lastShakeTime;
|
||||
lastShakeTime = xTaskGetTickCount();
|
||||
/* Currently Polling at 10hz, If this ever goes faster scalar and EMA might need adjusting */
|
||||
int32_t speed = std::abs(z + (y / 2) + (x / 4) - lastYForShake - lastZForShake) / diff * 100;
|
||||
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
|
||||
// implemented without floats as .25Alpha
|
||||
accumulatedspeed = (speed / 5) + ((accumulatedspeed / 5) * 4);
|
||||
|
||||
if (accumulatedspeed > thresh) {
|
||||
wake = true;
|
||||
}
|
||||
lastXForShake = x / 4;
|
||||
lastYForShake = y / 2;
|
||||
lastZForShake = z;
|
||||
return wake;
|
||||
}
|
||||
int32_t MotionController::currentShakeSpeed() {
|
||||
return accumulatedspeed;
|
||||
}
|
||||
|
||||
void MotionController::IsSensorOk(bool isOk) {
|
||||
isSensorOk = isOk;
|
||||
}
|
||||
|
|
|
@ -35,8 +35,10 @@ namespace Pinetime {
|
|||
uint32_t GetTripSteps() const {
|
||||
return currentTripSteps;
|
||||
}
|
||||
bool ShouldWakeUp(bool isSleeping);
|
||||
|
||||
bool Should_ShakeWake(uint16_t thresh);
|
||||
bool Should_RaiseWake(bool isSleeping);
|
||||
int32_t currentShakeSpeed();
|
||||
void IsSensorOk(bool isOk);
|
||||
bool IsSensorOk() const {
|
||||
return isSensorOk;
|
||||
|
@ -59,6 +61,12 @@ namespace Pinetime {
|
|||
bool isSensorOk = false;
|
||||
DeviceTypes deviceType = DeviceTypes::Unknown;
|
||||
Pinetime::Controllers::MotionService* service = nullptr;
|
||||
|
||||
int16_t lastXForShake = 0;
|
||||
int16_t lastYForShake = 0;
|
||||
int16_t lastZForShake = 0;
|
||||
int32_t accumulatedspeed = 0;
|
||||
uint32_t lastShakeTime = 0;
|
||||
};
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ namespace Pinetime {
|
|||
SingleTap = 0,
|
||||
DoubleTap = 1,
|
||||
RaiseWrist = 2,
|
||||
Shake = 3,
|
||||
};
|
||||
enum class Colors : uint8_t {
|
||||
White, Silver, Gray, Black, Red, Maroon, Yellow, Olive, Lime, Green, Cyan, Teal, Blue, Navy, Magenta, Purple, Orange
|
||||
|
@ -119,10 +120,23 @@ namespace Pinetime {
|
|||
}
|
||||
settings.screenTimeOut = timeout;
|
||||
};
|
||||
|
||||
uint32_t GetScreenTimeOut() const {
|
||||
return settings.screenTimeOut;
|
||||
};
|
||||
|
||||
void SetShakeThreshold(uint16_t thresh){
|
||||
if(settings.shakeWakeThreshold != thresh){
|
||||
settings.shakeWakeThreshold = thresh;
|
||||
settingsChanged = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int16_t GetShakeThreshold() const{
|
||||
return settings.shakeWakeThreshold;
|
||||
}
|
||||
|
||||
void setWakeUpMode(WakeUpMode wakeUp, bool enabled) {
|
||||
if (enabled != isWakeUpModeOn(wakeUp)) {
|
||||
settingsChanged = true;
|
||||
|
@ -137,13 +151,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;
|
||||
}
|
||||
|
||||
|
@ -187,8 +201,8 @@ namespace Pinetime {
|
|||
|
||||
PineTimeStyle PTS;
|
||||
|
||||
std::bitset<3> wakeUpMode {0};
|
||||
|
||||
std::bitset<4> wakeUpMode {0};
|
||||
uint16_t shakeWakeThreshold = 150;
|
||||
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ namespace Pinetime {
|
|||
SettingSetDate,
|
||||
SettingSetTime,
|
||||
SettingChimes,
|
||||
Error,
|
||||
SettingShakeThreshold,
|
||||
Error
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "displayapp/screens/settings/SettingSetDate.h"
|
||||
#include "displayapp/screens/settings/SettingSetTime.h"
|
||||
#include "displayapp/screens/settings/SettingChimes.h"
|
||||
#include "displayapp/screens/settings/SettingShakeThreshold.h"
|
||||
|
||||
#include "libs/lv_conf.h"
|
||||
|
||||
|
@ -423,6 +424,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
|||
currentScreen = std::make_unique<Screens::SettingChimes>(this, settingsController);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
break;
|
||||
case Apps::SettingShakeThreshold:
|
||||
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController,motionController,*systemTask);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
break;
|
||||
case Apps::BatteryInfo:
|
||||
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
|
||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
#include "SettingShakeThreshold.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/screens/Symbols.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
namespace {
|
||||
void event_handler(lv_obj_t* obj, lv_event_t event) {
|
||||
SettingShakeThreshold* screen = static_cast<SettingShakeThreshold*>(obj->user_data);
|
||||
screen->UpdateSelected(obj, event);
|
||||
}
|
||||
}
|
||||
|
||||
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
||||
Controllers::Settings& settingsController,
|
||||
Controllers::MotionController& motionController,
|
||||
System::SystemTask& systemTask)
|
||||
: Screen(app), settingsController {settingsController}, motionController {motionController}, systemTask {systemTask} {
|
||||
|
||||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_static(title, "Wake Sensitivity");
|
||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
|
||||
|
||||
positionArc = lv_arc_create(lv_scr_act(), nullptr);
|
||||
positionArc->user_data = this;
|
||||
|
||||
lv_obj_set_event_cb(positionArc, event_handler);
|
||||
lv_arc_set_bg_angles(positionArc, 180, 360);
|
||||
lv_arc_set_range(positionArc, 0, 4095);
|
||||
lv_arc_set_adjustable(positionArc, true);
|
||||
lv_obj_set_width(positionArc, lv_obj_get_width(lv_scr_act()) - 10);
|
||||
lv_obj_set_height(positionArc, 240);
|
||||
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
|
||||
|
||||
animArc = lv_arc_create(positionArc, positionArc);
|
||||
lv_arc_set_adjustable(animArc, false);
|
||||
lv_obj_set_width(animArc, lv_obj_get_width(positionArc));
|
||||
lv_obj_set_height(animArc, lv_obj_get_height(positionArc));
|
||||
lv_obj_align_mid(animArc, positionArc, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_BG, LV_STATE_DEFAULT, 0);
|
||||
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_OPA_70);
|
||||
lv_obj_set_style_local_line_opa(animArc, LV_ARC_PART_KNOB, LV_STATE_DEFAULT, LV_OPA_0);
|
||||
lv_obj_set_style_local_line_color(animArc, LV_ARC_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED);
|
||||
lv_obj_set_style_local_bg_color(animArc, LV_ARC_PART_BG, LV_STATE_CHECKED, LV_COLOR_TRANSP);
|
||||
|
||||
animArc->user_data = this;
|
||||
lv_obj_set_click(animArc, false);
|
||||
|
||||
calButton = lv_btn_create(lv_scr_act(), nullptr);
|
||||
calButton->user_data = this;
|
||||
lv_obj_set_event_cb(calButton, event_handler);
|
||||
lv_obj_set_height(calButton, 80);
|
||||
lv_obj_set_width(calButton, 200);
|
||||
lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
lv_btn_set_checkable(calButton, true);
|
||||
calLabel = lv_label_create(calButton, NULL);
|
||||
lv_label_set_text(calLabel, "Calibrate");
|
||||
|
||||
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
|
||||
|
||||
vDecay = xTaskGetTickCount();
|
||||
calibrating = false;
|
||||
EnableForCal = false;
|
||||
if(!settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)){
|
||||
EnableForCal = true;
|
||||
settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake,true);
|
||||
}
|
||||
refreshTask = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
|
||||
}
|
||||
|
||||
SettingShakeThreshold::~SettingShakeThreshold() {
|
||||
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
||||
|
||||
if(EnableForCal){
|
||||
settingsController.setWakeUpMode(Pinetime::Controllers::Settings::WakeUpMode::Shake,false);
|
||||
EnableForCal = false;
|
||||
}
|
||||
lv_task_del(refreshTask);
|
||||
settingsController.SaveSettings();
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void SettingShakeThreshold::Refresh() {
|
||||
|
||||
if (calibrating == 1) {
|
||||
if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(2000)) {
|
||||
vCalTime = xTaskGetTickCount();
|
||||
calibrating = 2;
|
||||
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED);
|
||||
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_RED);
|
||||
lv_label_set_text(calLabel, "Shake!!");
|
||||
}
|
||||
}
|
||||
if (calibrating == 2) {
|
||||
|
||||
if ((motionController.currentShakeSpeed() - 300) > lv_arc_get_value(positionArc)) {
|
||||
lv_arc_set_value(positionArc, (int16_t) motionController.currentShakeSpeed() - 300);
|
||||
}
|
||||
if (xTaskGetTickCount() - vCalTime > pdMS_TO_TICKS(7500)) {
|
||||
lv_btn_set_state(calButton, LV_STATE_DEFAULT);
|
||||
lv_event_send(calButton, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
}
|
||||
}
|
||||
if (motionController.currentShakeSpeed() - 300 > lv_arc_get_value(animArc)) {
|
||||
lv_arc_set_value(animArc, (uint16_t) motionController.currentShakeSpeed() - 300);
|
||||
vDecay = xTaskGetTickCount();
|
||||
} else if ((xTaskGetTickCount() - vDecay) > pdMS_TO_TICKS(1500)) {
|
||||
lv_arc_set_value(animArc, lv_arc_get_value(animArc) - 25);
|
||||
}
|
||||
}
|
||||
|
||||
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||
|
||||
switch (event) {
|
||||
case LV_EVENT_VALUE_CHANGED: {
|
||||
if (object == calButton) {
|
||||
if (lv_btn_get_state(calButton) == LV_BTN_STATE_CHECKED_RELEASED && calibrating == 0) {
|
||||
lv_arc_set_value(positionArc, 0);
|
||||
calibrating = 1;
|
||||
vCalTime = xTaskGetTickCount();
|
||||
lv_label_set_text(calLabel, "Ready!");
|
||||
lv_obj_set_click(positionArc, false);
|
||||
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN);
|
||||
lv_obj_set_style_local_bg_color(calButton, LV_BTN_PART_MAIN, LV_STATE_CHECKED, LV_COLOR_GREEN);
|
||||
} else if (lv_btn_get_state(calButton) == LV_BTN_STATE_RELEASED) {
|
||||
calibrating = 0;
|
||||
lv_obj_set_click(positionArc, true);
|
||||
lv_label_set_text(calLabel, "Calibrate");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include <components/motion/MotionController.h>
|
||||
namespace Pinetime {
|
||||
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
|
||||
class SettingShakeThreshold : public Screen {
|
||||
public:
|
||||
SettingShakeThreshold(DisplayApp* app,
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
Controllers::MotionController& motionController,
|
||||
System::SystemTask& systemTask);
|
||||
|
||||
~SettingShakeThreshold() override;
|
||||
void Refresh() override;
|
||||
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||
|
||||
private:
|
||||
Controllers::Settings& settingsController;
|
||||
Controllers::MotionController& motionController;
|
||||
System::SystemTask& systemTask;
|
||||
uint8_t calibrating;
|
||||
bool EnableForCal;
|
||||
uint32_t vDecay,vCalTime;
|
||||
lv_obj_t *positionArc, *animArc,*calButton, *calLabel;
|
||||
lv_task_t* refreshTask;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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], " 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() {
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Pinetime {
|
|||
private:
|
||||
Controllers::Settings& settingsController;
|
||||
uint8_t optionsTotal;
|
||||
lv_obj_t* cbOption[4];
|
||||
lv_obj_t* cbOption[5];
|
||||
// When UpdateSelected is called, it uses lv_checkbox_set_checked,
|
||||
// which can cause extra events to be fired,
|
||||
// which might trigger UpdateSelected again, causing a loop.
|
||||
|
|
|
@ -47,12 +47,10 @@ std::unique_ptr<Screen> Settings::CreateScreen1() {
|
|||
|
||||
std::unique_ptr<Screen> Settings::CreateScreen2() {
|
||||
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
{Symbols::shoe, "Steps", Apps::SettingSteps},
|
||||
std::array<Screens::List::Applications, 4> applications {{{Symbols::shoe, "Steps", Apps::SettingSteps},
|
||||
{Symbols::clock, "Set date", Apps::SettingSetDate},
|
||||
{Symbols::clock, "Set time", Apps::SettingSetTime},
|
||||
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo}
|
||||
}};
|
||||
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo}}};
|
||||
|
||||
return std::make_unique<Screens::List>(1, 3, app, settingsController, applications);
|
||||
}
|
||||
|
@ -60,11 +58,10 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
|
|||
std::unique_ptr<Screen> Settings::CreateScreen3() {
|
||||
|
||||
std::array<Screens::List::Applications, 4> applications {{
|
||||
|
||||
{Symbols::clock, "Chimes", Apps::SettingChimes},
|
||||
{Symbols::none, "Wake Sense", Apps::SettingShakeThreshold},
|
||||
{Symbols::check, "Firmware", Apps::FirmwareValidation},
|
||||
{Symbols::list, "About", Apps::SysInfo},
|
||||
{Symbols::none, "None", Apps::None}
|
||||
{Symbols::list, "About", Apps::SysInfo}
|
||||
}};
|
||||
|
||||
return std::make_unique<Screens::List>(2, 3, app, settingsController, applications);
|
||||
|
|
|
@ -347,13 +347,13 @@ void SystemTask::Work() {
|
|||
doNotGoToSleep = true;
|
||||
if (isSleeping && !isWakingUp)
|
||||
GoToRunning();
|
||||
//TODO add intent of fs access icon or something
|
||||
// TODO add intent of fs access icon or something
|
||||
break;
|
||||
case Messages::StopFileTransfer:
|
||||
NRF_LOG_INFO("[systemtask] FS Stopped");
|
||||
doNotGoToSleep = false;
|
||||
xTimerStart(dimTimer, 0);
|
||||
//TODO add intent of fs access icon or something
|
||||
// TODO add intent of fs access icon or something
|
||||
break;
|
||||
case Messages::OnTouchEvent:
|
||||
if (touchHandler.GetNewTouchInfo()) {
|
||||
|
@ -477,10 +477,10 @@ void SystemTask::UpdateMotion() {
|
|||
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;
|
||||
}
|
||||
|
||||
if (stepCounterMustBeReset) {
|
||||
motionSensor.ResetStepCounter();
|
||||
stepCounterMustBeReset = false;
|
||||
|
@ -490,7 +490,13 @@ void SystemTask::UpdateMotion() {
|
|||
|
||||
motionController.IsSensorOk(motionSensor.IsOk());
|
||||
motionController.Update(motionValues.x, motionValues.y, motionValues.z, motionValues.steps);
|
||||
if (motionController.ShouldWakeUp(isSleeping)) {
|
||||
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::RaiseWrist) &&
|
||||
motionController.Should_RaiseWake(isSleeping)) {
|
||||
GoToRunning();
|
||||
}
|
||||
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
|
||||
motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) {
|
||||
GoToRunning();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue