Initial public release of SystemK.
This commit is contained in:
parent
387f57cdda
commit
6f51f5b006
129 changed files with 11654 additions and 2 deletions
107
States/State_Reprogramming.c
Normal file
107
States/State_Reprogramming.c
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* 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 Reprogramming_Entry(StateMachineContext_T * context);
|
||||
static void Reprogramming_Do(StateMachineContext_T * context);
|
||||
static void Reprogramming_Exit(StateMachineContext_T * context);
|
||||
static All_On_Data_T Data;
|
||||
static bool Reprogramming_Sound_Complete = false;
|
||||
|
||||
//! Activities for the **Reprogramming** state.
|
||||
const StateActivity_T STATE_REPROGRAMMING_Activities =
|
||||
{
|
||||
.Entry = Reprogramming_Entry,
|
||||
.Do = Reprogramming_Do,
|
||||
.Exit = Reprogramming_Exit
|
||||
};
|
||||
|
||||
//! Sets up the Reprogramming state.
|
||||
/*!
|
||||
* \param context Context in which this state is being run.
|
||||
*/
|
||||
static void Reprogramming_Entry(StateMachineContext_T * context)
|
||||
{
|
||||
LOG("Entering the Reprogramming state.");
|
||||
Data.color = ApplyMask(COLOR_YELLOW, 0x70);
|
||||
Data.style = DISPLAY_STYLE_ALTERNATE;
|
||||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_ALL_ON, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&Data};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
Reprogramming_Sound_Complete = false;
|
||||
AudioAction_T audio_action = {.ID = AUDIO_PLAY_REPROGRAMMING, .Play_To_Completion = true, .Data = (void *)0x00};
|
||||
Perform_Audio_Action(&audio_action);
|
||||
}
|
||||
|
||||
//! Executes the Reprogramming state.
|
||||
/*!
|
||||
* \param context Context in which this state is being run.
|
||||
*/
|
||||
static void Reprogramming_Do(StateMachineContext_T * context)
|
||||
{
|
||||
portBASE_TYPE xStatus;
|
||||
static KEvent_T Event;
|
||||
static bool reprogramming_requested = false;
|
||||
|
||||
xStatus = Receive_KEvent(&Event);
|
||||
|
||||
if (xStatus == pdPASS)
|
||||
{
|
||||
switch (Event.ID)
|
||||
{
|
||||
case KEVENT_AUDIO_COMPLETED:
|
||||
if (((AudioActionID_T)Event.Data) == AUDIO_PLAY_REPROGRAMMING)
|
||||
{
|
||||
Reprogramming_Sound_Complete = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// All events are ignored in this state.
|
||||
ProcessUnhandledEvent(&Event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Wait one second to initiate reprogramming, to allow the UI to update.
|
||||
// Note that the `reprogram` command behaves differently on different platforms--see the documentation.
|
||||
if ((xTaskGetTickCount() - context->Time_At_State_Entry_In_Ticks) > (1 * 1000 / portTICK_PERIOD_MS))
|
||||
{
|
||||
if ((reprogramming_requested == false) && (Reprogramming_Sound_Complete == true))
|
||||
{
|
||||
(void) HW_Execute_Console_Command((uint8_t *)"reprogram");
|
||||
reprogramming_requested = true;
|
||||
Data.color = ApplyMask(COLOR_ORANGE, 0x70);
|
||||
Data.style = DISPLAY_STYLE_ALTERNATE;
|
||||
NeoPixelsAction_T neopixels_action = {.ID = NEOPIXELS_ALL_ON, .Prominence = NEOPIXELS_FOREGROUND, .Data = (void *)&Data};
|
||||
xQueueSend(xQueueNeoPixels, &neopixels_action, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! Cleans up the Reprogramming state.
|
||||
/*!
|
||||
* \param context Context in which this state is being run.
|
||||
*/
|
||||
static void Reprogramming_Exit(StateMachineContext_T * context)
|
||||
{
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue