WIP: New BLE
This commit is contained in:
parent
4fe072f2d3
commit
a9212c5a3a
12 changed files with 191 additions and 56 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -52,7 +52,8 @@ static void Configuring_Entry(StateMachineContext_T *context)
|
|||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_MENU, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0x00};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
|
||||
BLE_UpdateStatusPacket();
|
||||
BLE_UpdateHelloPacket();
|
||||
|
||||
if (BLE_ScanAndAdvertise() != SYSTEMK_RESULT_SUCCESS)
|
||||
{
|
||||
KLOG_ERROR(KLOG_TAG, "Couldn't start BLE!");
|
||||
|
@ -150,6 +151,7 @@ static void Configuring_Do(StateMachineContext_T *context)
|
|||
CurrentMenuItem->OnFocus(true);
|
||||
}
|
||||
}
|
||||
BLE_UpdateHelloPacket();
|
||||
break;
|
||||
|
||||
case KEVENT_TRIGGER_SWITCH_RELEASED:
|
||||
|
@ -180,6 +182,8 @@ static void Configuring_Do(StateMachineContext_T *context)
|
|||
{
|
||||
KLOG_WARN(KLOG_TAG, "Failed to increment team!");
|
||||
}
|
||||
|
||||
BLE_UpdateHelloPacket();
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -44,7 +44,8 @@ const StateActivity_T STATE_INITIALIZING_Activities =
|
|||
*/
|
||||
static void Initializing_Entry(StateMachineContext_T * context)
|
||||
{
|
||||
LOG("Entering the Initializing state.");
|
||||
KLOG_INFO("SystemK", "Using SystemK version %s.", SYSTEMK_VERSION_STRING);
|
||||
|
||||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_TEST_PATTERN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0x00};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
AudioAction_T audio_action = {.ID = AUDIO_PLAY_STARTUP_SOUND, .Play_To_Completion = true, .Data = (void *)0x00};
|
||||
|
|
|
@ -22,13 +22,6 @@
|
|||
/* Include Files */
|
||||
#include "SystemK.h"
|
||||
|
||||
const StateActivity_T STATE_DEFAULT_Activities =
|
||||
{
|
||||
.Entry = NULL,
|
||||
.Do = NULL,
|
||||
.Exit = NULL
|
||||
};
|
||||
|
||||
//! Activities for the top-level state machine.
|
||||
/*!
|
||||
* This array is indexed by #StateID_T (except there is no entry for
|
||||
|
@ -37,7 +30,6 @@ const StateActivity_T STATE_DEFAULT_Activities =
|
|||
*/
|
||||
static const StateActivity_T * Activities[] =
|
||||
{
|
||||
&STATE_DEFAULT_Activities,
|
||||
&STATE_INITIALIZING_Activities,
|
||||
&STATE_REPROGRAMMING_Activities,
|
||||
&STATE_CONFIGURING_Activities,
|
||||
|
@ -62,6 +54,11 @@ static StateMachineContext_T Context =
|
|||
.Time_At_State_Entry_In_Ticks = 0,
|
||||
};
|
||||
|
||||
StateMachineContext_T* GetContext()
|
||||
{
|
||||
return &Context;
|
||||
}
|
||||
|
||||
TaskHandle_t State_Machine_Task_Handle;
|
||||
|
||||
void State_Machine_Task(void * pvParameters)
|
||||
|
|
|
@ -36,22 +36,21 @@
|
|||
*/
|
||||
typedef enum
|
||||
{
|
||||
STATE_DEFAULT = 0,
|
||||
STATE_INITIALIZING = 1,
|
||||
STATE_REPROGRAMMING = 2,
|
||||
STATE_CONFIGURING = 3,
|
||||
STATE_READY = 4,
|
||||
STATE_INITIALIZING = 0,
|
||||
STATE_REPROGRAMMING = 1,
|
||||
STATE_CONFIGURING = 2,
|
||||
STATE_READY = 3,
|
||||
|
||||
// Substates of STATE_STARTING_GAME
|
||||
STATE_STARTING_GAME__INSTIGATING = 5,
|
||||
STATE_STARTING_GAME__RESPONDING = 6,
|
||||
STATE_STARTING_GAME__COUNTING_DOWN = 7,
|
||||
STATE_STARTING_GAME__INSTIGATING = 4,
|
||||
STATE_STARTING_GAME__RESPONDING = 5,
|
||||
STATE_STARTING_GAME__COUNTING_DOWN = 6,
|
||||
|
||||
// Substates of STATE_PLAYING
|
||||
STATE_PLAYING__INTERACTING = 8,
|
||||
STATE_PLAYING__TAGGED_OUT = 9,
|
||||
STATE_PLAYING__INTERACTING = 7,
|
||||
STATE_PLAYING__TAGGED_OUT = 8,
|
||||
|
||||
STATE_WRAPPING_UP = 10,
|
||||
STATE_WRAPPING_UP = 9,
|
||||
|
||||
// STATE_IS_OUT_OF_RANGE is one more than the last valid state.
|
||||
STATE_IS_OUT_OF_RANGE,
|
||||
|
@ -120,6 +119,8 @@ inline uint32_t GetTimeInState_in_ms(StateMachineContext_T * context)
|
|||
return result;
|
||||
}
|
||||
|
||||
StateMachineContext_T* GetContext();
|
||||
|
||||
#include "State_Configuring.h"
|
||||
#include "State_Ready.h"
|
||||
#include "State_Initializing.h"
|
||||
|
|
|
@ -47,7 +47,7 @@ static void Ready_Entry(StateMachineContext_T * context)
|
|||
LOG("Entering the Ready state.");
|
||||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_IDLE, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0x00};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
BLE_UpdateStatusPacket();
|
||||
BLE_UpdateStatusPacket(STATE_READY);
|
||||
if (BLE_ScanAndAdvertise() != SYSTEMK_RESULT_SUCCESS)
|
||||
{
|
||||
KLOG_ERROR(KLOG_TAG, "Couldn't start BLE!");
|
||||
|
|
|
@ -47,7 +47,7 @@ static void Wrapping_Up_Entry(StateMachineContext_T * context)
|
|||
LOG("Entering the Wrapping Up state.");
|
||||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_IDLE, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0x00};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
BLE_UpdateStatusPacket();
|
||||
BLE_UpdateStatusPacket(STATE_WRAPPING_UP);
|
||||
if (BLE_ScanAndAdvertise() != SYSTEMK_RESULT_SUCCESS)
|
||||
{
|
||||
KLOG_ERROR(KLOG_TAG, "Couldn't start BLE!");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue