#include "components/motor/MotorController.h" #include #include "systemtask/SystemTask.h" #include "app_timer.h" #include "drivers/PinMap.h" APP_TIMER_DEF(shortVibTimer); APP_TIMER_DEF(longVibTimer); using namespace Pinetime::Controllers; void MotorController::Init() { nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor); longVibTimer = xTimerCreate("longVibTm", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); } void MotorController::Ring(TimerHandle_t xTimer) { auto motorController = static_cast(pvTimerGetTimerID(xTimer)); motorController->RunForDuration(50); } void MotorController::RunForDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(PinMap::Motor); if (xTimerChangePeriod(shortVibTimer, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVibTimer, 0) == pdPASS) { return; } if (xTimerChangePeriodFromISR(shortVibTimer, pdMS_TO_TICKS(motorDuration), NULL) == pdPASS && xTimerStartFromISR(shortVibTimer, NULL) == pdPASS) { return; } nrf_gpio_pin_set(PinMap::Motor); } void MotorController::StartRinging() { Ring(this); xTimerStart(longVibTimer, 0); } void MotorController::StopRinging() { xTimerStop(longVibTimer, 0); nrf_gpio_pin_set(PinMap::Motor); } void MotorController::StopMotor(TimerHandle_t xTimer) { nrf_gpio_pin_set(PinMap::Motor); }