diff --git a/components/BLE/BLE.c b/components/BLE/BLE.c index c6b727b..44d5bef 100644 --- a/components/BLE/BLE.c +++ b/components/BLE/BLE.c @@ -343,50 +343,49 @@ SystemKResult_T BLE_Quiet(uint32_t duration_ms) // Already quiet; reset timer with new duration if duration_ms > 0. if (duration_ms > 0) { - // Stop and delete existing timer if it exists. + // Stop the timer and change the period if it is already running. 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; + xTimerChangePeriod(BLEUnquietTimer, pdMS_TO_TICKS(duration_ms), 0); + xTimerStart(BLEUnquietTimer, 0); } else { - if (xTimerStart(BLEUnquietTimer, 0) != pdPASS) + // There should already be a timer, but just in case... + BLEUnquietTimer = xTimerCreateStatic( + "BLEUnquietTimer", + pdMS_TO_TICKS(duration_ms), + pdFALSE, + (void *)0, + Unquiet_Timer_Callback, + &xBLEUnquietTimerBuffer); + + if (BLEUnquietTimer == NULL) { - KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!"); - result = SYSTEMK_RESULT_FAILED_TO_START_RTOS_TIMER; + 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 duration_ms is 0, stop the timer to stay quiet indefinitely. if (BLEUnquietTimer != NULL) { xTimerStop(BLEUnquietTimer, 0); - xTimerDelete(BLEUnquietTimer, 0); - BLEUnquietTimer = NULL; } } result = SYSTEMK_RESULT_SUCCESS; } - else if (Host_And_Controller_Synced == true) { Is_Quiet = true; @@ -433,6 +432,8 @@ SystemKResult_T BLE_Unquiet(void) { SystemKResult_T result = SYSTEMK_RESULT_NOT_READY; + KLOG_INFO(TAG, "BLE_Unquiet()"); + if (Is_Quiet == false) { // Already unquiet; no action needed. diff --git a/components/SystemK b/components/SystemK index 88c81dc..e0e7fdf 160000 --- a/components/SystemK +++ b/components/SystemK @@ -1 +1 @@ -Subproject commit 88c81dc405ef5d10fcf67d80d349bc1a7924e6f9 +Subproject commit e0e7fdf1aef151390c1e82d95e89e39038206bca