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
117 lines
4.1 KiB
C
117 lines
4.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 void Initializing_Entry(StateMachineContext_T * context);
|
|
static void Initializing_Do(StateMachineContext_T * context);
|
|
static void Initializing_Exit(StateMachineContext_T * context);
|
|
|
|
static const char *KLOG_TAG = "STATE_INITIALIZING";
|
|
|
|
static bool Startup_Sound_Complete = false;
|
|
|
|
//! Activities for the **Initializing** state.
|
|
const StateActivity_T STATE_INITIALIZING_Activities =
|
|
{
|
|
.Entry = Initializing_Entry,
|
|
.Do = Initializing_Do,
|
|
.Exit = Initializing_Exit
|
|
};
|
|
|
|
//! Sets up the Initializing state.
|
|
/*!
|
|
* \param context Context in which this state is being run.
|
|
*/
|
|
static void Initializing_Entry(StateMachineContext_T * context)
|
|
{
|
|
KLOG_INFO("SystemK", "Using SystemK version %s.", SYSTEMK_VERSION_STRING);
|
|
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_TEST_PATTERN, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0x00};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
AudioAction_T audio_action = {.ID = AUDIO_PLAY_STARTUP_SOUND, .Play_To_Completion = true, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
Startup_Sound_Complete = false;
|
|
}
|
|
|
|
//! Executes the Initializing state.
|
|
/*!
|
|
* \param context Context in which this state is being run.
|
|
*/
|
|
static void Initializing_Do(StateMachineContext_T * context)
|
|
{
|
|
portBASE_TYPE xStatus;
|
|
static KEvent_T Event;
|
|
|
|
xStatus = Receive_KEvent(&Event);
|
|
|
|
if (xStatus == pdPASS)
|
|
{
|
|
switch (Event.ID)
|
|
{
|
|
case KEVENT_TRIGGER_SWITCH_PRESSED:
|
|
Transition_For_Event(context, STATE_REPROGRAMMING, &Event);
|
|
break;
|
|
|
|
case KEVENT_AUDIO_COMPLETED:
|
|
if (((AudioActionID_T)Event.Data) == AUDIO_PLAY_STARTUP_SOUND)
|
|
{
|
|
Startup_Sound_Complete = true;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
// All other events are ignored in this state.
|
|
ProcessUnhandledEvent(&Event);
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Wait for the STARTUP_SOUND to complete, but at least three seconds.
|
|
if ((xTaskGetTickCount() - context->Time_At_State_Entry_In_Ticks) > (3 * 1000 / portTICK_PERIOD_MS))
|
|
{
|
|
if (Startup_Sound_Complete == true)
|
|
{
|
|
Event.ID = KEVENT_AUTOMATIC_TRANSITION;
|
|
Event.Data = NULL;
|
|
Transition_For_Event(context, STATE_CONFIGURING, &Event);
|
|
}
|
|
}
|
|
}
|
|
|
|
//! Cleans up the Initializing state.
|
|
/*!
|
|
* \param context Context in which this state is being run.
|
|
*/
|
|
static void Initializing_Exit(StateMachineContext_T * context)
|
|
{
|
|
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_ALL_OFF, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)0x00};
|
|
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
|
AudioAction_T audio_action = {.ID = AUDIO_SILENCE, .Data = (void *)0x00};
|
|
Perform_Audio_Action(&audio_action);
|
|
|
|
//! \todo Add a menu item to change the weapon.
|
|
KLOG_WARN(KLOG_TAG, "Weapon hardcoded to the Nerf Laser Strike Blaster!");
|
|
uint8_t weapon_ID = NERF_LASER_STRIKE_BLASTER_ID;
|
|
(void) SETTINGS_set_uint8_t(SYSTEMK_SETTING_WEAPONID, weapon_ID);
|
|
(void) SETTINGS_Save();
|
|
}
|