summaryrefslogtreecommitdiff
path: root/src/displayapp/screens
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-04-09 21:17:03 +0200
committerJean-François Milants <jf@codingfield.com>2021-04-09 21:17:03 +0200
commiteb769fb60ecb8f96ecf6901082ec3f0610842af8 (patch)
treec26870103f8baaa933399cfb86cca25aa7e60d8b /src/displayapp/screens
parent57b4c3f0edc6acfa31bd2160abdcd6091920ba63 (diff)
parent15b3b8e282dd5b2132b0095716cd9d88740d4579 (diff)
Merge branch 'motion-sensor' into develop
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r--src/displayapp/screens/ApplicationList.cpp4
-rw-r--r--src/displayapp/screens/Clock.cpp9
-rw-r--r--src/displayapp/screens/Clock.h5
-rw-r--r--src/displayapp/screens/Motion.cpp59
-rw-r--r--src/displayapp/screens/Motion.h39
-rw-r--r--src/displayapp/screens/WatchFaceDigital.cpp17
-rw-r--r--src/displayapp/screens/WatchFaceDigital.h6
7 files changed, 127 insertions, 12 deletions
diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp
index db244822..056d128c 100644
--- a/src/displayapp/screens/ApplicationList.cpp
+++ b/src/displayapp/screens/ApplicationList.cpp
@@ -16,7 +16,7 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp *app,
settingsController{settingsController},
batteryController{batteryController},
dateTimeController{dateTimeController},
- screens{app,
+ screens{app,
settingsController.GetAppMenu(),
{
[this]() -> std::unique_ptr<Screen> { return CreateScreen1(); },
@@ -47,7 +47,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
{Symbols::stopWatch, Apps::StopWatch},
{Symbols::music, Apps::Music},
{Symbols::map, Apps::Navigation},
- {Symbols::shoe, Apps::Clock},
+ {Symbols::shoe, Apps::Motion},
{Symbols::heartBeat, Apps::HeartRate},
{"", Apps::None},
}
diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp
index d8cc573a..c218aa5c 100644
--- a/src/displayapp/screens/Clock.cpp
+++ b/src/displayapp/screens/Clock.cpp
@@ -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(); },
@@ -59,7 +62,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() {
diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h
index a5163655..1a4e0ebd 100644
--- a/src/displayapp/screens/Clock.h
+++ b/src/displayapp/screens/Clock.h
@@ -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;
diff --git a/src/displayapp/screens/Motion.cpp b/src/displayapp/screens/Motion.cpp
new file mode 100644
index 00000000..ed4b8198
--- /dev/null
+++ b/src/displayapp/screens/Motion.cpp
@@ -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;
+}
diff --git a/src/displayapp/screens/Motion.h b/src/displayapp/screens/Motion.h
new file mode 100644
index 00000000..ad1341a8
--- /dev/null
+++ b/src/displayapp/screens/Motion.h
@@ -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;
+
+ };
+ }
+ }
+} \ No newline at end of file
diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp
index 6fe076c5..c085b0b4 100644
--- a/src/displayapp/screens/WatchFaceDigital.cpp
+++ b/src/displayapp/screens/WatchFaceDigital.cpp
@@ -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,10 +239,14 @@ bool WatchFaceDigital::Refresh() {
lv_obj_align(heartbeatBpm, heartbeatValue, LV_ALIGN_OUT_RIGHT_MID, 5, 0);
}
- // TODO stepCount = stepController.GetValue();
- if(stepCount.IsUpdated()) {
+ stepCount = motionController.NbSteps();
+ motionSensorOk = motionController.IsSensorOk();
+ if(stepCount.IsUpdated() || motionSensorOk.IsUpdated()) {
char stepBuffer[5];
- sprintf(stepBuffer, "%lu", stepCount.Get());
+ if(motionSensorOk.Get())
+ sprintf(stepBuffer, "%lu", stepCount.Get());
+ else
+ sprintf(stepBuffer, "---", stepCount.Get());
lv_label_set_text(stepValue, stepBuffer);
lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -5, -2);
lv_obj_align(stepIcon, stepValue, LV_ALIGN_OUT_LEFT_MID, -5, 0);
diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h
index 8f23985c..67d32ff6 100644
--- a/src/displayapp/screens/WatchFaceDigital.h
+++ b/src/displayapp/screens/WatchFaceDigital.h
@@ -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;
@@ -48,6 +50,7 @@ namespace Pinetime {
DirtyValue<int> batteryPercentRemaining {};
DirtyValue<bool> bleState {};
DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime{};
+ DirtyValue<bool> motionSensorOk {};
DirtyValue<uint32_t> stepCount {};
DirtyValue<uint8_t> heartbeat {};
DirtyValue<bool> heartbeatRunning {};
@@ -73,6 +76,7 @@ namespace Pinetime {
Controllers::NotificationManager& notificatioManager;
Controllers::Settings& settingsController;
Controllers::HeartRateController& heartRateController;
+ Controllers::MotionController& motionController;