From 4b57063d034646a5d9a55827d300e570d8d02c03 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Fri, 12 Dec 2025 23:33:08 +0000 Subject: Make chime play twice instead of once --- src/components/motor/MotorController.cpp | 16 ++++++++++++++++ src/components/motor/MotorController.h | 4 ++++ src/displayapp/DisplayApp.cpp | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) 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(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); diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index ab8c956e..04b08b08 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -13,15 +13,19 @@ namespace Pinetime { void Init(); void RunForDuration(uint8_t motorDuration); + void Pulse(uint32_t interval, uint8_t repetitions); void StartRinging(); void StopRinging(); bool IsRinging(); private: static void Ring(TimerHandle_t xTimer); + static void RingWithLatch(TimerHandle_t xTimer); static void StopMotor(TimerHandle_t xTimer); TimerHandle_t shortVib; TimerHandle_t longVib; + TimerHandle_t pulse; + uint8_t pulseLatch; }; } } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 84fa6036..4a01db09 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -483,7 +483,7 @@ void DisplayApp::Refresh() { break; case Messages::Chime: LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None); - motorController.RunForDuration(35); + motorController.Pulse(1000, 2); break; } } -- cgit v1.2.3-70-g09d2