WIP: New BLE

This commit is contained in:
Joe Kearney 2025-02-03 20:49:54 -06:00
parent 4fe072f2d3
commit a9212c5a3a
12 changed files with 191 additions and 56 deletions

View file

@ -37,7 +37,8 @@ static const int_fast8_t TAG_RSSI_THRESHOLD = -75;
static void BLEStatusTimerCallback(TimerHandle_t xTimer)
{
BLE_UpdateStatusPacket();
StateMachineContext_T* context = GetContext();
BLE_UpdateStatusPacket(context->States.Current_State);
}
static void GameDurationTimerCallback(TimerHandle_t xTimer)
@ -60,7 +61,7 @@ void Playing_Entry(StateMachineContext_T *context)
BLE_RXd_data.neighbors[slot].TimeToLive_in_ms = 0;
}
BLE_UpdateStatusPacket();
BLE_UpdateStatusPacket(context->States.Current_State);
if (BLE_ScanAndAdvertise() != SYSTEMK_RESULT_SUCCESS)
{
KLOG_ERROR(KLOG_TAG, "Couldn't start BLE!");
@ -92,7 +93,8 @@ void Playing_Entry(StateMachineContext_T *context)
}
// The timer is only needed for timed games.
if (Get_Time_Remaining_in_Game_in_ms() != UINT32_MAX)
if ((Get_Time_Remaining_in_Game_in_ms() != UINT32_MAX) &&
(Get_Time_Remaining_in_Game_in_ms() != 0))
{
if (GameDurationTimer == NULL)
{
@ -129,7 +131,7 @@ void Playing_Exit(StateMachineContext_T *context)
{
LOG("Exiting the Playing state.");
xTimerStop(BLEStatusTimer, portMAX_DELAY);
BLE_UpdateStatusPacket();
BLE_UpdateStatusPacket(context->States.Next_State);
}
void HandleBLEStatusPacket(const BLE_StatusPacket_T *const packet)
@ -202,21 +204,25 @@ void HandleBLETagPacket(const BLE_TagPacket_T *const packet)
{
if (BLE_IsPacketNew(packet->BD_ADDR, BLE_PACKET_TYPE_TAG, packet->event_number))
{
Health_In_Percent = (int16_t)Get_Health();
if (packet->damage > 0)
{
Reduce_Health(packet->damage);
if (Health_In_Percent > 0)
{
Reduce_Health(packet->damage);
ReceivedTagColor = packet->color;
ReceivedTagColor = packet->color;
AudioAction_T audio_action = {.ID = AUDIO_PLAY_TAG_RECEIVED, .Data = (void *)0x00};
Perform_Audio_Action(&audio_action);
AudioAction_T audio_action = {.ID = AUDIO_PLAY_TAG_RECEIVED, .Data = (void *)0x00};
Perform_Audio_Action(&audio_action);
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_TAG_RECEIVED, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&ReceivedTagColor};
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_TAG_RECEIVED, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&ReceivedTagColor};
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
}
}
else if (packet->damage < 0)
{
Health_In_Percent = (uint8_t)Get_Health();
Health_In_Percent -= packet->damage;
if (Health_In_Percent > MAX_HEALTH)
{
@ -236,4 +242,6 @@ void HandleBLETagPacket(const BLE_TagPacket_T *const packet)
}
}
}
BLE_FreePacketBuffer(packet);
}

View file

@ -51,7 +51,7 @@ static void Playing__Tagged_Out_Entry(StateMachineContext_T * context)
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_TAGGED_OUT, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0x00};
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
BLE_UpdateStatusPacket();
BLE_UpdateStatusPacket(STATE_PLAYING__TAGGED_OUT);
Increment_Times_Tagged_Out();
}