Better Sensitivity UI, Calibration button added

This commit is contained in:
Tim Keller 2021-09-28 03:50:08 +00:00
parent 6d74820698
commit d2510d7926
6 changed files with 89 additions and 69 deletions

View file

@ -1,6 +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) {
@ -49,18 +48,22 @@ bool MotionController::Should_ShakeWake(uint16_t thresh) {
bool wake = false;
auto diff = xTaskGetTickCount() - lastShakeTime;
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);
//implemented without floats as .25Alpha
accumulatedspeed = (speed/4) + ((accumulatedspeed/4)*3);
accumulatedspeed = (speed/5) + ((accumulatedspeed/5)*4);
if (accumulatedspeed > thresh) {
wake = true;
}
lastXForShake = x;
lastYForShake = y;
lastXForShake = x/4;
lastYForShake = y/2;
lastZForShake = z;
return wake;
}
int32_t MotionController::currentShakeSpeed(){
return accumulatedspeed;
}
void MotionController::IsSensorOk(bool isOk) {
isSensorOk = isOk;

View file

@ -38,7 +38,7 @@ namespace Pinetime {
bool Should_ShakeWake(uint16_t thresh);
bool Should_RaiseWake(bool isSleeping);
int32_t currentShakeSpeed();
void IsSensorOk(bool isOk);
bool IsSensorOk() const {
return isSensorOk;

View file

@ -136,8 +136,7 @@ namespace Pinetime {
case WakeUpMode::DoubleTap:
settings.wakeUpMode.set(static_cast<size_t>(WakeUpMode::SingleTap), false);
break;
case WakeUpMode::RaiseWrist:
case WakeUpMode::Shake:
default:
break;
}
}

View file

@ -417,7 +417,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
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);
break;
case Apps::BatteryInfo:

View file

@ -4,6 +4,7 @@
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"
using namespace Pinetime::Applications::Screens;
namespace {
@ -13,77 +14,82 @@ namespace {
}
}
SettingShakeThreshold::SettingShakeThreshold(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
: Screen(app), settingsController {settingsController} {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
// lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111));
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
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);
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, "Shake Threshold");
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;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " High");
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);
positionArc = lv_arc_create(lv_scr_act(), nullptr);
// Why do this?
positionArc->user_data = this;
lv_obj_set_event_cb(positionArc, event_handler);
// lv_arc_set_start_angle(positionArc,270);
lv_arc_set_angles(positionArc, 180, 360);
lv_arc_set_bg_angles(positionArc, 180, 360);
// lv_arc_set_rotation(positionArc, 135);
lv_arc_set_range(positionArc, 10, 4095);
lv_arc_set_value(positionArc, settingsController.GetShakeThreshold());
lv_obj_set_size(positionArc, 240, 180);
lv_arc_set_adjustable(positionArc, false);
lv_obj_align(positionArc, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 10);
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++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Medium");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetShakeThreshold() == 300) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text_static(cbOption[optionsTotal], " Low");
cbOption[optionsTotal]->user_data = this;
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
if (settingsController.GetShakeThreshold() == 450) {
lv_checkbox_set_checked(cbOption[optionsTotal], true);
}
optionsTotal++;
}
SettingShakeThreshold::~SettingShakeThreshold() {
lv_obj_clean(lv_scr_act());
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) {
if (event == LV_EVENT_VALUE_CHANGED) {
for (uint8_t i = 0; i < optionsTotal; i++) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);
settingsController.SetShakeThreshold((i+1)*150);
} else {
lv_checkbox_set_checked(cbOption[i], false);
switch (event) {
case LV_EVENT_PRESSED: {
taskCount = 0;
refreshTask = lv_task_create(RefreshTaskCallback, 100, LV_TASK_PRIO_MID, this);
lv_label_set_text(calLabel, "Shake!!!");
break;
}
case LV_EVENT_VALUE_CHANGED: {
if (object == positionArc) {
settingsController.SetShakeThreshold(lv_arc_get_value(positionArc));
}
break;
}
}
}

View file

@ -4,7 +4,7 @@
#include <lvgl/lvgl.h>
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include <components/motion/MotionController.h>
namespace Pinetime {
namespace Applications {
@ -12,15 +12,27 @@ namespace Pinetime {
class SettingShakeThreshold : public Screen {
public:
SettingShakeThreshold(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
~SettingShakeThreshold() override;
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;
uint8_t optionsTotal;
Controllers::MotionController& motionController;
System::SystemTask& systemTask;
uint8_t taskCount;
lv_obj_t* cbOption[2];
lv_obj_t *positionArc, *calButton, *calLabel;
lv_task_t* refreshTask;
};
}
}