aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/motor/MotorController.cpp
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2025-12-12 23:33:08 +0000
committerLeonardo Bishop <me@leonardobishop.net>2026-01-07 23:51:11 +0000
commit4b57063d034646a5d9a55827d300e570d8d02c03 (patch)
tree4b1a154311eb42aac642142c3fcfd800f05d2424 /src/components/motor/MotorController.cpp
parent0fabfe99d9115c5e258a14fd0c985d300ee41f2d (diff)
Make chime play twice instead of oncelocal
Diffstat (limited to 'src/components/motor/MotorController.cpp')
-rw-r--r--src/components/motor/MotorController.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index d3bd2cf3..3984a7b2 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -11,6 +11,7 @@ void MotorController::Init() {
shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor);
longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring);
+ pulse = xTimerCreate("pulse", 1, pdTRUE, this, RingWithLatch);
}
void MotorController::Ring(TimerHandle_t xTimer) {
@@ -18,12 +19,27 @@ void MotorController::Ring(TimerHandle_t xTimer) {
motorController->RunForDuration(50);
}
+void MotorController::RingWithLatch(TimerHandle_t xTimer) {
+ auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
+ if (--(motorController->pulseLatch) == 0) {
+ xTimerStop(motorController->pulse, 0);
+ }
+ 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::Pulse(uint32_t interval, uint8_t repetitions) {
+ pulseLatch = repetitions;
+ if (xTimerChangePeriod(pulse, pdMS_TO_TICKS(interval), 0) == pdPASS) {
+ xTimerStart(pulse, 0);
+ }
+}
+
void MotorController::StartRinging() {
RunForDuration(50);
xTimerStart(longVib, 0);