Reworked BLE according to v0.11 of the KTag Beacon Specification #2
4 changed files with 92 additions and 16 deletions
|
@ -154,10 +154,12 @@ void BLE_UpdateStatusPacket(uint8_t current_state)
|
||||||
uint8_t team_ID;
|
uint8_t team_ID;
|
||||||
uint8_t player_ID;
|
uint8_t player_ID;
|
||||||
uint8_t weapon_ID;
|
uint8_t weapon_ID;
|
||||||
|
uint32_t secondary_color;
|
||||||
Protocol_T protocol;
|
Protocol_T protocol;
|
||||||
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &team_ID);
|
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &team_ID);
|
||||||
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_PLAYERID, &player_ID);
|
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_PLAYERID, &player_ID);
|
||||||
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_WEAPONID, &weapon_ID);
|
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_WEAPONID, &weapon_ID);
|
||||||
|
(void) SETTINGS_get_uint32_t(SYSTEMK_SETTING_SECONDARY_COLOR, &secondary_color);
|
||||||
protocol = GetWeaponFromID(weapon_ID).Protocol;
|
protocol = GetWeaponFromID(weapon_ID).Protocol;
|
||||||
uint32_t Team_Color = (uint32_t)PROTOCOLS_GetColor(protocol, team_ID, player_ID);
|
uint32_t Team_Color = (uint32_t)PROTOCOLS_GetColor(protocol, team_ID, player_ID);
|
||||||
|
|
||||||
|
@ -186,10 +188,10 @@ void BLE_UpdateStatusPacket(uint8_t current_state)
|
||||||
Advertising_Data.data[19] = (Team_Color >> 8) & 0xFF;
|
Advertising_Data.data[19] = (Team_Color >> 8) & 0xFF;
|
||||||
Advertising_Data.data[20] = (Team_Color >> 16) & 0xFF;
|
Advertising_Data.data[20] = (Team_Color >> 16) & 0xFF;
|
||||||
Advertising_Data.data[21] = (Team_Color >> 24) & 0xFF;
|
Advertising_Data.data[21] = (Team_Color >> 24) & 0xFF;
|
||||||
Advertising_Data.data[22] = (Team_Color >> 0) & 0xFF; // Secondary Color
|
Advertising_Data.data[22] = (secondary_color >> 0) & 0xFF;
|
||||||
Advertising_Data.data[23] = (Team_Color >> 8) & 0xFF; // Secondary Color
|
Advertising_Data.data[23] = (secondary_color >> 8) & 0xFF;
|
||||||
Advertising_Data.data[24] = (Team_Color >> 16) & 0xFF; // Secondary Color
|
Advertising_Data.data[24] = (secondary_color >> 16) & 0xFF;
|
||||||
Advertising_Data.data[25] = (Team_Color >> 24) & 0xFF; // Secondary Color
|
Advertising_Data.data[25] = (secondary_color >> 24) & 0xFF;
|
||||||
Advertising_Data.data[26] = current_state;
|
Advertising_Data.data[26] = current_state;
|
||||||
Advertising_Data.data[27] = 0xFF;
|
Advertising_Data.data[27] = 0xFF;
|
||||||
Advertising_Data.data[28] = 0xFF;
|
Advertising_Data.data[28] = 0xFF;
|
||||||
|
|
|
@ -60,6 +60,7 @@ static void Playing__Interacting_Entry(StateMachineContext_T * context)
|
||||||
Playing_Entry(context);
|
Playing_Entry(context);
|
||||||
srand(xTaskGetTickCount());
|
srand(xTaskGetTickCount());
|
||||||
}
|
}
|
||||||
|
BLE_UpdateStatusPacket(STATE_PLAYING__INTERACTING);
|
||||||
LOG("Entering the Interacting substate of the Playing state.");
|
LOG("Entering the Interacting substate of the Playing state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ static void Configuring_Entry(StateMachineContext_T *context)
|
||||||
BLEConfigurationResponseTimer = xTimerCreateStatic(
|
BLEConfigurationResponseTimer = xTimerCreateStatic(
|
||||||
"BLEConfigResponse",
|
"BLEConfigResponse",
|
||||||
xBLEConfigurationResponseTimerPeriod,
|
xBLEConfigurationResponseTimerPeriod,
|
||||||
pdTRUE,
|
pdFALSE,
|
||||||
(void *)0,
|
(void *)0,
|
||||||
BLEConfigurationResponseTimerCallback,
|
BLEConfigurationResponseTimerCallback,
|
||||||
&xBLEConfigurationResponseTimerBuffer);
|
&xBLEConfigurationResponseTimerBuffer);
|
||||||
|
@ -106,6 +106,13 @@ static void Configuring_Do(StateMachineContext_T *context)
|
||||||
portBASE_TYPE xStatus;
|
portBASE_TYPE xStatus;
|
||||||
static KEvent_T Event;
|
static KEvent_T Event;
|
||||||
|
|
||||||
|
// For the first hunderd milliseconds, keep updating the Hello packet, since on some platforms (PSoC6), one call is not enough.
|
||||||
|
// TODO: Fix the Hello packet hack on PSoC6.
|
||||||
|
if ((xTaskGetTickCount() - context->Time_At_State_Entry_In_Ticks) < (100 / portTICK_PERIOD_MS))
|
||||||
|
{
|
||||||
|
BLE_UpdateHelloPacket();
|
||||||
|
}
|
||||||
|
|
||||||
xStatus = Receive_KEvent(&Event);
|
xStatus = Receive_KEvent(&Event);
|
||||||
|
|
||||||
if (xStatus == pdPASS)
|
if (xStatus == pdPASS)
|
||||||
|
@ -278,11 +285,87 @@ static SystemKResult_T HandleParameterChangeRequest(BLE_ParameterKey_T key, uint
|
||||||
{
|
{
|
||||||
result = Set_Team_With_Audio_Feedback(team_ID);
|
result = Set_Team_With_Audio_Feedback(team_ID);
|
||||||
}
|
}
|
||||||
|
if (result == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
KLOG_INFO(KLOG_TAG, "Team set to %u over BLE.", team_ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (key == BLE_PARAMETER_KEY_PLAYER_ID)
|
else if (key == BLE_PARAMETER_KEY_PLAYER_ID)
|
||||||
{
|
{
|
||||||
uint8_t player_ID = (uint8_t)value;
|
uint8_t player_ID = (uint8_t)value;
|
||||||
result = Set_Player_With_Audio_Feedback(player_ID);
|
result = Set_Player_With_Audio_Feedback(player_ID);
|
||||||
|
if (result == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
KLOG_INFO(KLOG_TAG, "Player set to %u over BLE.", player_ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (key == BLE_PARAMETER_KEY_GAME_LENGTH)
|
||||||
|
{
|
||||||
|
result = SETTINGS_set_uint32_t(SYSTEMK_SETTING_T_GAME_LENGTH_in_ms, value);
|
||||||
|
|
||||||
|
if (result == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BEEP, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
KLOG_INFO(KLOG_TAG, "Game length set to %lu ms over BLE.", value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BONK, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (key == BLE_PARAMETER_KEY_MAX_HEALTH)
|
||||||
|
{
|
||||||
|
uint8_t max_health = (uint8_t)value;
|
||||||
|
Set_Max_Health(max_health);
|
||||||
|
result = SETTINGS_set_uint8_t(SYSTEMK_SETTING_MAX_HEALTH, max_health);
|
||||||
|
|
||||||
|
if (result == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BEEP, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
KLOG_INFO(KLOG_TAG, "Max health set to %u over BLE.", max_health);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BONK, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (key == BLE_PARAMETER_KEY_SECONDARY_COLOR)
|
||||||
|
{
|
||||||
|
result = SETTINGS_set_uint32_t(SYSTEMK_SETTING_SECONDARY_COLOR, value);
|
||||||
|
|
||||||
|
if (result == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BEEP, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
KLOG_INFO(KLOG_TAG, "Secondary color set to %lu over BLE.", value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BONK, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (key == BLE_PARAMETER_KEY_SPECIAL_WEAPONS_ON_REENTRY)
|
||||||
|
{
|
||||||
|
uint8_t n_weapons_on_reentry = (uint8_t)value;
|
||||||
|
Set_Available_Bombs(n_weapons_on_reentry);
|
||||||
|
result = SETTINGS_set_uint8_t(SYSTEMK_SETTING_N_SPECIAL_WEAPONS_ON_REENTRY, n_weapons_on_reentry);
|
||||||
|
|
||||||
|
if (result == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BEEP, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
KLOG_INFO(KLOG_TAG, "Number of special weapons granted on reentry set to %u over BLE.", n_weapons_on_reentry);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BONK, .Data = (void *)0x00};
|
||||||
|
Perform_Audio_Action(&audio_action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -114,14 +114,4 @@ static void Initializing_Exit(StateMachineContext_T * context)
|
||||||
uint8_t weapon_ID = NERF_LASER_STRIKE_BLASTER_ID;
|
uint8_t weapon_ID = NERF_LASER_STRIKE_BLASTER_ID;
|
||||||
(void) SETTINGS_set_uint8_t(SYSTEMK_SETTING_WEAPONID, weapon_ID);
|
(void) SETTINGS_set_uint8_t(SYSTEMK_SETTING_WEAPONID, weapon_ID);
|
||||||
(void) SETTINGS_Save();
|
(void) SETTINGS_Save();
|
||||||
|
|
||||||
//! \todo TEAM_PURPLE is always one-hit kill.
|
|
||||||
uint8_t team_ID;
|
|
||||||
(void) SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &team_ID);
|
|
||||||
TeamID_t my_common_team_ID = Resolve_Common_Team_ID(team_ID);
|
|
||||||
|
|
||||||
if (my_common_team_ID == TEAM_PURPLE)
|
|
||||||
{
|
|
||||||
Set_Health(10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue