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: add non-blocking motor controller --- src/components/motor/MotorController.cpp | 40 ++++++++++++++++++++++ src/components/motor/MotorController.h | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/components/motor/MotorController.cpp create mode 100644 src/components/motor/MotorController.h (limited to 'src/components') 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 -- cgit v1.2.3 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: add motor to notifs, fix tabs in motorcontroller.h --- src/components/motor/MotorController.h | 88 ++++++++++++++++---------------- src/displayapp/screens/Notifications.cpp | 4 ++ src/displayapp/screens/Notifications.h | 2 + 3 files changed, 50 insertions(+), 44 deletions(-) (limited to 'src/components') 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 - - #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: + 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: }; } 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; -- cgit v1.2.3 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: remove unneeded defines --- src/components/motor/MotorController.cpp | 1 - src/components/motor/MotorController.h | 39 +------------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) (limited to 'src/components') 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: -- cgit v1.2.3 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: move app timer def --- src/components/motor/MotorController.cpp | 3 ++- src/components/motor/MotorController.h | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/components') 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 +} -- cgit v1.2.3 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: remove vibtimer from .h to fix nonstop vibration --- src/components/motor/MotorController.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/components') 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; }; } } -- cgit v1.2.3 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: refactor MotorController --- src/components/motor/MotorController.cpp | 33 +++++++++----------------------- src/components/motor/MotorController.h | 1 + 2 files changed, 10 insertions(+), 24 deletions(-) (limited to 'src/components') 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); }; } } -- cgit v1.2.3 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: 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(-) (limited to 'src/components') 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: -- cgit v1.2.3