Pulled in the latest SystemK (with BLE v0.12) #5

Merged
Joe merged 14 commits from BLE_Protocol_v0.12 into main 2025-09-01 18:05:45 +00:00
2 changed files with 98 additions and 3 deletions
Showing only changes of commit fcd88a5ae1 - Show all commits

View file

@ -13,6 +13,11 @@ static const char *TAG = "BLE";
static bool Host_And_Controller_Synced = false; static bool Host_And_Controller_Synced = false;
static bool Is_Scanning = false; static bool Is_Scanning = false;
static bool Is_Advertising = false; static bool Is_Advertising = false;
static bool Is_Quiet = false;
static bool Was_Advertising = false;
static TimerHandle_t BLEUnquietTimer = NULL;
static StaticTimer_t xBLEUnquietTimerBuffer;
static uint8_t Advertising_Data[BLE_KTAG_PACKET_TOTAL_SIZE] = {0x1E, 0xFF, 0xFF, 0xFF, 'K', 'T', 'a', 'g'}; static uint8_t Advertising_Data[BLE_KTAG_PACKET_TOTAL_SIZE] = {0x1E, 0xFF, 0xFF, 0xFF, 'K', 'T', 'a', 'g'};
@ -271,8 +276,17 @@ SystemKResult_T BLE_ScanAndAdvertise(void)
} }
if (Is_Advertising == false) if (Is_Advertising == false)
{ {
ble_advertise(); if (Is_Quiet == false)
Is_Advertising = true; {
ble_advertise();
Is_Advertising = true;
}
else
{
// If we are quiet, we don't want to advertise yet,
// but we will remember that we were asked to advertise.
Was_Advertising = true;
}
} }
result = SYSTEMK_RESULT_SUCCESS; result = SYSTEMK_RESULT_SUCCESS;
} }
@ -311,5 +325,86 @@ SystemKResult_T BLE_StopAdvertising(void)
result = SYSTEMK_RESULT_SUCCESS; result = SYSTEMK_RESULT_SUCCESS;
} }
return result;
}
static void Unquiet_Timer_Callback(TimerHandle_t xTimer)
{
KLOG_INFO(TAG, "Unquiet timer expired after %lu ms.", (xTimerGetPeriod(xTimer) / portTICK_PERIOD_MS));
BLE_Unquiet();
}
SystemKResult_T BLE_Quiet(uint32_t duration_ms)
{
SystemKResult_T result = SYSTEMK_RESULT_NOT_READY;
if (Is_Quiet == true)
{
// Already quiet; no action needed.
return SYSTEMK_RESULT_SUCCESS;
}
if (Host_And_Controller_Synced == true)
{
Is_Quiet = true;
if (Is_Advertising == true)
{
ble_gap_adv_stop();
Is_Advertising = false;
Was_Advertising = true;
}
if (duration_ms > 0)
{
// Set a timer to unquiet after the specified 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!");
}
else
{
if (xTimerStart(BLEUnquietTimer, 0) != pdPASS)
{
KLOG_ERROR(TAG, "Couldn't start the BLEUnquietTimer!");
}
}
}
result = SYSTEMK_RESULT_SUCCESS;
}
return result;
}
SystemKResult_T BLE_Unquiet(void)
{
SystemKResult_T result = SYSTEMK_RESULT_NOT_READY;
if (Is_Quiet == false)
{
// Already unquiet; no action needed.
return SYSTEMK_RESULT_SUCCESS;
}
if (Host_And_Controller_Synced == true)
{
Is_Quiet = false;
if (Was_Advertising == true)
{
ble_advertise();
Is_Advertising = true;
Was_Advertising = false;
}
result = SYSTEMK_RESULT_SUCCESS;
}
return result; return result;
} }

@ -1 +1 @@
Subproject commit fb1a4ab07b990fef8f957ef7c5f806649e126d0f Subproject commit c514219ccc3978fa27bb7925a85ce826c37e6e63