2021-10-13 16:08:35 -04:00
|
|
|
#include "components/motor/MotorController.h"
|
2021-01-15 22:11:53 -05:00
|
|
|
#include <hal/nrf_gpio.h>
|
|
|
|
#include "systemtask/SystemTask.h"
|
2021-08-03 14:32:23 -04:00
|
|
|
#include "drivers/PinMap.h"
|
2021-01-15 22:11:53 -05:00
|
|
|
|
|
|
|
using namespace Pinetime::Controllers;
|
|
|
|
|
|
|
|
void MotorController::Init() {
|
2021-08-03 14:32:23 -04:00
|
|
|
nrf_gpio_cfg_output(PinMap::Motor);
|
|
|
|
nrf_gpio_pin_set(PinMap::Motor);
|
2021-08-01 04:47:26 -04:00
|
|
|
|
2022-06-06 11:47:43 -04:00
|
|
|
shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor);
|
|
|
|
longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring);
|
2021-01-15 22:11:53 -05:00
|
|
|
}
|
|
|
|
|
2022-06-06 11:47:43 -04:00
|
|
|
void MotorController::Ring(TimerHandle_t xTimer) {
|
|
|
|
auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
|
2021-08-01 06:05:48 -04:00
|
|
|
motorController->RunForDuration(50);
|
|
|
|
}
|
2021-04-03 22:08:51 -04:00
|
|
|
|
2021-08-01 06:05:48 -04:00
|
|
|
void MotorController::RunForDuration(uint8_t motorDuration) {
|
2022-06-06 11:47:43 -04:00
|
|
|
if (xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) {
|
|
|
|
nrf_gpio_pin_clear(PinMap::Motor);
|
|
|
|
}
|
2021-01-25 12:44:58 -05:00
|
|
|
}
|
2021-02-05 11:06:56 -05:00
|
|
|
|
2021-08-01 06:05:48 -04:00
|
|
|
void MotorController::StartRinging() {
|
2022-06-06 11:47:43 -04:00
|
|
|
RunForDuration(50);
|
|
|
|
xTimerStart(longVib, 0);
|
2021-05-12 14:23:04 -04:00
|
|
|
}
|
|
|
|
|
2021-08-01 06:05:48 -04:00
|
|
|
void MotorController::StopRinging() {
|
2022-06-06 11:47:43 -04:00
|
|
|
xTimerStop(longVib, 0);
|
2021-08-03 14:32:23 -04:00
|
|
|
nrf_gpio_pin_set(PinMap::Motor);
|
2021-05-12 14:23:04 -04:00
|
|
|
}
|
|
|
|
|
2022-06-06 11:47:43 -04:00
|
|
|
void MotorController::StopMotor(TimerHandle_t xTimer) {
|
2021-08-22 16:11:57 -04:00
|
|
|
nrf_gpio_pin_set(PinMap::Motor);
|
2021-08-01 04:47:26 -04:00
|
|
|
}
|