diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-16 05:19:28 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-16 05:20:22 (GMT) |
| commit | 1d48a97f09104e6b26159622d1631c781498e6f3 (patch) | |
| tree | d3ce694b3e79549d7c2bccb975b308273410f536 | |
| parent | c92fdb2e8cec3c581124c5efcfb5297ac4cfdcb5 (diff) | |
replace pdMS_TO_TICKS with APP_TIMER_TICKS; more tweaks
| -rw-r--r-- | src/components/alarm/AlarmController.cpp | 2 | ||||
| -rw-r--r-- | src/components/motor/MotorController.cpp | 11 | ||||
| -rw-r--r-- | src/components/timer/TimerController.cpp | 2 |
3 files changed, 9 insertions, 6 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp index 33a58fe..cea679f 100644 --- a/src/components/alarm/AlarmController.cpp +++ b/src/components/alarm/AlarmController.cpp @@ -77,7 +77,7 @@ void AlarmController::ScheduleAlarm() { // now can convert back to a time_point alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime)); auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count(); - xTimerChangePeriod(alarmAppTimer, pdMS_TO_TICKS(mSecToAlarm), 0); + xTimerChangePeriod(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), 0); xTimerStart(alarmAppTimer, 0); state = AlarmState::Set; diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index a02c037..5ff549e 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -14,7 +14,7 @@ void MotorController::Init() { nrf_gpio_pin_set(PinMap::Motor); shortVibTimer = xTimerCreate("shortVibTm", 1, pdFALSE, nullptr, StopMotor); - longVibTimer = xTimerCreate("longVibTm", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); + longVibTimer = xTimerCreate("longVibTm", APP_TIMER_TICKS(1000), pdTRUE, this, Ring); } void MotorController::Ring(TimerHandle_t xTimer) { @@ -24,11 +24,11 @@ void MotorController::Ring(TimerHandle_t xTimer) { void MotorController::RunForDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(PinMap::Motor); - if (xTimerChangePeriod(shortVibTimer, pdMS_TO_TICKS(motorDuration), 0) == pdPASS + if (xTimerChangePeriod(shortVibTimer, APP_TIMER_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVibTimer, 0) == pdPASS) { return; } - if (xTimerChangePeriodFromISR(shortVibTimer, pdMS_TO_TICKS(motorDuration), NULL) == pdPASS + if (xTimerChangePeriodFromISR(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL) == pdPASS && xTimerStartFromISR(shortVibTimer, NULL) == pdPASS) { return; } @@ -36,8 +36,11 @@ void MotorController::RunForDuration(uint8_t motorDuration) { } void MotorController::StartRinging() { + if (xTimerChangePeriod(longVibTimer, APP_TIMER_TICKS(1000), 0) == pdPASS + && xTimerStart(longVibTimer, 0) == pdPASS) { + return; + } Ring(this); - xTimerStart(longVibTimer, 0); } void MotorController::StopRinging() { diff --git a/src/components/timer/TimerController.cpp b/src/components/timer/TimerController.cpp index 1988094..115aa27 100644 --- a/src/components/timer/TimerController.cpp +++ b/src/components/timer/TimerController.cpp @@ -24,7 +24,7 @@ void TimerController::Init() { void TimerController::StartTimer(uint32_t duration) { xTimerStop(timerAppTimer,0); auto currentTicks = xTaskGetTickCount(); - TickType_t durationTicks = pdMS_TO_TICKS(duration); + TickType_t durationTicks = APP_TIMER_TICKS(duration); xTimerChangePeriod(timerAppTimer, durationTicks, 0); xTimerStart(timerAppTimer, 0); endTicks = currentTicks + durationTicks; |
