From f367b5ae5b794d6b4f3638038be8a11a9e92943e Mon Sep 17 00:00:00 2001 From: Joe Kearney Date: Sat, 16 Aug 2025 11:34:44 -0500 Subject: [PATCH] BLE_Quiet() now resets the timer. --- components/BLE/BLE.c | 51 +++++++++++++++++++++++++++++++++++++++++--- components/SystemK | 2 +- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/components/BLE/BLE.c b/components/BLE/BLE.c index e06087f..c6b727b 100644 --- a/components/BLE/BLE.c +++ b/components/BLE/BLE.c @@ -340,11 +340,54 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms) if (Is_Quiet == true) { - // Already quiet; no action needed. - return SYSTEMK_RESULT_SUCCESS; + // Already quiet; reset timer with new duration if duration_ms > 0. + if (duration_ms > 0) + { + // Stop and delete existing timer if it exists. + if (BLEUnquietTimer != NULL) + { + xTimerStop(BLEUnquietTimer, 0); + xTimerDelete(BLEUnquietTimer, 0); + BLEUnquietTimer = NULL; + } + + // Create and start new timer with the new duration. + BLEUnquietTimer = xTimerCreateStatic( + "BLEUnquietTimer", + pdMS_TO_TICKS(duration_ms), + pdFALSE, + (void *)0, + Unquiet_Timer_Callback, + &xBLEUnquietTimerBuffer); + + if (BLEUnquietTimer == NULL) + { + KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER; + } + else + { + if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) + { + KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER; + } + } + } + else + { + // If duration_ms is 0, stop and delete the timer to stay quiet indefinitely. + if (BLEUnquietTimer != NULL) + { + xTimerStop(BLEUnquietTimer, 0); + xTimerDelete(BLEUnquietTimer, 0); + BLEUnquietTimer = NULL; + } + } + result = SYSTEMK_RESULT_SUCCESS; } - if (Host_And_Controller_Synced == true) + else if (Host_And_Controller_Synced == true) { Is_Quiet = true; @@ -369,12 +412,14 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms) if (BLEUnquietTimer == NULL) { KLOG_ERROR(TAG, "Couldn't create the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_CREATE_RTOS_TIMER; } else { if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) { KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); + result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER; } } } diff --git a/components/SystemK b/components/SystemK index bb91512..88c81dc 160000 --- a/components/SystemK +++ b/components/SystemK @@ -1 +1 @@ -Subproject commit bb915121e8e9c8b2679397f4554fa9bc2d836b67 +Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9