Initial public release of SystemK.
This commit is contained in:
parent
387f57cdda
commit
6f51f5b006
129 changed files with 11654 additions and 2 deletions
39
States/Starting_Game/State_Starting_Game.c
Normal file
39
States/Starting_Game/State_Starting_Game.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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"
|
||||
|
||||
void Starting_Game_Entry(StateMachineContext_T * context)
|
||||
{
|
||||
|
||||
#ifdef LOG_STATE_MACHINE
|
||||
LOG("Entering the Starting Game state.");
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
#endif // LOG_STATE_MACHINE
|
||||
|
||||
AudioAction_T audio_action = {.ID = AUDIO_PLAY_STARTING_THEME, .Data = (void *)0x00};
|
||||
Perform_Audio_Action(&audio_action);
|
||||
}
|
||||
|
||||
void Starting_Game_Exit(StateMachineContext_T * context)
|
||||
{
|
||||
}
|
34
States/Starting_Game/State_Starting_Game.h
Normal file
34
States/Starting_Game/State_Starting_Game.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef STATE_STARTING_GAME_H
|
||||
#define STATE_STARTING_GAME_H
|
||||
|
||||
|
||||
extern void Starting_Game_Entry(StateMachineContext_T * context);
|
||||
extern void Starting_Game_Exit(StateMachineContext_T * context);
|
||||
|
||||
/* Include Files */
|
||||
#include "States/Starting_Game/State_Starting_Game__Counting_Down.h"
|
||||
#include "States/Starting_Game/State_Starting_Game__Instigating.h"
|
||||
#include "States/Starting_Game/State_Starting_Game__Responding.h"
|
||||
|
||||
#endif // STATE_STARTING_GAME_H
|
145
States/Starting_Game/State_Starting_Game__Counting_Down.c
Normal file
145
States/Starting_Game/State_Starting_Game__Counting_Down.c
Normal file
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* 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 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);
|
||||
}
|
32
States/Starting_Game/State_Starting_Game__Counting_Down.h
Normal file
32
States/Starting_Game/State_Starting_Game__Counting_Down.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef STATE_STARTING_GAME__COUNTING_DOWN_H
|
||||
#define STATE_STARTING_GAME__COUNTING_DOWN_H
|
||||
|
||||
/* Include Files */
|
||||
|
||||
/* Definitions */
|
||||
|
||||
/* External Data */
|
||||
extern const StateActivity_T STATE_STARTING_GAME__COUNTING_DOWN_Activities;
|
||||
|
||||
#endif // STATE_STARTING_GAME__COUNTING_DOWN_H
|
137
States/Starting_Game/State_Starting_Game__Instigating.c
Normal file
137
States/Starting_Game/State_Starting_Game__Instigating.c
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* 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 void Starting_Game__Instigating_Entry(StateMachineContext_T * context);
|
||||
static void Starting_Game__Instigating_Do(StateMachineContext_T * context);
|
||||
static void Starting_Game__Instigating_Exit(StateMachineContext_T * context);
|
||||
|
||||
static TickType_t Period_Start = 0;
|
||||
static uint_fast8_t N_Lights_Lit = 0;
|
||||
|
||||
static const char *KLOG_TAG = "STATE_STARTING_GAME__INSTIGATING";
|
||||
|
||||
//! Activities for the **Instigating** substate of the **Starting Game** state.
|
||||
const StateActivity_T STATE_STARTING_GAME__INSTIGATING_Activities =
|
||||
{
|
||||
.Entry = Starting_Game__Instigating_Entry,
|
||||
.Do = Starting_Game__Instigating_Do,
|
||||
.Exit = Starting_Game__Instigating_Exit
|
||||
};
|
||||
|
||||
//! Sets up the Instigating substate.
|
||||
/*!
|
||||
* \param context Context in which this substate is being run.
|
||||
*/
|
||||
static void Starting_Game__Instigating_Entry(StateMachineContext_T * context)
|
||||
{
|
||||
// First of all, enter the state containing this substate.
|
||||
Starting_Game_Entry(context);
|
||||
|
||||
LOG("Entering the Instigating substate of the Starting Game state.");
|
||||
|
||||
Set_Time_Remaining_in_Game(UINT32_MAX);
|
||||
uint32_t start_game_time_in_ms;
|
||||
(void) SETTINGS_get_uint32_t(SYSTEMK_SETTING_T_START_GAME_in_ms, &start_game_time_in_ms);
|
||||
Set_Time_Remaining_Until_Countdown(start_game_time_in_ms);
|
||||
BLE_UpdateInstigationPacket(Get_Time_Remaining_in_Game_in_ms(), Get_Time_Remaining_Until_Countdown_in_ms());
|
||||
if (BLE_ScanAndAdvertise() != SYSTEMK_RESULT_SUCCESS)
|
||||
{
|
||||
KLOG_ERROR(KLOG_TAG, "Couldn't start BLE!");
|
||||
}
|
||||
|
||||
Period_Start = xTaskGetTickCount();
|
||||
}
|
||||
|
||||
//! Executes the Instigating substate.
|
||||
/*!
|
||||
* \param context Context in which this substate is being run.
|
||||
*/
|
||||
static void Starting_Game__Instigating_Do(StateMachineContext_T * context)
|
||||
{
|
||||
portBASE_TYPE xStatus;
|
||||
static KEvent_T Event;
|
||||
|
||||
xStatus = Receive_KEvent(&Event);
|
||||
|
||||
if (xStatus == pdPASS)
|
||||
{
|
||||
switch (Event.ID)
|
||||
{
|
||||
case KEVENT_PLAY_PRESSED_ON_REMOTE:
|
||||
Transition_For_Event(context, STATE_STARTING_GAME__COUNTING_DOWN, &Event);
|
||||
break;
|
||||
|
||||
default:
|
||||
// All other events are ignored in this state.
|
||||
ProcessUnhandledEvent(&Event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for T_start_game before proceeding.
|
||||
uint32_t start_game_time_in_ms;
|
||||
(void) SETTINGS_get_uint32_t(SYSTEMK_SETTING_T_START_GAME_in_ms, &start_game_time_in_ms);
|
||||
if (GetTimeInState_in_ms(context) > start_game_time_in_ms)
|
||||
{
|
||||
static KEvent_T Event;
|
||||
Event.ID = KEVENT_AUTOMATIC_TRANSITION;
|
||||
Event.Data = NULL;
|
||||
Transition_For_Event(context, STATE_STARTING_GAME__COUNTING_DOWN, &Event);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t period_time_in_ms = (xTaskGetTickCount() - Period_Start) * portTICK_PERIOD_MS;
|
||||
uint32_t time_remaining_until_countdown_in_ms = start_game_time_in_ms - GetTimeInState_in_ms(context);
|
||||
Set_Time_Remaining_Until_Countdown(time_remaining_until_countdown_in_ms);
|
||||
|
||||
if (period_time_in_ms > 150)
|
||||
{
|
||||
BLE_UpdateInstigationPacket(Get_Time_Remaining_in_Game_in_ms(), Get_Time_Remaining_Until_Countdown_in_ms());
|
||||
|
||||
// Toggle the lights.
|
||||
if (N_Lights_Lit == 0)
|
||||
{
|
||||
N_Lights_Lit = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
N_Lights_Lit = 0;
|
||||
}
|
||||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_COUNTDOWN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&N_Lights_Lit};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
|
||||
// Start a new period.
|
||||
Period_Start = xTaskGetTickCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Cleans up the Instigating substate.
|
||||
/*!
|
||||
* \param context Context in which this substate is being run.
|
||||
*/
|
||||
static void Starting_Game__Instigating_Exit(StateMachineContext_T * context)
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
32
States/Starting_Game/State_Starting_Game__Instigating.h
Normal file
32
States/Starting_Game/State_Starting_Game__Instigating.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef STATE_STARTING_GAME__INSTIGATING_H
|
||||
#define STATE_STARTING_GAME__INSTIGATING_H
|
||||
|
||||
/* Include Files */
|
||||
|
||||
/* Definitions */
|
||||
|
||||
/* External Data */
|
||||
extern const StateActivity_T STATE_STARTING_GAME__INSTIGATING_Activities;
|
||||
|
||||
#endif // STATE_STARTING_GAME__INSTIGATING_H
|
134
States/Starting_Game/State_Starting_Game__Responding.c
Normal file
134
States/Starting_Game/State_Starting_Game__Responding.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* 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 void Starting_Game__Responding_Entry(StateMachineContext_T * context);
|
||||
static void Starting_Game__Responding_Do(StateMachineContext_T * context);
|
||||
static void Starting_Game__Responding_Exit(StateMachineContext_T * context);
|
||||
|
||||
static TickType_t Period_Start = 0;
|
||||
static uint_fast8_t N_Lights_Lit = 0;
|
||||
|
||||
static const char *KLOG_TAG = "STATE_STARTING_GAME__RESPONDING";
|
||||
|
||||
//! Activities for the **Responding** substate of the **Starting Game** state.
|
||||
const StateActivity_T STATE_STARTING_GAME__RESPONDING_Activities =
|
||||
{
|
||||
.Entry = Starting_Game__Responding_Entry,
|
||||
.Do = Starting_Game__Responding_Do,
|
||||
.Exit = Starting_Game__Responding_Exit
|
||||
};
|
||||
|
||||
//! Sets up the Responding substate.
|
||||
/*!
|
||||
* \param context Context in which this substate is being run.
|
||||
*/
|
||||
static void Starting_Game__Responding_Entry(StateMachineContext_T * context)
|
||||
{
|
||||
// First of all, enter the state containing this substate.
|
||||
Starting_Game_Entry(context);
|
||||
|
||||
LOG("Entering the Responding substate of the Starting Game state.");
|
||||
|
||||
if (context->Cause_Of_Transition->ID == KEVENT_BLE_PACKET_RECEIVED)
|
||||
{
|
||||
if (((BLE_Packet_T *)context->Cause_Of_Transition->Data)->Generic.type == BLE_PACKET_TYPE_INSTIGATE_GAME)
|
||||
{
|
||||
uint32_t game_length_in_ms = ((BLE_Packet_T *)context->Cause_Of_Transition->Data)->Instigation.game_length_in_ms;
|
||||
Set_Time_Remaining_in_Game(game_length_in_ms);
|
||||
|
||||
uint32_t time_remaining_until_countdown_in_ms = ((BLE_Packet_T *)context->Cause_Of_Transition->Data)->Instigation.time_remaining_until_countdown_in_ms;
|
||||
Set_Time_Remaining_Until_Countdown(time_remaining_until_countdown_in_ms);
|
||||
|
||||
#ifdef LOG_STATE_MACHINE
|
||||
KLOG_TRACE(KLOG_TAG, "Game length: %lu ms", game_length_in_ms);
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
KLOG_TRACE(KLOG_TAG, "Time until countdown: %lu ms", time_remaining_until_countdown_in_ms);
|
||||
#endif // LOG_STATE_MACHINE
|
||||
}
|
||||
|
||||
BLE_FreePacketBuffer(context->Cause_Of_Transition->Data);
|
||||
}
|
||||
}
|
||||
|
||||
//! Executes the Responding substate.
|
||||
/*!
|
||||
* \param context Context in which this substate is being run.
|
||||
*/
|
||||
static void Starting_Game__Responding_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;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for (T_start_game - T_instigation) before proceeding.
|
||||
if (GetTimeInState_in_ms(context) > Get_Time_Remaining_Until_Countdown_in_ms())
|
||||
{
|
||||
static KEvent_T Event;
|
||||
Event.ID = KEVENT_AUTOMATIC_TRANSITION;
|
||||
Event.Data = NULL;
|
||||
Transition_For_Event(context, STATE_STARTING_GAME__COUNTING_DOWN, &Event);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t period_time_in_ms = (xTaskGetTickCount() - Period_Start) * portTICK_PERIOD_MS;
|
||||
|
||||
if (period_time_in_ms > 150)
|
||||
{
|
||||
// Toggle the lights.
|
||||
if (N_Lights_Lit == 0)
|
||||
{
|
||||
N_Lights_Lit = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
N_Lights_Lit = 0;
|
||||
}
|
||||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_COUNTDOWN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&N_Lights_Lit};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
|
||||
// Start a new period.
|
||||
Period_Start = xTaskGetTickCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Cleans up the Responding substate.
|
||||
/*!
|
||||
* \param context Context in which this substate is being run.
|
||||
*/
|
||||
static void Starting_Game__Responding_Exit(StateMachineContext_T * context)
|
||||
{
|
||||
}
|
32
States/Starting_Game/State_Starting_Game__Responding.h
Normal file
32
States/Starting_Game/State_Starting_Game__Responding.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef STATE_STARTING_GAME__RESPONDING_H
|
||||
#define STATE_STARTING_GAME__RESPONDING_H
|
||||
|
||||
/* Include Files */
|
||||
|
||||
/* Definitions */
|
||||
|
||||
/* External Data */
|
||||
extern const StateActivity_T STATE_STARTING_GAME__RESPONDING_Activities;
|
||||
|
||||
#endif // STATE_STARTING_GAME__RESPONDING_H
|
Loading…
Add table
Add a link
Reference in a new issue