Better Sensitivity UI, Calibration button added
This commit is contained in:
parent
6d74820698
commit
d2510d7926
|
@ -1,6 +1,5 @@
|
||||||
#include "components/motion/MotionController.h"
|
#include "components/motion/MotionController.h"
|
||||||
#include "os/os_cputime.h"
|
#include "os/os_cputime.h"
|
||||||
|
|
||||||
using namespace Pinetime::Controllers;
|
using namespace Pinetime::Controllers;
|
||||||
|
|
||||||
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
|
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) {
|
||||||
bool wake = false;
|
bool wake = false;
|
||||||
auto diff = xTaskGetTickCount() - lastShakeTime;
|
auto diff = xTaskGetTickCount() - lastShakeTime;
|
||||||
lastShakeTime = xTaskGetTickCount();
|
lastShakeTime = xTaskGetTickCount();
|
||||||
int32_t speed = std::abs(y + z - lastYForShake - lastZForShake) / diff * 10;
|
int32_t speed = std::abs(z + (y/2) + (x/4)- lastYForShake - lastZForShake) / diff * 100;
|
||||||
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
|
//(.2 * speed) + ((1 - .2) * accumulatedspeed);
|
||||||
//implemented without floats as .25Alpha
|
//implemented without floats as .25Alpha
|
||||||
accumulatedspeed = (speed/4) + ((accumulatedspeed/4)*3);
|
accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4);
|
||||||
|
|
||||||
if (accumulatedspeed > thresh) {
|
if (accumulatedspeed > thresh) {
|
||||||
wake = true;
|
wake = true;
|
||||||
}
|
}
|
||||||
lastXForShake = x;
|
lastXForShake = x/4;
|
||||||
lastYForShake = y;
|
lastYForShake = y/2;
|
||||||
lastZForShake = z;
|
lastZForShake = z;
|
||||||
return wake;
|
return wake;
|
||||||
}
|
}
|
||||||
|
int32_t MotionController::currentShakeSpeed(){
|
||||||
|
return accumulatedspeed;
|
||||||
|
}
|
||||||
|
|
||||||
void MotionController::IsSensorOk(bool isOk) {
|
void MotionController::IsSensorOk(bool isOk) {
|
||||||
isSensorOk = isOk;
|
isSensorOk = isOk;
|
||||||
|
|
|
@ -38,7 +38,7 @@ namespace Pinetime {
|
||||||
|
|
||||||
bool Should_ShakeWake(uint16_t thresh);
|
bool Should_ShakeWake(uint16_t thresh);
|
||||||
bool Should_RaiseWake(bool isSleeping);
|
bool Should_RaiseWake(bool isSleeping);
|
||||||
|
int32_t currentShakeSpeed();
|
||||||
void IsSensorOk(bool isOk);
|
void IsSensorOk(bool isOk);
|
||||||
bool IsSensorOk() const {
|
bool IsSensorOk() const {
|
||||||
return isSensorOk;
|
return isSensorOk;
|
||||||
|
|
|
@ -136,8 +136,7 @@ namespace Pinetime {
|
||||||
case WakeUpMode::DoubleTap:
|
case WakeUpMode::DoubleTap:
|
||||||
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
|
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
|
||||||
break;
|
break;
|
||||||
case WakeUpMode::RaiseWrist:
|
default:
|
||||||
case WakeUpMode::Shake:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,7 +417,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||||
break;
|
break;
|
||||||
case Apps::SettingShakeThreshold:
|
case Apps::SettingShakeThreshold:
|
||||||
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController);
|
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController,motionController,*systemTask);
|
||||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||||
break;
|
break;
|
||||||
case Apps::BatteryInfo:
|
case Apps::BatteryInfo:
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "displayapp/screens/Symbols.h"
|
#include "displayapp/screens/Symbols.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -13,61 +14,48 @@ namespace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingShakeThreshold::SettingShakeThreshold(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
|
SettingShakeThreshold::SettingShakeThreshold(DisplayApp* app,
|
||||||
: Screen(app), settingsController {settingsController} {
|
Controllers::Settings& settingsController,
|
||||||
|
Controllers::MotionController& motionController,
|
||||||
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
|
System::SystemTask& systemTask)
|
||||||
|
: Screen(app),
|
||||||
// lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
|
settingsController {settingsController},
|
||||||
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
motionController {motionController},
|
||||||
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
|
systemTask {systemTask} {
|
||||||
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_width(container1, LV_HOR_RES - 20);
|
|
||||||
lv_obj_set_height(container1, LV_VER_RES - 50);
|
|
||||||
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
|
|
||||||
|
|
||||||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
||||||
lv_label_set_text_static(title, "Shake Threshold");
|
lv_label_set_text_static(title, "Shake Threshold");
|
||||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||||
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15);
|
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, 0);
|
||||||
|
|
||||||
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
|
|
||||||
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
|
||||||
lv_label_set_text_static(icon, Symbols::home);
|
|
||||||
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
|
|
||||||
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
|
|
||||||
|
|
||||||
optionsTotal = 0;
|
positionArc = lv_arc_create(lv_scr_act(), nullptr);
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
// Why do this?
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " High");
|
positionArc->user_data = this;
|
||||||
cbOption[optionsTotal]->user_data = this;
|
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
|
||||||
if (settingsController.GetShakeThreshold() == 150) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
|
||||||
|
|
||||||
optionsTotal++;
|
lv_obj_set_event_cb(positionArc, event_handler);
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
// lv_arc_set_start_angle(positionArc,270);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Medium");
|
lv_arc_set_angles(positionArc, 180, 360);
|
||||||
cbOption[optionsTotal]->user_data = this;
|
lv_arc_set_bg_angles(positionArc, 180, 360);
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
|
||||||
if (settingsController.GetShakeThreshold() == 300) {
|
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
|
||||||
|
|
||||||
optionsTotal++;
|
// lv_arc_set_rotation(positionArc, 135);
|
||||||
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
|
lv_arc_set_range(positionArc, 10, 4095);
|
||||||
lv_checkbox_set_text_static(cbOption[optionsTotal], " Low");
|
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
|
||||||
cbOption[optionsTotal]->user_data = this;
|
lv_obj_set_size(positionArc, 240, 180);
|
||||||
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
|
lv_arc_set_adjustable(positionArc, false);
|
||||||
if (settingsController.GetShakeThreshold() == 450) {
|
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
|
||||||
lv_checkbox_set_checked(cbOption[optionsTotal], true);
|
|
||||||
}
|
calButton = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
calButton->user_data = this;
|
||||||
|
lv_obj_set_event_cb(calButton, event_handler);
|
||||||
|
lv_btn_set_fit(calButton, LV_FIT_TIGHT);
|
||||||
|
|
||||||
|
// lv_obj_set_style_local_bg_opa(calButton, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
||||||
|
lv_obj_set_height(calButton, 80);
|
||||||
|
lv_obj_align(calButton, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||||
|
calLabel = lv_label_create(calButton, NULL);
|
||||||
|
lv_label_set_text(calLabel, "Calibrate");
|
||||||
|
|
||||||
optionsTotal++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingShakeThreshold::~SettingShakeThreshold() {
|
SettingShakeThreshold::~SettingShakeThreshold() {
|
||||||
|
@ -75,15 +63,33 @@ SettingShakeThreshold::~SettingShakeThreshold() {
|
||||||
settingsController.SaveSettings();
|
settingsController.SaveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingShakeThreshold::Refresh() {
|
||||||
|
|
||||||
|
taskCount++; //100ms Update time so finish @100
|
||||||
|
if((motionController.currentShakeSpeed()-200) > lv_arc_get_value(positionArc)){
|
||||||
|
lv_arc_set_value(positionArc,(int16_t)motionController.currentShakeSpeed()-200);
|
||||||
|
}
|
||||||
|
if(taskCount >= 100){
|
||||||
|
lv_label_set_text(calLabel, "Calibrate");
|
||||||
|
lv_task_del(refreshTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
void SettingShakeThreshold::UpdateSelected(lv_obj_t* object, lv_event_t event) {
|
||||||
if (event == LV_EVENT_VALUE_CHANGED) {
|
|
||||||
for (uint8_t i = 0; i < optionsTotal; i++) {
|
switch (event) {
|
||||||
if (object == cbOption[i]) {
|
case LV_EVENT_PRESSED: {
|
||||||
lv_checkbox_set_checked(cbOption[i], true);
|
taskCount = 0;
|
||||||
settingsController.SetShakeThreshold((i+1)*150);
|
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
|
||||||
} else {
|
lv_label_set_text(calLabel, "Shake!!!");
|
||||||
lv_checkbox_set_checked(cbOption[i], false);
|
break;
|
||||||
}
|
}
|
||||||
|
case LV_EVENT_VALUE_CHANGED: {
|
||||||
|
if (object == positionArc) {
|
||||||
|
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
|
#include <components/motion/MotionController.h>
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
|
||||||
namespace Applications {
|
namespace Applications {
|
||||||
|
@ -12,15 +12,27 @@ namespace Pinetime {
|
||||||
|
|
||||||
class SettingShakeThreshold : public Screen {
|
class SettingShakeThreshold : public Screen {
|
||||||
public:
|
public:
|
||||||
SettingShakeThreshold(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
|
SettingShakeThreshold(DisplayApp* app,
|
||||||
~SettingShakeThreshold() override;
|
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);
|
void UpdateSelected(lv_obj_t* object, lv_event_t event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Controllers::Settings& settingsController;
|
Controllers::Settings& settingsController;
|
||||||
uint8_t optionsTotal;
|
Controllers::MotionController& motionController;
|
||||||
|
System::SystemTask& systemTask;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t taskCount;
|
||||||
lv_obj_t* cbOption[2];
|
lv_obj_t* cbOption[2];
|
||||||
|
lv_obj_t *positionArc, *calButton, *calLabel;
|
||||||
|
lv_task_t* refreshTask;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user