InfiniTime/src/components/motor/MotorController.cpp
Riku Isokoski a3e14c012d src: Enable unused parameter warning
Fix warnings.
Some clang-formatting was necessary.
DebugPins is unused and was removed.
2023-01-24 10:43:17 +02:00

40 lines
1.1 KiB
C++

#include "components/motor/MotorController.h"
#include <hal/nrf_gpio.h>
#include "systemtask/SystemTask.h"
#include "drivers/PinMap.h"
using namespace Pinetime::Controllers;
void MotorController::Init() {
nrf_gpio_cfg_output(PinMap::Motor);
nrf_gpio_pin_set(PinMap::Motor);
shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor);
longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring);
}
void MotorController::Ring(TimerHandle_t xTimer) {
auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
motorController->RunForDuration(50);
}
void MotorController::RunForDuration(uint8_t motorDuration) {
if (motorDuration > 0 && xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) {
nrf_gpio_pin_clear(PinMap::Motor);
}
}
void MotorController::StartRinging() {
RunForDuration(50);
xTimerStart(longVib, 0);
}
void MotorController::StopRinging() {
xTimerStop(longVib, 0);
nrf_gpio_pin_set(PinMap::Motor);
}
void MotorController::StopMotor(TimerHandle_t /*xTimer*/) {
nrf_gpio_pin_set(PinMap::Motor);
}