diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/motor/MotorController.cpp | 37 | ||||
-rw-r--r-- | src/components/motor/MotorController.h | 7 |
2 files changed, 34 insertions, 10 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 1f209368..42057a86 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -4,7 +4,8 @@ #include "app_timer.h" #include "drivers/PinMap.h" -APP_TIMER_DEF(vibTimer); +APP_TIMER_DEF(shortVibTimer); +APP_TIMER_DEF(longVibTimer); using namespace Pinetime::Controllers; @@ -14,19 +15,39 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se void MotorController::Init() { nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); - app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate); + app_timer_init(); + + app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor); + app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring); } -void MotorController::SetDuration(uint8_t motorDuration) { +void MotorController::Ring(void* p_context) { + auto* motorController = static_cast<MotorController*>(p_context); + motorController->RunForDuration(50); +} - if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) +void MotorController::RunForDuration(uint8_t motorDuration) { + if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) { return; + } nrf_gpio_pin_clear(PinMap::Motor); - /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/ - app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); + app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr); +} + +void MotorController::StartRinging() { + if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) { + return; + } + Ring(this); + app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this); } -void MotorController::vibrate(void* p_context) { +void MotorController::StopRinging() { + app_timer_stop(longVibTimer); nrf_gpio_pin_set(PinMap::Motor); -}
\ No newline at end of file +} + +void MotorController::StopMotor(void* p_context) { + nrf_gpio_pin_set(PinMap::Motor); +} diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 00cd1937..1d8fcc95 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -11,11 +11,14 @@ namespace Pinetime { public: MotorController(Controllers::Settings& settingsController); void Init(); - void SetDuration(uint8_t motorDuration); + void RunForDuration(uint8_t motorDuration); + void StartRinging(); + static void StopRinging(); private: + static void Ring(void* p_context); Controllers::Settings& settingsController; - static void vibrate(void* p_context); + static void StopMotor(void* p_context); }; } } |