diff options
Diffstat (limited to 'src/components/motor')
-rw-r--r-- | src/components/motor/MotorController.cpp | 42 | ||||
-rw-r--r-- | src/components/motor/MotorController.h | 14 |
2 files changed, 34 insertions, 22 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 3afa0ced..f596c718 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -2,30 +2,42 @@ #include <hal/nrf_gpio.h> #include "systemtask/SystemTask.h" #include "app_timer.h" +#include "drivers/PinMap.h" -APP_TIMER_DEF(vibTimer); +APP_TIMER_DEF(shortVibTimer); +APP_TIMER_DEF(longVibTimer); using namespace Pinetime::Controllers; -MotorController::MotorController(Controllers::Settings& settingsController) : settingsController {settingsController} { +void MotorController::Init() { + nrf_gpio_cfg_output(PinMap::Motor); + nrf_gpio_pin_set(PinMap::Motor); + app_timer_init(); + + app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor); + app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring); } -void MotorController::Init() { - nrf_gpio_cfg_output(pinMotor); - nrf_gpio_pin_set(pinMotor); - app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate); +void MotorController::Ring(void* p_context) { + auto* motorController = static_cast<MotorController*>(p_context); + motorController->RunForDuration(50); } -void MotorController::SetDuration(uint8_t motorDuration) { +void MotorController::RunForDuration(uint8_t motorDuration) { + nrf_gpio_pin_clear(PinMap::Motor); + app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr); +} - if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) - return; +void MotorController::StartRinging() { + Ring(this); + app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this); +} - nrf_gpio_pin_clear(pinMotor); - /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/ - app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); +void MotorController::StopRinging() { + app_timer_stop(longVibTimer); + nrf_gpio_pin_set(PinMap::Motor); } -void MotorController::vibrate(void* p_context) { - nrf_gpio_pin_set(pinMotor); -}
\ 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 df61af78..c9326d57 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -1,22 +1,22 @@ #pragma once #include <cstdint> -#include "app_timer.h" -#include "components/settings/Settings.h" namespace Pinetime { namespace Controllers { - static constexpr uint8_t pinMotor = 16; class MotorController { public: - MotorController(Controllers::Settings& settingsController); + MotorController() = default; + void Init(); - void SetDuration(uint8_t motorDuration); + void RunForDuration(uint8_t motorDuration); + void StartRinging(); + static void StopRinging(); private: - Controllers::Settings& settingsController; - static void vibrate(void* p_context); + static void Ring(void* p_context); + static void StopMotor(void* p_context); }; } } |