summaryrefslogtreecommitdiff
path: root/src/components/motor/MotorController.cpp
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2022-04-16 11:43:58 (GMT)
committerMichele Bini <michele.bini@gmail.com>2022-04-16 12:12:52 (GMT)
commit2e367ec0aea857a1aee7306a2de893f96a60f2df (patch)
tree86439281fb0ed810b83161cb36985f2a731b22bc /src/components/motor/MotorController.cpp
parentebf3859407adba9da7acbc77b1ebabfd39d80a37 (diff)
parentc9808e29f1bbfbd1396d7b83212f6d223d52f99d (diff)
Merge branch 'alarm-fix-work' into edge
# Conflicts: # src/components/timer/TimerController.cpp
Diffstat (limited to 'src/components/motor/MotorController.cpp')
-rw-r--r--src/components/motor/MotorController.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index c794a02..5ff549e 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -12,32 +12,42 @@ using namespace Pinetime::Controllers;
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);
+ shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor);
+ longVibTimer = xTimerCreate("longVibTm", APP_TIMER_TICKS(1000), pdTRUE, this, Ring);
}
-void MotorController::Ring(void* p_context) {
- auto* motorController = static_cast<MotorController*>(p_context);
+void MotorController::Ring(TimerHandle_t xTimer) {
+ auto motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
motorController->RunForDuration(50);
}
void MotorController::RunForDuration(uint8_t motorDuration) {
nrf_gpio_pin_clear(PinMap::Motor);
- app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
+ if (xTimerChangePeriod(shortVibTimer, APP_TIMER_TICKS(motorDuration), 0) == pdPASS
+ && xTimerStart(shortVibTimer, 0) == pdPASS) {
+ return;
+ }
+ if (xTimerChangePeriodFromISR(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL) == pdPASS
+ && xTimerStartFromISR(shortVibTimer, NULL) == pdPASS) {
+ return;
+ }
+ nrf_gpio_pin_set(PinMap::Motor);
}
void MotorController::StartRinging() {
+ if (xTimerChangePeriod(longVibTimer, APP_TIMER_TICKS(1000), 0) == pdPASS
+ && xTimerStart(longVibTimer, 0) == pdPASS) {
+ return;
+ }
Ring(this);
- app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
void MotorController::StopRinging() {
- app_timer_stop(longVibTimer);
+ xTimerStop(longVibTimer, 0);
nrf_gpio_pin_set(PinMap::Motor);
}
-void MotorController::StopMotor(void* p_context) {
+void MotorController::StopMotor(TimerHandle_t xTimer) {
nrf_gpio_pin_set(PinMap::Motor);
}