Skip to content

Commit d2510d7

Browse files
committed
Better Sensitivity UI, Calibration button added
1 parent 6d74820 commit d2510d7

6 files changed

Lines changed: 89 additions & 69 deletions

File tree

src/components/motion/MotionController.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "components/motion/MotionController.h"
22
#include "os/os_cputime.h"
3-
43
using namespace Pinetime::Controllers;
54

65
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
@@ -49,18 +48,22 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
4948
bool wake = false;
5049
auto diff = xTaskGetTickCount() - lastShakeTime;
5150
lastShakeTime = xTaskGetTickCount();
52-
int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10;
51+
int32_t speed = std::abs(z + (y/2) + (x/4)- lastYForShake - lastZForShake) / diff * 100;
5352
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
5453
//implemented without floats as .25Alpha
55-
accumulatedspeed = (speed/4) + ((accumulatedspeed/4)*3);
54+
accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4);
55+
5656
if (accumulatedspeed > thresh) {
5757
wake = true;
5858
}
59-
lastXForShake = x;
60-
lastYForShake = y;
59+
lastXForShake = x/4;
60+
lastYForShake = y/2;
6161
lastZForShake = z;
6262
return wake;
6363
}
64+
int32_t MotionController::currentShakeSpeed(){
65+
return accumulatedspeed;
66+
}
6467

6568
void MotionController::IsSensorOk(bool isOk) {
6669
isSensorOk = isOk;

src/components/motion/MotionController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Pinetime {
3838

3939
bool Should_ShakeWake(uint16_t thresh);
4040
bool Should_RaiseWake(bool isSleeping);
41-
41+
int32_t currentShakeSpeed();
4242
void IsSensorOk(bool isOk);
4343
bool IsSensorOk() const {
4444
return isSensorOk;

src/components/settings/Settings.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ namespace Pinetime {
136136
case WakeUpMode::DoubleTap:
137137
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
138138
break;
139-
case WakeUpMode::RaiseWrist:
140-
case WakeUpMode::Shake:
139+
default:
141140
break;
142141
}
143142
}

src/displayapp/DisplayApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
417417
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
418418
break;
419419
case Apps::SettingShakeThreshold:
420-
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController);
420+
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController,motionController,*systemTask);
421421
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
422422
break;
423423
case Apps::BatteryInfo:

src/displayapp/screens/settings/SettingShakeThreshold.cpp

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "displayapp/screens/Screen.h"
55
#include "displayapp/screens/Symbols.h"
66

7+
78
using namespace Pinetime::Applications::Screens;
89

910
namespace {
@@ -13,77 +14,82 @@ namespace {
1314
}
1415
}
1516

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);
17+
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
18+
Controllers::Settings& settingsController,
19+
Controllers::MotionController& motionController,
20+
System::SystemTask& systemTask)
21+
: Screen(app),
22+
settingsController {settingsController},
23+
motionController {motionController},
24+
systemTask {systemTask} {
3125

3226
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
3327
lv_label_set_text_static(title, "Shake Threshold");
3428
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-
}
29+
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
5130

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-
}
6031

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-
}
32+
positionArc = lv_arc_create(lv_scr_act(), nullptr);
33+
// Why do this?
34+
positionArc->user_data = this;
6935

70-
optionsTotal++;
71-
}
36+
lv_obj_set_event_cb(positionArc, event_handler);
37+
// lv_arc_set_start_angle(positionArc,270);
38+
lv_arc_set_angles(positionArc, 180, 360);
39+
lv_arc_set_bg_angles(positionArc, 180, 360);
40+
41+
// lv_arc_set_rotation(positionArc, 135);
42+
lv_arc_set_range(positionArc, 10, 4095);
43+
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
44+
lv_obj_set_size(positionArc, 240, 180);
45+
lv_arc_set_adjustable(positionArc, false);
46+
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
47+
48+
calButton = lv_btn_create(lv_scr_act(), nullptr);
49+
calButton->user_data = this;
50+
lv_obj_set_event_cb(calButton, event_handler);
51+
lv_btn_set_fit(calButton, LV_FIT_TIGHT);
52+
53+
// lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
54+
lv_obj_set_height(calButton, 80);
55+
lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
56+
calLabel = lv_label_create(calButton, NULL);
57+
lv_label_set_text(calLabel, "Calibrate");
58+
59+
}
7260

7361
SettingShakeThreshold::~SettingShakeThreshold() {
7462
lv_obj_clean(lv_scr_act());
7563
settingsController.SaveSettings();
7664
}
7765

66+
void SettingShakeThreshold::Refresh() {
67+
68+
taskCount++; //100ms Update time so finish @100
69+
if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){
70+
lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200);
71+
}
72+
if(taskCount >= 100){
73+
lv_label_set_text(calLabel, "Calibrate");
74+
lv_task_del(refreshTask);
75+
}
76+
77+
}
78+
7879
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);
80+
81+
switch (event) {
82+
case LV_EVENT_PRESSED: {
83+
taskCount = 0;
84+
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
85+
lv_label_set_text(calLabel, "Shake!!!");
86+
break;
87+
}
88+
case LV_EVENT_VALUE_CHANGED: {
89+
if (object == positionArc) {
90+
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
8691
}
92+
break;
8793
}
8894
}
8995
}

src/displayapp/screens/settings/SettingShakeThreshold.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,35 @@
44
#include <lvgl/lvgl.h>
55
#include "components/settings/Settings.h"
66
#include "displayapp/screens/Screen.h"
7-
7+
#include <components/motion/MotionController.h>
88
namespace Pinetime {
99

1010
namespace Applications {
1111
namespace Screens {
1212

1313
class SettingShakeThreshold : public Screen {
1414
public:
15-
SettingShakeThreshold(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
16-
~SettingShakeThreshold() override;
15+
SettingShakeThreshold(DisplayApp* app,
16+
Pinetime::Controllers::Settings& settingsController,
17+
Controllers::MotionController& motionController,
18+
System::SystemTask& systemTask);
1719

20+
~SettingShakeThreshold() override;
21+
void Refresh() override;
1822
void UpdateSelected(lv_obj_t* object, lv_event_t event);
1923

2024
private:
2125
Controllers::Settings& settingsController;
22-
uint8_t optionsTotal;
26+
Controllers::MotionController& motionController;
27+
System::SystemTask& systemTask;
28+
29+
30+
31+
32+
uint8_t taskCount;
2333
lv_obj_t* cbOption[2];
34+
lv_obj_t *positionArc, *calButton, *calLabel;
35+
lv_task_t* refreshTask;
2436
};
2537
}
2638
}

0 commit comments

Comments
 (0)