diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-17 10:12:03 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-17 10:27:45 (GMT) |
| commit | ee9dc8f79eaada3ef5ffdcb4bab9bfe8c2219d0b (patch) | |
| tree | 0b5ddf377abe5ee8431175fe2be409e201b45c6d | |
| parent | c37e38517c60a45fca5a03d64962a8f95bf46114 (diff) | |
StartRinging immediately, simplify code
| -rw-r--r-- | src/components/motor/MotorController.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 6eff2ee..547d87b 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -14,30 +14,25 @@ void MotorController::Init() { nrf_gpio_pin_set(PinMap::Motor); shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor); - longVibTimer = xTimerCreate("longVibTm", APP_TIMER_TICKS(1000), pdTRUE, this, Ring); + longVibTimer = xTimerCreate("longVibTm", 1, pdTRUE, this, Ring); } void MotorController::Ring(TimerHandle_t xTimer) { auto motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer)); - + xTimerChangePeriod(motorController->longVibTimer, APP_TIMER_TICKS(1000), 0); motorController->RunForDuration(50); } void MotorController::RunForDuration(uint8_t motorDuration) { - nrf_gpio_pin_clear(PinMap::Motor); if (xTimerChangePeriod(shortVibTimer, APP_TIMER_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVibTimer, 0) == pdPASS) { - return; + nrf_gpio_pin_clear(PinMap::Motor); } - 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); + xTimerChangePeriod(longVibTimer, 1, 0); + xTimerStart(longVibTimer, 0); } void MotorController::StopRinging() { |
