/* * This program source code file is part of SystemK, a library in the KTag project. * * 🛡️ 🃞 * * 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 . */ /* Include Files */ #include "SystemK.h" 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(); // TODO: Get this from settings. Set_Available_Bombs(1); 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); }