diff options
author | Jean-François Milants <jf@codingfield.com> | 2021-03-31 19:47:27 +0200 |
---|---|---|
committer | Jean-François Milants <jf@codingfield.com> | 2021-04-04 15:56:04 +0200 |
commit | 68bdaee1cc301a2aca1849f38d2596debe7d67d1 (patch) | |
tree | 00f3bd9a1554c286aa2d5bd3a86bcfcdf7ba7171 /src/displayapp | |
parent | 04fc33e2d479161ec261f932b908dffbd73e227f (diff) |
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".
Diffstat (limited to 'src/displayapp')
-rw-r--r-- | src/displayapp/Apps.h | 3 | ||||
-rw-r--r-- | src/displayapp/DisplayApp.cpp | 15 | ||||
-rw-r--r-- | src/displayapp/DisplayApp.h | 5 | ||||
-rw-r--r-- | src/displayapp/DisplayAppRecovery.cpp | 3 | ||||
-rw-r--r-- | src/displayapp/DisplayAppRecovery.h | 4 | ||||
-rw-r--r-- | src/displayapp/lv_pinetime_theme.c | 13 | ||||
-rw-r--r-- | src/displayapp/screens/ApplicationList.cpp | 4 | ||||
-rw-r--r-- | src/displayapp/screens/Clock.cpp | 9 | ||||
-rw-r--r-- | src/displayapp/screens/Clock.h | 5 | ||||
-rw-r--r-- | src/displayapp/screens/Motion.cpp | 59 | ||||
-rw-r--r-- | src/displayapp/screens/Motion.h | 39 | ||||
-rw-r--r-- | src/displayapp/screens/WatchFaceDigital.cpp | 9 | ||||
-rw-r--r-- | src/displayapp/screens/WatchFaceDigital.h | 5 |
13 files changed, 153 insertions, 20 deletions
diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index 74b121df..11401c3e 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -2,6 +2,7 @@ namespace Pinetime { namespace Applications { - enum class Apps {None, Launcher, Clock, SysInfo, Meter, Brightness, Music, FirmwareValidation, Paint, Paddle, Notifications, Twos, HeartRate, Navigation, StopWatch}; + enum class Apps {None, Launcher, Clock, SysInfo, Meter, Brightness, Music, FirmwareValidation, + Paint, Paddle, Notifications, Twos, HeartRate, Navigation, StopWatch, Motion}; } } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 3de26991..da398dcf 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -1,10 +1,12 @@ #include "DisplayApp.h" #include <libraries/log/nrf_log.h> #include <displayapp/screens/HeartRate.h> +#include <displayapp/screens/Motion.h> #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/datetime/DateTimeController.h" #include "components/ble/NotificationManager.h" +#include "components/motion/MotionController.h" #include "displayapp/screens/ApplicationList.h" #include "displayapp/screens/Brightness.h" #include "displayapp/screens/Clock.h" @@ -34,7 +36,8 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::HeartRateController& heartRateController, - Controllers::Settings &settingsController) : + Controllers::Settings &settingsController, + Pinetime::Controllers::MotionController& motionController) : lcd{lcd}, lvgl{lvgl}, batteryController{batteryController}, @@ -42,11 +45,12 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver dateTimeController{dateTimeController}, watchdog{watchdog}, touchPanel{touchPanel}, - currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController) }, + currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController, motionController) }, systemTask{systemTask}, notificationManager{notificationManager}, heartRateController{heartRateController}, - settingsController{settingsController} { + settingsController{settingsController}, + motionController{motionController} { msgQueue = xQueueCreate(queueSize, itemSize); onClockApp = true; } @@ -178,7 +182,7 @@ void DisplayApp::Refresh() { break; case Messages::UpdateDateTime: // Added to remove warning - // What should happen here? + // What should happen here? break; } } @@ -204,7 +208,7 @@ void DisplayApp::RunningState() { case Apps::None: case Apps::Launcher: currentScreen = std::make_unique<Screens::ApplicationList>(this, settingsController); break; case Apps::Clock: - currentScreen = std::make_unique<Screens::Clock>(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController); + currentScreen = std::make_unique<Screens::Clock>(this, dateTimeController, batteryController, bleController, notificationManager, settingsController, heartRateController, motionController); onClockApp = true; break; case Apps::SysInfo: currentScreen = std::make_unique<Screens::SystemInfo>(this, dateTimeController, batteryController, brightnessController, bleController, watchdog); break; @@ -219,6 +223,7 @@ void DisplayApp::RunningState() { case Apps::FirmwareValidation: currentScreen = std::make_unique<Screens::FirmwareValidation>(this, validator); break; case Apps::Notifications: currentScreen = std::make_unique<Screens::Notifications>(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal); break; case Apps::HeartRate: currentScreen = std::make_unique<Screens::HeartRate>(this, heartRateController); break; + case Apps::Motion: currentScreen = std::make_unique<Screens::Motion>(this, motionController); break; } nextApp = Apps::None; } diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index c22aa1f2..88a5691a 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -27,6 +27,7 @@ namespace Pinetime { class DateTime; class NotificationManager; class HeartRateController; + class MotionController; } namespace System { @@ -45,7 +46,8 @@ namespace Pinetime { System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::HeartRateController& heartRateController, - Controllers::Settings &settingsController + Controllers::Settings &settingsController, + Pinetime::Controllers::MotionController& motionController ); void Start(); void PushMessage(Display::Messages msg); @@ -92,6 +94,7 @@ namespace Pinetime { TouchModes touchMode = TouchModes::Gestures; Pinetime::Controllers::HeartRateController& heartRateController; Pinetime::Controllers::Settings& settingsController; + Pinetime::Controllers::MotionController& motionController; }; } } diff --git a/src/displayapp/DisplayAppRecovery.cpp b/src/displayapp/DisplayAppRecovery.cpp index 57b8aedd..d5723835 100644 --- a/src/displayapp/DisplayAppRecovery.cpp +++ b/src/displayapp/DisplayAppRecovery.cpp @@ -13,7 +13,8 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::HeartRateController& heartRateController, - Pinetime::Controllers::Settings& settingsController): + Pinetime::Controllers::Settings& settingsController, + Pinetime::Controllers::MotionController& motionController): lcd{lcd}, bleController{bleController} { msgQueue = xQueueCreate(queueSize, itemSize); diff --git a/src/displayapp/DisplayAppRecovery.h b/src/displayapp/DisplayAppRecovery.h index a3f27d2c..c35fa729 100644 --- a/src/displayapp/DisplayAppRecovery.h +++ b/src/displayapp/DisplayAppRecovery.h @@ -16,6 +16,7 @@ #include <date/date.h> #include <drivers/Watchdog.h> #include <components/heartrate/HeartRateController.h> +#include <components/motion/MotionController.h> #include <components/settings/Settings.h> #include "TouchEvents.h" #include "Apps.h" @@ -35,7 +36,8 @@ namespace Pinetime { System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::HeartRateController& heartRateController, - Pinetime::Controllers::Settings& settingsController); + Pinetime::Controllers::Settings& settingsController, + Pinetime::Controllers::MotionController& motionController); void Start(); void PushMessage(Pinetime::Applications::Display::Messages msg); diff --git a/src/displayapp/lv_pinetime_theme.c b/src/displayapp/lv_pinetime_theme.c index 88f77557..1350b0d1 100644 --- a/src/displayapp/lv_pinetime_theme.c +++ b/src/displayapp/lv_pinetime_theme.c @@ -53,6 +53,7 @@ static lv_style_t style_table_cell; static lv_style_t style_pad_small; static lv_style_t style_bg_grad; static lv_style_t style_lmeter; +static lv_style_t style_chart_serie; static bool inited; @@ -260,6 +261,11 @@ static void basic_init(void) lv_style_set_line_width(&style_lmeter, LV_STATE_DEFAULT, LV_DPX(10)); lv_style_set_scale_end_line_width(&style_lmeter, LV_STATE_DEFAULT, LV_DPX(7)); + style_init_reset(&style_chart_serie); + lv_style_set_line_color(&style_chart_serie, LV_STATE_DEFAULT, LV_PINETIME_WHITE); + lv_style_set_line_width(&style_chart_serie, LV_STATE_DEFAULT, 4); + lv_style_set_size(&style_chart_serie, LV_STATE_DEFAULT, 4); + lv_style_set_bg_opa(&style_chart_serie, LV_STATE_DEFAULT, 0); } @@ -465,7 +471,12 @@ static void theme_apply(lv_obj_t * obj, lv_theme_style_t name) _lv_style_list_add_style(list, &style_bg); _lv_style_list_add_style(list, &style_lmeter); break; - + + case LV_THEME_CHART: + lv_obj_clean_style_list(obj, LV_CHART_PART_SERIES); + list = lv_obj_get_style_list(obj, LV_CHART_PART_SERIES); + _lv_style_list_add_style(list, &style_btn); + _lv_style_list_add_style(list, &style_chart_serie); default: break; diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index 60039045..4083c4b2 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -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} } diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index 69180370..1cbd0a91 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(); }, @@ -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() { diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 964ccbf6..95968c5c 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 c39fe496..2204e177 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,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()); diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 70a9ce5d..e6514f1e 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; @@ -73,6 +75,7 @@ namespace Pinetime { Controllers::NotificationManager& notificatioManager; Controllers::Settings& settingsController; Controllers::HeartRateController& heartRateController; + Controllers::MotionController& motionController; bool running = true; |