diff options
author | hubmartin <hub.martin@gmail.com> | 2021-08-22 22:11:57 +0200 |
---|---|---|
committer | hubmartin <hub.martin@gmail.com> | 2021-08-22 22:11:57 +0200 |
commit | 2a299fe2759e934c69b360995745d43c741115f8 (patch) | |
tree | 83813367684eba510da5d5295aca476151b545f3 /src/components/motor/MotorController.cpp | |
parent | 0d083a2beac118234f07dacee42f0925420abb42 (diff) | |
parent | df8ea7fe523bb9ec0ac3e24f0b1bebe5743d90cc (diff) |
Merge branch 'develop' into pinmap
Diffstat (limited to 'src/components/motor/MotorController.cpp')
-rw-r--r-- | src/components/motor/MotorController.cpp | 37 |
1 files changed, 29 insertions, 8 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); +} |