First integration of the motion sensor (bma 421) : step counting + wake on wrist rotation + app to see the value of the 3 axis in "real time".

This commit is contained in:
Jean-François Milants
2021-03-31 19:47:27 +02:00
parent 04fc33e2d4
commit 68bdaee1cc
27 changed files with 12344 additions and 26 deletions

View File

@@ -45,7 +45,7 @@ bool ApplicationList::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
std::array<Screens::Tile::Applications, 6> applications {
{{Symbols::clock, Apps::Clock},
{{Symbols::info, Apps::Notifications},
{Symbols::music, Apps::Music},
{Symbols::sun, Apps::Brightness},
{Symbols::list, Apps::SysInfo},
@@ -64,7 +64,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
{{Symbols::map, Apps::Navigation},
{Symbols::stopWatch, Apps::StopWatch},
{Symbols::paintbrush, Apps::Paint},
{Symbols::info, Apps::Notifications},
{Symbols::shoe, Apps::Motion},
{Symbols::paddle, Apps::Paddle},
{"2", Apps::Twos}
}

View File

@@ -8,6 +8,7 @@
#include "NotificationIcon.h"
#include "Symbols.h"
#include "components/battery/BatteryController.h"
#include "components/motion/MotionController.h"
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "../DisplayApp.h"
@@ -23,12 +24,14 @@ Clock::Clock(DisplayApp* app,
Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager,
Controllers::Settings &settingsController,
Controllers::HeartRateController& heartRateController) : Screen(app),
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController) : Screen(app),
dateTimeController{dateTimeController}, batteryController{batteryController},
bleController{bleController}, notificatioManager{notificatioManager},
settingsController{settingsController},
heartRateController{heartRateController},
screens{app,
motionController{motionController},
screens{app,
settingsController.GetClockFace(),
{
[this]() -> std::unique_ptr<Screen> { return WatchFaceDigitalScreen(); },
@@ -64,7 +67,7 @@ bool Clock::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
}
std::unique_ptr<Screen> Clock::WatchFaceDigitalScreen() {
return std::make_unique<Screens::WatchFaceDigital>(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController, heartRateController);
return std::make_unique<Screens::WatchFaceDigital>(app, dateTimeController, batteryController, bleController, notificatioManager, settingsController, heartRateController, motionController);
}
std::unique_ptr<Screen> Clock::WatchFaceAnalogScreen() {

View File

@@ -17,6 +17,7 @@ namespace Pinetime {
class Battery;
class Ble;
class NotificationManager;
class MotionController;
}
namespace Applications {
@@ -29,7 +30,8 @@ namespace Pinetime {
Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager,
Controllers::Settings &settingsController,
Controllers::HeartRateController& heartRateController);
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController);
~Clock() override;
bool Refresh() override;
@@ -44,6 +46,7 @@ namespace Pinetime {
Controllers::NotificationManager& notificatioManager;
Controllers::Settings& settingsController;
Controllers::HeartRateController& heartRateController;
Controllers::MotionController& motionController;
ScreenList<2> screens;

View File

@@ -0,0 +1,59 @@
#include <libs/lvgl/lvgl.h>
#include "Motion.h"
#include "../DisplayApp.h"
using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressed;
extern lv_font_t jetbrains_mono_bold_20;
Motion::Motion(Pinetime::Applications::DisplayApp *app, Controllers::MotionController& motionController) : Screen(app), motionController{motionController} {
chart = lv_chart_create(lv_scr_act(), NULL);
lv_obj_set_size(chart, 240, 240);
lv_obj_align(chart, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
//lv_chart_set_series_opa(chart, LV_OPA_70); /*Opacity of the data series*/
//lv_chart_set_series_width(chart, 4); /*Line width and point radious*/
lv_chart_set_range(chart, -1100, 1100);
lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT);
lv_chart_set_point_count(chart, 10);
/*Add 3 data series*/
ser1 = lv_chart_add_series(chart, LV_COLOR_RED);
ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN);
ser3 = lv_chart_add_series(chart, LV_COLOR_YELLOW);
lv_chart_init_points(chart, ser1, 0);
lv_chart_init_points(chart, ser2, 0);
lv_chart_init_points(chart, ser3, 0);
lv_chart_refresh(chart); /*Required after direct set*/
labelStep = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(labelStep, chart, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_label_set_text(labelStep, "Steps: ");
labelStepValue = lv_label_create(lv_scr_act(), NULL);
lv_obj_align(labelStepValue, labelStep, LV_ALIGN_OUT_RIGHT_MID, 0, 0);
lv_label_set_text(labelStepValue, "-");
}
Motion::~Motion() {
lv_obj_clean(lv_scr_act());
}
bool Motion::Refresh() {
lv_chart_set_next(chart, ser1, motionController.X());
lv_chart_set_next(chart, ser2, motionController.Y());
lv_chart_set_next(chart, ser3, motionController.Z());
snprintf(nbStepsBuffer, nbStepsBufferSize, "%lu", motionController.NbSteps());
lv_label_set_text(labelStepValue, nbStepsBuffer);
return running;
}
bool Motion::OnButtonPushed() {
running = false;
return true;
}

View File

@@ -0,0 +1,39 @@
#pragma once
#include <cstdint>
#include <chrono>
#include "Screen.h"
#include <bits/unique_ptr.h>
#include <libs/lvgl/src/lv_core/lv_style.h>
#include <libs/lvgl/src/lv_core/lv_obj.h>
#include <components/motion/MotionController.h>
namespace Pinetime {
namespace Applications {
namespace Screens {
class Motion : public Screen{
public:
Motion(DisplayApp* app, Controllers::MotionController& motionController);
~Motion() override;
bool Refresh() override;
bool OnButtonPushed() override;
private:
Controllers::MotionController& motionController;
lv_obj_t * chart;
lv_chart_series_t * ser1;
lv_chart_series_t * ser2;
lv_chart_series_t * ser3;
lv_obj_t* labelStep;
lv_obj_t* labelStepValue;
static constexpr uint8_t nbStepsBufferSize = 9;
char nbStepsBuffer[nbStepsBufferSize+1];
bool running = true;
};
}
}
}

View File

@@ -11,6 +11,7 @@
#include "components/ble/BleController.h"
#include "components/ble/NotificationManager.h"
#include "components/heartrate/HeartRateController.h"
#include "components/motion/MotionController.h"
#include "components/settings/Settings.h"
#include "../DisplayApp.h"
@@ -23,11 +24,13 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app,
Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager,
Controllers::Settings &settingsController,
Controllers::HeartRateController& heartRateController): Screen(app), currentDateTime{{}},
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController) : Screen(app), currentDateTime{{}},
dateTimeController{dateTimeController}, batteryController{batteryController},
bleController{bleController}, notificatioManager{notificatioManager},
settingsController{settingsController},
heartRateController{heartRateController} {
heartRateController{heartRateController},
motionController{motionController} {
settingsController.SetClockFace(0);
displayedChar[0] = 0;
@@ -236,7 +239,7 @@ bool WatchFaceDigital::Refresh() {
lv_obj_align(heartbeatBpm, heartbeatValue, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
}
// TODO stepCount = stepController.GetValue();
stepCount = motionController.NbSteps();
if(stepCount.IsUpdated()) {
char stepBuffer[5];
sprintf(stepBuffer, "%lu", stepCount.Get());

View File

@@ -15,6 +15,7 @@ namespace Pinetime {
class Ble;
class NotificationManager;
class HeartRateController;
class MotionController;
}
namespace Applications {
@@ -28,7 +29,8 @@ namespace Pinetime {
Controllers::Ble& bleController,
Controllers::NotificationManager& notificatioManager,
Controllers::Settings &settingsController,
Controllers::HeartRateController& heartRateController);
Controllers::HeartRateController& heartRateController,
Controllers::MotionController& motionController);
~WatchFaceDigital() override;
bool Refresh() override;
@@ -73,6 +75,7 @@ namespace Pinetime {
Controllers::NotificationManager& notificatioManager;
Controllers::Settings& settingsController;
Controllers::HeartRateController& heartRateController;
Controllers::MotionController& motionController;
bool running = true;