Skip to content

Commit 3ebf002

Browse files
committed
Add start of settings app for senstivity.
really just debugging. I want to make it more configurable then high med low. Position of setting needs a new location...dynamicly adding it currently at the end. Which honestly im fine with.
1 parent ad42cdf commit 3ebf002

10 files changed

Lines changed: 145 additions & 8 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ list(APPEND SOURCE_FILES
447447
displayapp/screens/settings/SettingSteps.cpp
448448
displayapp/screens/settings/SettingSetDate.cpp
449449
displayapp/screens/settings/SettingSetTime.cpp
450+
displayapp/screens/settings/SettingShakeThreshold.cpp
450451

451452
## Watch faces
452453
displayapp/icons/bg_clock.c

src/components/motion/MotionController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ bool MotionController::Should_RaiseWake(bool isSleeping) {
4545
return false;
4646
}
4747

48-
bool MotionController::Should_ShakeWake() {
48+
bool MotionController::Should_ShakeWake(uint16_t thresh) {
4949
bool wake = false;
5050
auto diff = xTaskGetTickCount() - lastShakeTime;
5151
lastShakeTime = xTaskGetTickCount();
5252
int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10;
53-
if (speed > 150) { // TODO move threshold to a setting
53+
if (speed > thresh) {
5454
wake = true;
5555
}
5656
lastXForShake = x;

src/components/motion/MotionController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ namespace Pinetime {
3535
uint32_t GetTripSteps() const {
3636
return currentTripSteps;
3737
}
38-
bool Should_ShakeWake();
38+
39+
bool Should_ShakeWake(uint16_t thresh);
3940
bool Should_RaiseWake(bool isSleeping);
4041

4142
void IsSensorOk(bool isOk);

src/components/settings/Settings.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,19 @@ namespace Pinetime {
109109
}
110110
settings.screenTimeOut = timeout;
111111
};
112+
112113
uint32_t GetScreenTimeOut() const {
113114
return settings.screenTimeOut;
114115
};
115116

117+
void SetShakeThreshold(uint16_t thresh){
118+
settings.shakeWakeThreshold = thresh;
119+
}
120+
121+
int16_t GetShakeThreshold() const{
122+
return settings.shakeWakeThreshold;
123+
}
124+
116125
void setWakeUpMode(WakeUpMode wakeUp, bool enabled) {
117126
if (enabled != isWakeUpModeOn(wakeUp)) {
118127
settingsChanged = true;
@@ -164,7 +173,7 @@ namespace Pinetime {
164173
private:
165174
Pinetime::Controllers::FS& fs;
166175

167-
static constexpr uint32_t settingsVersion = 0x0003;
176+
static constexpr uint32_t settingsVersion = 0x0004;
168177
struct SettingsData {
169178
uint32_t version = settingsVersion;
170179
uint32_t stepsGoal = 10000;
@@ -178,7 +187,7 @@ namespace Pinetime {
178187
PineTimeStyle PTS;
179188

180189
std::bitset<4> wakeUpMode {0};
181-
190+
uint16_t shakeWakeThreshold = 300;
182191
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
183192
};
184193

src/displayapp/Apps.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ namespace Pinetime {
3636
SettingSteps,
3737
SettingSetDate,
3838
SettingSetTime,
39-
Error,
39+
SettingShakeThreshold,
40+
Error
41+
4042
};
4143
}
4244
}

src/displayapp/DisplayApp.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "displayapp/screens/settings/SettingSteps.h"
4848
#include "displayapp/screens/settings/SettingSetDate.h"
4949
#include "displayapp/screens/settings/SettingSetTime.h"
50+
#include "displayapp/screens/settings/SettingShakeThreshold.h"
5051

5152
#include "libs/lv_conf.h"
5253

@@ -415,6 +416,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
415416
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController);
416417
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
417418
break;
419+
case Apps::SettingShakeThreshold:
420+
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController);
421+
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
422+
break;
418423
case Apps::BatteryInfo:
419424
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
420425
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "SettingShakeThreshold.h"
2+
#include <lvgl/lvgl.h>
3+
#include "displayapp/DisplayApp.h"
4+
#include "displayapp/screens/Screen.h"
5+
#include "displayapp/screens/Symbols.h"
6+
7+
using namespace Pinetime::Applications::Screens;
8+
9+
namespace {
10+
static void event_handler(lv_obj_t* obj, lv_event_t event) {
11+
SettingShakeThreshold* screen = static_cast<SettingShakeThreshold*>(obj->user_data);
12+
screen->UpdateSelected(obj, event);
13+
}
14+
}
15+
16+
SettingShakeThreshold::SettingShakeThreshold(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
17+
: Screen(app), settingsController {settingsController} {
18+
19+
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
20+
21+
// lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
22+
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
23+
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
24+
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
25+
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
26+
27+
lv_obj_set_pos(container1, 10, 60);
28+
lv_obj_set_width(container1, LV_HOR_RES - 20);
29+
lv_obj_set_height(container1, LV_VER_RES - 50);
30+
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
31+
32+
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
33+
lv_label_set_text_static(title, "Shake Threshold");
34+
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
35+
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15);
36+
37+
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
38+
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
39+
lv_label_set_text_static(icon, Symbols::home);
40+
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
41+
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
42+
43+
optionsTotal = 0;
44+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
45+
lv_checkbox_set_text_static(cbOption[optionsTotal], " High");
46+
cbOption[optionsTotal]->user_data = this;
47+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
48+
if (settingsController.GetShakeThreshold() == 150) {
49+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
50+
}
51+
52+
optionsTotal++;
53+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
54+
lv_checkbox_set_text_static(cbOption[optionsTotal], " Medium");
55+
cbOption[optionsTotal]->user_data = this;
56+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
57+
if (settingsController.GetShakeThreshold() == 300) {
58+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
59+
}
60+
61+
optionsTotal++;
62+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
63+
lv_checkbox_set_text_static(cbOption[optionsTotal], " Low");
64+
cbOption[optionsTotal]->user_data = this;
65+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
66+
if (settingsController.GetShakeThreshold() == 450) {
67+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
68+
}
69+
70+
optionsTotal++;
71+
}
72+
73+
SettingShakeThreshold::~SettingShakeThreshold() {
74+
lv_obj_clean(lv_scr_act());
75+
settingsController.SaveSettings();
76+
}
77+
78+
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
79+
if (event == LV_EVENT_VALUE_CHANGED) {
80+
for (uint8_t i = 0; i < optionsTotal; i++) {
81+
if (object == cbOption[i]) {
82+
lv_checkbox_set_checked(cbOption[i], true);
83+
settingsController.SetShakeThreshold((i+1)*150);
84+
} else {
85+
lv_checkbox_set_checked(cbOption[i], false);
86+
}
87+
}
88+
}
89+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <lvgl/lvgl.h>
5+
#include "components/settings/Settings.h"
6+
#include "displayapp/screens/Screen.h"
7+
8+
namespace Pinetime {
9+
10+
namespace Applications {
11+
namespace Screens {
12+
13+
class SettingShakeThreshold : public Screen {
14+
public:
15+
SettingShakeThreshold(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
16+
~SettingShakeThreshold() override;
17+
18+
void UpdateSelected(lv_obj_t* object, lv_event_t event);
19+
20+
private:
21+
Controllers::Settings& settingsController;
22+
uint8_t optionsTotal;
23+
lv_obj_t* cbOption[2];
24+
};
25+
}
26+
}
27+
}

src/displayapp/screens/settings/Settings.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ std::unique_ptr<Screen> Settings::CreateScreen3() {
6565
{Symbols::none, "None", Apps::None},
6666
{Symbols::none, "None", Apps::None}
6767
}};
68-
68+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake)) {
69+
applications[1] = {Symbols::list, "Shake Threshold", Apps::SettingShakeThreshold};
70+
}
6971
return std::make_unique<Screens::List>(2, 3, app, settingsController, applications);
7072
}

src/systemtask/SystemTask.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ void SystemTask::UpdateMotion() {
475475
motionController.Should_RaiseWake(isSleeping)) {
476476
GoToRunning();
477477
}
478-
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) && motionController.Should_ShakeWake()) {
478+
if (settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::Shake) &&
479+
motionController.Should_ShakeWake(settingsController.GetShakeThreshold())) {
479480
GoToRunning();
480481
}
481482
}

0 commit comments

Comments
 (0)