From fbb77baa3b6e487f4c68e08770499cb893c4e035 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Fri, 15 Jan 2021 22:11:53 -0500 Subject: [PATCH 01/12] add non-blocking motor controller --- src/CMakeLists.txt | 2 + src/components/motor/MotorController.cpp | 40 +++++++++++++++++ src/components/motor/MotorController.h | 57 ++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/components/motor/MotorController.cpp create mode 100644 src/components/motor/MotorController.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fde1f586..b5669414 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,10 +36,12 @@ set(SDK_SOURCE_FILES # Base SDK "${NRF5_SDK_PATH}/components/boards/boards.c" "${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.c" + "${NRF5_SDK_PATH}/integration/nrfx/legacy/nrf_drv_clock.h" "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_clock.c" "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_gpiote.c" "${NRF5_SDK_PATH}/modules/nrfx/soc/nrfx_atomic.c" "${NRF5_SDK_PATH}/modules/nrfx/drivers/src/nrfx_saadc.c" + "${NRF5_SDK_PATH}/components/libraries/timer/app_timer.h" # FreeRTOS ${NRF5_SDK_PATH}/external/freertos/source/croutine.c diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp new file mode 100644 index 00000000..1885f7bd --- /dev/null +++ b/src/components/motor/MotorController.cpp @@ -0,0 +1,40 @@ +#include "MotorController.h" +#include +#include "systemtask/SystemTask.h" +#include "app_timer.h" +#include "nrf_drv_clock.h" + +APP_TIMER_DEF(vibTimer); + +using namespace Pinetime::Controllers; + +static void lfclk_request(void) //get the low freq. clock +{ + nrf_drv_clock_init(); + nrf_drv_clock_lfclk_request(NULL); +} + +void vibrateTimer(void * p_context) +{ + nrf_gpio_pin_set(pinMotor); +} + +static void create_timers() +{ + //create timer, single shot, re-armable + app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrateTimer); +} + +void MotorController::Init() { + nrf_gpio_cfg_output(pinMotor); // set the motor pin as an output + nrf_gpio_pin_set(pinMotor); + lfclk_request(); //get lfclock ready + app_timer_init(); //start app timers to make calls + create_timers(); +} + +void MotorController::SetDuration(uint8_t motorDuration) { + nrf_gpio_pin_clear(pinMotor); + //start timer for motorDuration miliseconds + app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? +} \ No newline at end of file diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h new file mode 100644 index 00000000..6712d933 --- /dev/null +++ b/src/components/motor/MotorController.h @@ -0,0 +1,57 @@ +#pragma once + +#include + +namespace Pinetime { + namespace Controllers { + static constexpr uint8_t pinMotor = 16; + + class MotorController { + public: + void Init(); + void SetDuration(uint8_t motorDuration); + #ifndef NRF_CLOCK_ENABLED + #define NRF_CLOCK_ENABLED 1 + #endif + + #ifndef CLOCK_CONFIG_LF_SRC + #define CLOCK_CONFIG_LF_SRC 1 + #endif + + #ifndef CLOCK_CONFIG_IRQ_PRIORITY + #define CLOCK_CONFIG_IRQ_PRIORITY 6 + #endif + + #define APP_TIMER_ENABLED 1 + #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz + #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 + + #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE + #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 + #endif + + #ifndef APP_TIMER_CONFIG_USE_SCHEDULER + #define APP_TIMER_CONFIG_USE_SCHEDULER 0 + #endif + + #ifndef APP_TIMER_KEEPS_RTC_ACTIVE + #define APP_TIMER_KEEPS_RTC_ACTIVE 0 + #endif + + #ifndef APP_TIMER_SAFE_WINDOW_MS + #define APP_TIMER_SAFE_WINDOW_MS 300000 + #endif + + #ifndef APP_TIMER_WITH_PROFILER + #define APP_TIMER_WITH_PROFILER 0 + #endif + + #ifndef APP_TIMER_CONFIG_SWI_NUMBER + #define APP_TIMER_CONFIG_SWI_NUMBER 0 + #endif + + private: + + }; + } +} \ No newline at end of file From ce6c5d3bd3691b283ac2102d1ed7b9a298928b6c Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Fri, 15 Jan 2021 22:46:03 -0500 Subject: [PATCH 02/12] add motorcontroller to cmake --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5669414..3fe5d50a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -376,6 +376,7 @@ list(APPEND SOURCE_FILES components/ble/ImmediateAlertService.cpp components/ble/ServiceDiscovery.cpp components/firmwarevalidator/FirmwareValidator.cpp + components/motor/MotorController.cpp drivers/Cst816s.cpp FreeRTOS/port.c FreeRTOS/port_cmsis_systick.c @@ -456,6 +457,7 @@ set(INCLUDE_FILES components/ble/ImmediateAlertService.h components/ble/ServiceDiscovery.h components/ble/BleClient.h + components/motor/MotorController.h drivers/Cst816s.h FreeRTOS/portmacro.h FreeRTOS/portmacro_cmsis.h From b5992fd7ec369d057ce4fe1b10bbc52ed4f6f988 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Fri, 15 Jan 2021 22:49:37 -0500 Subject: [PATCH 03/12] add motor to notifs, fix tabs in motorcontroller.h --- src/components/motor/MotorController.h | 68 ++++++++++++------------ src/displayapp/screens/Notifications.cpp | 4 ++ src/displayapp/screens/Notifications.h | 2 + 3 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 6712d933..63bc9580 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -7,50 +7,50 @@ namespace Pinetime { static constexpr uint8_t pinMotor = 16; class MotorController { - public: - void Init(); - void SetDuration(uint8_t motorDuration); - #ifndef NRF_CLOCK_ENABLED - #define NRF_CLOCK_ENABLED 1 - #endif + public: + void Init(); + void SetDuration(uint8_t motorDuration); + #ifndef NRF_CLOCK_ENABLED + #define NRF_CLOCK_ENABLED 1 + #endif - #ifndef CLOCK_CONFIG_LF_SRC - #define CLOCK_CONFIG_LF_SRC 1 - #endif + #ifndef CLOCK_CONFIG_LF_SRC + #define CLOCK_CONFIG_LF_SRC 1 + #endif - #ifndef CLOCK_CONFIG_IRQ_PRIORITY - #define CLOCK_CONFIG_IRQ_PRIORITY 6 - #endif + #ifndef CLOCK_CONFIG_IRQ_PRIORITY + #define CLOCK_CONFIG_IRQ_PRIORITY 6 + #endif - #define APP_TIMER_ENABLED 1 - #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz - #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 + #define APP_TIMER_ENABLED 1 + #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz + #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 - #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE - #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 - #endif + #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE + #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 + #endif - #ifndef APP_TIMER_CONFIG_USE_SCHEDULER - #define APP_TIMER_CONFIG_USE_SCHEDULER 0 - #endif + #ifndef APP_TIMER_CONFIG_USE_SCHEDULER + #define APP_TIMER_CONFIG_USE_SCHEDULER 0 + #endif - #ifndef APP_TIMER_KEEPS_RTC_ACTIVE - #define APP_TIMER_KEEPS_RTC_ACTIVE 0 - #endif + #ifndef APP_TIMER_KEEPS_RTC_ACTIVE + #define APP_TIMER_KEEPS_RTC_ACTIVE 0 + #endif - #ifndef APP_TIMER_SAFE_WINDOW_MS - #define APP_TIMER_SAFE_WINDOW_MS 300000 - #endif + #ifndef APP_TIMER_SAFE_WINDOW_MS + #define APP_TIMER_SAFE_WINDOW_MS 300000 + #endif - #ifndef APP_TIMER_WITH_PROFILER - #define APP_TIMER_WITH_PROFILER 0 - #endif + #ifndef APP_TIMER_WITH_PROFILER + #define APP_TIMER_WITH_PROFILER 0 + #endif - #ifndef APP_TIMER_CONFIG_SWI_NUMBER - #define APP_TIMER_CONFIG_SWI_NUMBER 0 - #endif + #ifndef APP_TIMER_CONFIG_SWI_NUMBER + #define APP_TIMER_CONFIG_SWI_NUMBER 0 + #endif - private: + private: }; } diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 51a601c4..cfcecec2 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -7,6 +7,9 @@ Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::Notificatio Screen(app), notificationManager{notificationManager}, mode{mode} { notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); + + motorController.Init(); //start the vibration timer setups + if(notification.valid) { currentId = notification.id; currentItem.reset(new NotificationItem("\nNotification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); @@ -22,6 +25,7 @@ Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::Notificatio style_line.line.width = 3; style_line.line.rounded = 0; + motorController.SetDuration(35); timeoutLine = lv_line_create(lv_scr_act(), nullptr); lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index f5c6a860..345ad15a 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -5,6 +5,7 @@ #include #include "Screen.h" #include "components/ble/NotificationManager.h" +#include "components/motor/MotorController.h" namespace Pinetime { namespace Applications { @@ -45,6 +46,7 @@ namespace Pinetime { const char* text; }; Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::MotorController motorController; Modes mode = Modes::Normal; std::unique_ptr currentItem; Controllers::NotificationManager::Notification::Id currentId; From bf7d77bd341de7360d7e4331ee088dc7a72620fc Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:15:42 -0500 Subject: [PATCH 04/12] remove unneeded defines --- src/components/motor/MotorController.cpp | 1 - src/components/motor/MotorController.h | 39 +----------------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 1885f7bd..738e6d33 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -4,7 +4,6 @@ #include "app_timer.h" #include "nrf_drv_clock.h" -APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 63bc9580..01fe9304 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -10,45 +10,8 @@ namespace Pinetime { public: void Init(); void SetDuration(uint8_t motorDuration); - #ifndef NRF_CLOCK_ENABLED - #define NRF_CLOCK_ENABLED 1 - #endif - #ifndef CLOCK_CONFIG_LF_SRC - #define CLOCK_CONFIG_LF_SRC 1 - #endif - - #ifndef CLOCK_CONFIG_IRQ_PRIORITY - #define CLOCK_CONFIG_IRQ_PRIORITY 6 - #endif - - #define APP_TIMER_ENABLED 1 - #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz - #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 - - #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE - #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 - #endif - - #ifndef APP_TIMER_CONFIG_USE_SCHEDULER - #define APP_TIMER_CONFIG_USE_SCHEDULER 0 - #endif - - #ifndef APP_TIMER_KEEPS_RTC_ACTIVE - #define APP_TIMER_KEEPS_RTC_ACTIVE 0 - #endif - - #ifndef APP_TIMER_SAFE_WINDOW_MS - #define APP_TIMER_SAFE_WINDOW_MS 300000 - #endif - - #ifndef APP_TIMER_WITH_PROFILER - #define APP_TIMER_WITH_PROFILER 0 - #endif - - #ifndef APP_TIMER_CONFIG_SWI_NUMBER - #define APP_TIMER_CONFIG_SWI_NUMBER 0 - #endif + APP_TIMER_DEF(vibTimer); private: From 4cbcc99c8dfbd27bf3c87ef1c2b13af871a9c269 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Sat, 23 Jan 2021 16:12:06 -0500 Subject: [PATCH 05/12] fis merge conflict? --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3fe5d50a..0ed2562f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -457,7 +457,6 @@ set(INCLUDE_FILES components/ble/ImmediateAlertService.h components/ble/ServiceDiscovery.h components/ble/BleClient.h - components/motor/MotorController.h drivers/Cst816s.h FreeRTOS/portmacro.h FreeRTOS/portmacro_cmsis.h @@ -474,6 +473,7 @@ set(INCLUDE_FILES systemtask/SystemMonitor.h displayapp/screens/Symbols.h drivers/TwiMaster.h + components/motor/MotorController.h ) include_directories( From 51c8cadcb78bdbe9013f5aace629c96ed3dfd06f Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Sat, 23 Jan 2021 16:13:58 -0500 Subject: [PATCH 06/12] fix merge issue --- src/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0ed2562f..b66f2ece 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -473,6 +473,11 @@ set(INCLUDE_FILES systemtask/SystemMonitor.h displayapp/screens/Symbols.h drivers/TwiMaster.h + heartratetask/HeartRateTask.h + components/heartrate/Ppg.h + components/heartrate/Biquad.h + components/heartrate/Ptagc.h + components/heartrate/HeartRateController.h components/motor/MotorController.h ) From f27e63290639ca257e88298b60429d72271c4954 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Mon, 25 Jan 2021 12:44:58 -0500 Subject: [PATCH 07/12] move app timer def --- src/components/motor/MotorController.cpp | 3 ++- src/components/motor/MotorController.h | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 738e6d33..51a01b4c 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -4,6 +4,7 @@ #include "app_timer.h" #include "nrf_drv_clock.h" +APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; @@ -36,4 +37,4 @@ void MotorController::SetDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(pinMotor); //start timer for motorDuration miliseconds app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? -} \ No newline at end of file +} diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 01fe9304..52ab558c 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -1,6 +1,7 @@ #pragma once #include +#include "app_timer.h" namespace Pinetime { namespace Controllers { @@ -11,10 +12,8 @@ namespace Pinetime { void Init(); void SetDuration(uint8_t motorDuration); - APP_TIMER_DEF(vibTimer); - private: - + app_timer_id_t vibTimer; }; } -} \ No newline at end of file +} From 3dd88339f39089232c40f043a478b9ba47cb1dad Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Mon, 25 Jan 2021 16:47:52 +0100 Subject: [PATCH 08/12] create motorcontroller in main and pass by reference --- src/displayapp/DisplayApp.cpp | 7 +++++-- src/displayapp/DisplayApp.h | 3 +++ src/displayapp/screens/Notifications.cpp | 10 +++++++--- src/displayapp/screens/Notifications.h | 7 +++++-- src/main.cpp | 4 +++- src/systemtask/SystemTask.cpp | 7 +++++-- src/systemtask/SystemTask.h | 3 +++ 7 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index b6ad90b4..12efe62b 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -5,6 +5,7 @@ #include "components/ble/BleController.h" #include "components/datetime/DateTimeController.h" #include "components/ble/NotificationManager.h" +#include "components/motor/MotorController.h" #include "displayapp/screens/ApplicationList.h" #include "displayapp/screens/Brightness.h" #include "displayapp/screens/Clock.h" @@ -32,6 +33,7 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog, System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, + Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::HeartRateController& heartRateController) : lcd{lcd}, lvgl{lvgl}, @@ -43,6 +45,7 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController, notificationManager, heartRateController) }, systemTask{systemTask}, notificationManager{notificationManager}, + motorController{motorController}, heartRateController{heartRateController} { msgQueue = xQueueCreate(queueSize, itemSize); onClockApp = true; @@ -124,7 +127,7 @@ void DisplayApp::Refresh() { currentScreen.reset(nullptr); lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); onClockApp = false; - currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Preview)); + currentScreen.reset(new Screens::Notifications(this, notificationManager, motorController, Screens::Notifications::Modes::Preview)); } } break; @@ -215,7 +218,7 @@ void DisplayApp::RunningState() { case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::Navigation : currentScreen.reset(new Screens::Navigation(this, systemTask.nimble().navigation())); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; - case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Normal)); break; + case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, motorController, Screens::Notifications::Modes::Normal)); break; case Apps::HeartRate: currentScreen.reset(new Screens::HeartRate(this, heartRateController)); break; } nextApp = Apps::None; diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index da5a7b22..68730468 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -23,6 +23,7 @@ namespace Pinetime { class Ble; class DateTime; class NotificationManager; + class MotorController; class HeartRateController; } @@ -44,6 +45,7 @@ namespace Pinetime { Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog, System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, + Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::HeartRateController& heartRateController); void Start(); void PushMessage(Messages msg); @@ -87,6 +89,7 @@ namespace Pinetime { Controllers::BrightnessController brightnessController; std::unique_ptr modal; Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::MotorController& motorController; Pinetime::Controllers::FirmwareValidator validator; TouchModes touchMode = TouchModes::Gestures; Pinetime::Controllers::HeartRateController& heartRateController; diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index cfcecec2..b777aca8 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -3,12 +3,16 @@ using namespace Pinetime::Applications::Screens; -Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager ¬ificationManager, Modes mode) : - Screen(app), notificationManager{notificationManager}, mode{mode} { +Notifications::Notifications(DisplayApp *app, + Pinetime::Controllers::NotificationManager ¬ificationManager, + Pinetime::Controllers::MotorController& motorController, + Modes mode) : + Screen(app), notificationManager{notificationManager}, + motorController{motorController}, mode{mode} { + notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); - motorController.Init(); //start the vibration timer setups if(notification.valid) { currentId = notification.id; diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index 345ad15a..85d13545 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -13,7 +13,10 @@ namespace Pinetime { class Notifications : public Screen { public: enum class Modes {Normal, Preview}; - explicit Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Modes mode); + explicit Notifications(DisplayApp* app, + Pinetime::Controllers::NotificationManager& notificationManager, + Pinetime::Controllers::MotorController& motorController, + Modes mode); ~Notifications() override; bool Refresh() override; @@ -46,7 +49,7 @@ namespace Pinetime { const char* text; }; Pinetime::Controllers::NotificationManager& notificationManager; - Pinetime::Controllers::MotorController motorController; + Pinetime::Controllers::MotorController& motorController; Modes mode = Modes::Normal; std::unique_ptr currentItem; Controllers::NotificationManager::Notification::Id currentId; diff --git a/src/main.cpp b/src/main.cpp index 3b993ee9..78a2cf5b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,7 @@ #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" #include "components/ble/NotificationManager.h" +#include "components/motor/MotorController.h" #include "components/datetime/DateTimeController.h" #include "displayapp/DisplayApp.h" #include "displayapp/LittleVgl.h" @@ -99,6 +100,7 @@ static constexpr uint8_t pinTouchIrq = 28; std::unique_ptr systemTask; Pinetime::Controllers::NotificationManager notificationManager; +Pinetime::Controllers::MotorController motorController; void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if(pin == pinTouchIrq) { @@ -241,7 +243,7 @@ int main(void) { debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback); systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController, - dateTimeController, notificationManager, heartRateSensor)); + dateTimeController, notificationManager, motorController, heartRateSensor)); systemTask->Start(); nimble_port_init(); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 13a84c26..4b9cb429 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -41,13 +41,14 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::DateTime &dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager, + Pinetime::Controllers::MotorController& motorController, Pinetime::Drivers::Hrs3300& heartRateSensor) : spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash}, twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, heartRateController{*this}, bleController{bleController}, dateTimeController{dateTimeController}, watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, - heartRateSensor{heartRateSensor}, + motorController{motorController}, heartRateSensor{heartRateSensor}, nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) { systemTasksMsgQueue = xQueueCreate(10, 1); } @@ -81,12 +82,14 @@ void SystemTask::Work() { batteryController.Init(); displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, - dateTimeController, watchdogView, *this, notificationManager, heartRateController)); + dateTimeController, watchdogView, *this, notificationManager, + motorController, heartRateController)); displayApp->Start(); batteryController.Update(); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel); + motorController.Init(); heartRateSensor.Init(); heartRateSensor.Disable(); diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index cf3f1021..70abf5f3 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -12,6 +12,7 @@ #include "components/battery/BatteryController.h" #include "components/ble/NimbleController.h" #include "components/ble/NotificationManager.h" +#include "components/motor/MotorController.h" #include "displayapp/DisplayApp.h" #include "drivers/Watchdog.h" @@ -38,6 +39,7 @@ namespace Pinetime { Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::DateTime &dateTimeController, Pinetime::Controllers::NotificationManager& manager, + Pinetime::Controllers::MotorController& motorController, Pinetime::Drivers::Hrs3300& heartRateSensor); @@ -74,6 +76,7 @@ namespace Pinetime { Pinetime::Drivers::Watchdog watchdog; Pinetime::Drivers::WatchdogView watchdogView; Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::MotorController& motorController; Pinetime::Drivers::Hrs3300& heartRateSensor; Pinetime::Controllers::NimbleController nimbleController; From da56ca5bfb5c9569d53bbe26ea8e6630dbead9f6 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Mon, 25 Jan 2021 13:03:04 -0500 Subject: [PATCH 09/12] remove vibtimer from .h to fix nonstop vibration --- src/components/motor/MotorController.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 52ab558c..9ce91c52 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -13,7 +13,6 @@ namespace Pinetime { void SetDuration(uint8_t motorDuration); private: - app_timer_id_t vibTimer; }; } } From 1bd5457848babefbc0c129e77c9a2a314c55b780 Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Fri, 5 Feb 2021 15:43:20 +0100 Subject: [PATCH 10/12] trigger vibration from systemtask --- src/displayapp/DisplayApp.cpp | 7 ++----- src/displayapp/DisplayApp.h | 3 --- src/displayapp/screens/Notifications.cpp | 10 +++------- src/displayapp/screens/Notifications.h | 3 --- src/systemtask/SystemTask.cpp | 7 ++++--- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 12efe62b..b6ad90b4 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -5,7 +5,6 @@ #include "components/ble/BleController.h" #include "components/datetime/DateTimeController.h" #include "components/ble/NotificationManager.h" -#include "components/motor/MotorController.h" #include "displayapp/screens/ApplicationList.h" #include "displayapp/screens/Brightness.h" #include "displayapp/screens/Clock.h" @@ -33,7 +32,6 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog, System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, - Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::HeartRateController& heartRateController) : lcd{lcd}, lvgl{lvgl}, @@ -45,7 +43,6 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver currentScreen{new Screens::Clock(this, dateTimeController, batteryController, bleController, notificationManager, heartRateController) }, systemTask{systemTask}, notificationManager{notificationManager}, - motorController{motorController}, heartRateController{heartRateController} { msgQueue = xQueueCreate(queueSize, itemSize); onClockApp = true; @@ -127,7 +124,7 @@ void DisplayApp::Refresh() { currentScreen.reset(nullptr); lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); onClockApp = false; - currentScreen.reset(new Screens::Notifications(this, notificationManager, motorController, Screens::Notifications::Modes::Preview)); + currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Preview)); } } break; @@ -218,7 +215,7 @@ void DisplayApp::RunningState() { case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::Navigation : currentScreen.reset(new Screens::Navigation(this, systemTask.nimble().navigation())); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; - case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, motorController, Screens::Notifications::Modes::Normal)); break; + case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Normal)); break; case Apps::HeartRate: currentScreen.reset(new Screens::HeartRate(this, heartRateController)); break; } nextApp = Apps::None; diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index 68730468..da5a7b22 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -23,7 +23,6 @@ namespace Pinetime { class Ble; class DateTime; class NotificationManager; - class MotorController; class HeartRateController; } @@ -45,7 +44,6 @@ namespace Pinetime { Controllers::DateTime &dateTimeController, Drivers::WatchdogView &watchdog, System::SystemTask &systemTask, Pinetime::Controllers::NotificationManager& notificationManager, - Pinetime::Controllers::MotorController& motorController, Pinetime::Controllers::HeartRateController& heartRateController); void Start(); void PushMessage(Messages msg); @@ -89,7 +87,6 @@ namespace Pinetime { Controllers::BrightnessController brightnessController; std::unique_ptr modal; Pinetime::Controllers::NotificationManager& notificationManager; - Pinetime::Controllers::MotorController& motorController; Pinetime::Controllers::FirmwareValidator validator; TouchModes touchMode = TouchModes::Gestures; Pinetime::Controllers::HeartRateController& heartRateController; diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index b777aca8..ece9eb07 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -5,11 +5,9 @@ using namespace Pinetime::Applications::Screens; Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager ¬ificationManager, - Pinetime::Controllers::MotorController& motorController, - Modes mode) : - Screen(app), notificationManager{notificationManager}, - motorController{motorController}, mode{mode} { - + Modes mode) : + Screen(app), notificationManager{notificationManager}, mode{mode} { + notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); @@ -29,8 +27,6 @@ Notifications::Notifications(DisplayApp *app, style_line.line.width = 3; style_line.line.rounded = 0; - motorController.SetDuration(35); - timeoutLine = lv_line_create(lv_scr_act(), nullptr); lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line); lv_line_set_points(timeoutLine, timeoutLinePoints, 2); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index 85d13545..b621b777 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -5,7 +5,6 @@ #include #include "Screen.h" #include "components/ble/NotificationManager.h" -#include "components/motor/MotorController.h" namespace Pinetime { namespace Applications { @@ -15,7 +14,6 @@ namespace Pinetime { enum class Modes {Normal, Preview}; explicit Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, - Pinetime::Controllers::MotorController& motorController, Modes mode); ~Notifications() override; @@ -49,7 +47,6 @@ namespace Pinetime { const char* text; }; Pinetime::Controllers::NotificationManager& notificationManager; - Pinetime::Controllers::MotorController& motorController; Modes mode = Modes::Normal; std::unique_ptr currentItem; Controllers::NotificationManager::Notification::Id currentId; diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 4b9cb429..e195de8e 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -80,17 +80,17 @@ void SystemTask::Work() { twiMaster.Init(); touchPanel.Init(); batteryController.Init(); + motorController.Init(); + displayApp.reset(new Pinetime::Applications::DisplayApp(lcd, lvgl, touchPanel, batteryController, bleController, dateTimeController, watchdogView, *this, notificationManager, - motorController, heartRateController)); + heartRateController)); displayApp->Start(); batteryController.Update(); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::UpdateBatteryLevel); - motorController.Init(); - heartRateSensor.Init(); heartRateSensor.Disable(); heartRateApp.reset(new Pinetime::Applications::HeartRateTask(heartRateSensor, heartRateController)); @@ -162,6 +162,7 @@ void SystemTask::Work() { break; case Messages::OnNewNotification: if(isSleeping && !isWakingUp) GoToRunning(); + motorController.SetDuration(35); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); break; case Messages::BleConnected: From 7ab153cd7690db8a43bde1af792edecc5e0f8d5d Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Fri, 5 Feb 2021 17:06:56 +0100 Subject: [PATCH 11/12] refactor MotorController --- src/components/motor/MotorController.cpp | 33 +++++++----------------- src/components/motor/MotorController.h | 1 + 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 51a01b4c..7f53fbf7 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -2,39 +2,24 @@ #include #include "systemtask/SystemTask.h" #include "app_timer.h" -#include "nrf_drv_clock.h" APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; -static void lfclk_request(void) //get the low freq. clock -{ - nrf_drv_clock_init(); - nrf_drv_clock_lfclk_request(NULL); -} - -void vibrateTimer(void * p_context) -{ - nrf_gpio_pin_set(pinMotor); -} - -static void create_timers() -{ - //create timer, single shot, re-armable - app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrateTimer); -} - void MotorController::Init() { - nrf_gpio_cfg_output(pinMotor); // set the motor pin as an output + nrf_gpio_cfg_output(pinMotor); nrf_gpio_pin_set(pinMotor); - lfclk_request(); //get lfclock ready - app_timer_init(); //start app timers to make calls - create_timers(); + app_timer_init(); + app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate); } void MotorController::SetDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(pinMotor); - //start timer for motorDuration miliseconds - app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? + /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/ + app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); } + +void MotorController::vibrate(void * p_context) { + nrf_gpio_pin_set(pinMotor); +} \ No newline at end of file diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 9ce91c52..bdc20c0c 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -13,6 +13,7 @@ namespace Pinetime { void SetDuration(uint8_t motorDuration); private: + static void vibrate(void * p_context); }; } } From 1e2cc3ce91b402459790332b84e3f8dcbe5dc340 Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Sun, 7 Feb 2021 13:31:02 +0100 Subject: [PATCH 12/12] add vibration toggle --- src/components/ble/NotificationManager.cpp | 8 ++++++++ src/components/ble/NotificationManager.h | 3 +++ src/displayapp/screens/Notifications.cpp | 4 ++++ src/systemtask/SystemTask.cpp | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index dabcb4ba..fd66c194 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -71,6 +71,14 @@ bool NotificationManager::AreNewNotificationsAvailable() { return newNotification; } +bool NotificationManager::isVibrationEnabled() { + return vibrationEnabled; +} + +void NotificationManager::toggleVibrations() { + vibrationEnabled = !vibrationEnabled; +} + bool NotificationManager::ClearNewNotificationFlag() { return newNotification.exchange(false); } diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index 036d2ed9..4dce4eda 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -28,6 +28,8 @@ namespace Pinetime { Notification GetPrevious(Notification::Id id); bool ClearNewNotificationFlag(); bool AreNewNotificationsAvailable(); + bool isVibrationEnabled(); + void toggleVibrations(); static constexpr size_t MaximumMessageSize() { return MessageSize; }; size_t NbNotifications() const; @@ -40,6 +42,7 @@ namespace Pinetime { uint8_t writeIndex = 0; bool empty = true; std::atomic newNotification{false}; + bool vibrationEnabled = true; }; } } \ No newline at end of file diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index ece9eb07..b481c972 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -92,6 +92,10 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); } return true; + case Pinetime::Applications::TouchEvents::LongTap: { + notificationManager.toggleVibrations(); + return true; + } default: return false; } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index e195de8e..250a4ab4 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -162,7 +162,7 @@ void SystemTask::Work() { break; case Messages::OnNewNotification: if(isSleeping && !isWakingUp) GoToRunning(); - motorController.SetDuration(35); + if(notificationManager.isVibrationEnabled()) motorController.SetDuration(35); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); break; case Messages::BleConnected: