Added BLE events
This commit is contained in:
parent
58f379dc18
commit
82ec410264
10 changed files with 121 additions and 23 deletions
|
@ -128,3 +128,70 @@ void ProcessUnhandledEvent(KEvent_T * Event)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleBLEEventPacket(const BLE_EventPacket_T *const packet, StateMachineContext_T *context)
|
||||
{
|
||||
if (BLE_IsBLEPacketForMe(packet->target_BD_ADDR))
|
||||
{
|
||||
if (BLE_IsPacketNew(packet->BD_ADDR, BLE_PACKET_TYPE_EVENT, packet->event_number))
|
||||
{
|
||||
if (packet->event_ID == BLE_EVENT_CONFIGURED)
|
||||
{
|
||||
if (context->States.Current_State == STATE_CONFIGURING)
|
||||
{
|
||||
static KEvent_T Event =
|
||||
{
|
||||
.ID = KEVENT_BLE_EVENT_RECEIVED,
|
||||
.Data = (void *)BLE_EVENT_CONFIGURED
|
||||
};
|
||||
Transition_For_Event(context, STATE_READY, &Event);
|
||||
}
|
||||
}
|
||||
else if (packet->event_ID == BLE_EVENT_CONFIGURE)
|
||||
{
|
||||
if (context->States.Current_State == STATE_READY)
|
||||
{
|
||||
static KEvent_T Event =
|
||||
{
|
||||
.ID = KEVENT_BLE_EVENT_RECEIVED,
|
||||
.Data = (void *)BLE_EVENT_CONFIGURE
|
||||
};
|
||||
Transition_For_Event(context, STATE_CONFIGURING, &Event);
|
||||
}
|
||||
}
|
||||
else if (packet->event_ID == BLE_EVENT_WRAPUP_COMPLETE)
|
||||
{
|
||||
if (context->States.Current_State == STATE_WRAPPING_UP)
|
||||
{
|
||||
StateID_T next_state = (StateID_T)packet->event_data;
|
||||
|
||||
if (next_state < STATE_IS_OUT_OF_RANGE)
|
||||
{
|
||||
static KEvent_T Event =
|
||||
{
|
||||
.ID = KEVENT_BLE_EVENT_RECEIVED,
|
||||
.Data = (void *)BLE_EVENT_WRAPUP_COMPLETE
|
||||
};
|
||||
Transition_For_Event(context, next_state, &Event);
|
||||
}
|
||||
else
|
||||
{
|
||||
KLOG_WARN("STATE", "Received a BLE Wrapup Complete event with an invalid Next State!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (packet->event_ID == BLE_EVENT_GAME_OVER)
|
||||
{
|
||||
if ((context->States.Current_State == STATE_PLAYING__INTERACTING) ||
|
||||
(context->States.Current_State == STATE_PLAYING__TAGGED_OUT))
|
||||
{
|
||||
KEvent_T game_over_event = { .ID = KEVENT_GAME_OVER, .Data = (void *)0x00 };
|
||||
Post_KEvent(&game_over_event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BLE_FreePacketBuffer((BLE_GenericPacketType_T *)packet);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue