This was done to support the new KTag Konfigurator app, which Jack created for his Senior Design project. Co-authored-by: Joe Kearney <joe@clubk.club> Reviewed-on: #2
156 lines
6.1 KiB
C
156 lines
6.1 KiB
C
/*
|
|
* This program source code file is part of SystemK, a library in the KTag project.
|
|
*
|
|
* 🛡️ <https://ktag.clubk.club> 🃞
|
|
*
|
|
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
|
* later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
* details.
|
|
*
|
|
* There should be a copy of the GNU Affero General Public License in the LICENSE
|
|
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/* Include Files */
|
|
#include "SystemK.h"
|
|
|
|
static const char *KLOG_TAG = "STARTING_GAME__COUNTING_DOWN";
|
|
|
|
static void Starting_Game__Counting_Down_Entry(StateMachineContext_T * context);
|
|
static void Starting_Game__Counting_Down_Do(StateMachineContext_T * context);
|
|
static void Starting_Game__Counting_Down_Exit(StateMachineContext_T * context);
|
|
|
|
static uint_fast8_t N_Lights_Lit = 0;
|
|
|
|
//! Activities for the **Counting Down** substate of the **Starting Game** state.
|
|
const StateActivity_T STATE_STARTING_GAME__COUNTING_DOWN_Activities =
|
|
{
|
|
.Entry = Starting_Game__Counting_Down_Entry,
|
|
.Do = Starting_Game__Counting_Down_Do,
|
|
.Exit = Starting_Game__Counting_Down_Exit
|
|
};
|
|
|
|
//! Sets up the Counting Down substate.
|
|
/*!
|
|
* \param context Context in which this substate is being run.
|
|
*/
|
|
static void Starting_Game__Counting_Down_Entry(StateMachineContext_T * context)
|
|
{
|
|
LOG("Entering the Counting Down substate of the Starting Game state.");
|
|
|
|
Prepare_Tag();
|
|
Reset_Shots_Fired();
|
|
Reset_Tags_Received();
|
|
Reset_Times_Tagged_Out();
|
|
|
|
uint8_t n_bombs;
|
|
if (SETTINGS_get_uint8_t(SYSTEMK_SETTING_N_SPECIAL_WEAPONS_ON_REENTRY, &n_bombs) == SYSTEMK_RESULT_SUCCESS)
|
|
{
|
|
Set_Available_Bombs(n_bombs);
|
|
}
|
|
else
|
|
{
|
|
Set_Available_Bombs(0);
|
|
KLOG_ERROR(KLOG_TAG, "Error getting available bombs!");
|
|
}
|
|
|
|
N_Lights_Lit = 0;
|
|
AudioAction_T audio_action = {.ID = AUDIO_SILENCE, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_ALL_OFF, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
}
|
|
|
|
//! Executes the Counting Down substate.
|
|
/*!
|
|
* \param context Context in which this substate is being run.
|
|
*/
|
|
static void Starting_Game__Counting_Down_Do(StateMachineContext_T * context)
|
|
{
|
|
portBASE_TYPE xStatus;
|
|
static KEvent_T Event;
|
|
|
|
xStatus = Receive_KEvent(&Event);
|
|
|
|
if (xStatus == pdPASS)
|
|
{
|
|
switch (Event.ID)
|
|
{
|
|
default:
|
|
// All events are ignored in this state.
|
|
ProcessUnhandledEvent(&Event);
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ((N_Lights_Lit == 0) && (GetTimeInState_in_ms(context) >= 1000))
|
|
{
|
|
N_Lights_Lit++;
|
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BOOP, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_COUNTDOWN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&N_Lights_Lit};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
}
|
|
else if ((N_Lights_Lit == 1) && (GetTimeInState_in_ms(context) >= 2000))
|
|
{
|
|
N_Lights_Lit++;
|
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BOOP, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_COUNTDOWN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&N_Lights_Lit};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
}
|
|
else if ((N_Lights_Lit == 2) && (GetTimeInState_in_ms(context) >= 3000))
|
|
{
|
|
N_Lights_Lit++;
|
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BOOP, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_COUNTDOWN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&N_Lights_Lit};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
}
|
|
else if ((N_Lights_Lit == 3) && (GetTimeInState_in_ms(context) >= 4000))
|
|
{
|
|
N_Lights_Lit++;
|
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BOOP, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_COUNTDOWN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&N_Lights_Lit};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
}
|
|
else if ((N_Lights_Lit == 4) && (GetTimeInState_in_ms(context) >= 5000))
|
|
{
|
|
N_Lights_Lit++;
|
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BOOP, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_COUNTDOWN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&N_Lights_Lit};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
}
|
|
else if ((N_Lights_Lit == 5) && (GetTimeInState_in_ms(context) >= 6000))
|
|
{
|
|
N_Lights_Lit++;
|
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_BEEP, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_ALL_OFF, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
|
|
Event.ID = KEVENT_AUTOMATIC_TRANSITION;
|
|
Event.Data = NULL;
|
|
Transition_For_Event(context, STATE_PLAYING__INTERACTING, &Event);
|
|
}
|
|
}
|
|
|
|
//! Cleans up the Counting Down substate.
|
|
/*!
|
|
* \param context Context in which this substate is being run.
|
|
*/
|
|
static void Starting_Game__Counting_Down_Exit(StateMachineContext_T * context)
|
|
{
|
|
// Last of all, exit the state containing this substate.
|
|
Starting_Game_Exit(context);
|
|
}
|