summaryrefslogtreecommitdiff
path: root/src/components/motor/MotorController.cpp
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2022-06-06 18:27:54 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-06-06 23:09:58 (GMT)
commit7c45f185a32c7bcff47c8fda1acdec82d3213717 (patch)
tree53b0419fe2a19e6ec5c89d0be0a11dcd8d4ceb00 /src/components/motor/MotorController.cpp
parent94b1b330fc1f6e941a797fedabade4e790e28bc2 (diff)
parent35dcf8c8607483c104711c9398d47d57147f4389 (diff)
Merge remote-tracking branch 'origin/develop' into analog24
Diffstat (limited to 'src/components/motor/MotorController.cpp')
-rw-r--r--src/components/motor/MotorController.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index 4c44fc4..90e41d2 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -1,41 +1,36 @@
#include "components/motor/MotorController.h"
#include <hal/nrf_gpio.h>
#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", 1, pdTRUE, this, Ring);
+ 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));
- xTimerChangePeriod(motorController->longVibTimer, APP_TIMER_TICKS(1000), 0);
+ auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
motorController->RunForDuration(50);
}
void MotorController::RunForDuration(uint8_t motorDuration) {
- if (xTimerChangePeriod(shortVibTimer, APP_TIMER_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVibTimer, 0) == pdPASS) {
+ if (xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) {
nrf_gpio_pin_clear(PinMap::Motor);
}
}
void MotorController::StartRinging() {
- xTimerChangePeriod(longVibTimer, 1, 0);
- xTimerStart(longVibTimer, 0);
+ RunForDuration(50);
+ xTimerStart(longVib, 0);
}
void MotorController::StopRinging() {
- xTimerStop(longVibTimer, 0);
+ xTimerStop(longVib, 0);
nrf_gpio_pin_set(PinMap::Motor);
}