WIP: System Events

This commit is contained in:
Joe Kearney 2025-11-22 14:18:35 -06:00
parent 1c2f281579
commit c979c38fd7
46 changed files with 647 additions and 470 deletions

View file

@ -5,6 +5,7 @@ idf_component_register(
"."
REQUIRES
"SystemK"
"System_Events"
"driver"
"spiffs"
"esp-audio-player"

View file

@ -1,4 +1,5 @@
#include <SystemK.h>
#include <System_Events.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -245,21 +246,37 @@ SystemKResult_T Play_Sound_By_Prefix(const char *prefix)
{
SystemKResult_T result = SYSTEMK_RESULT_SUCCESS;
const char *sounds_dir = "/usb/01";
// Check for USB audio files.
EventBits_t bits = xEventGroupWaitBits(
Get_System_Events(),
SYS_USB_FS_PRESENT,
pdFALSE,
pdTRUE,
0);
char *filename = find_filename(sounds_dir, prefix);
if (filename != NULL)
if ((bits & SYS_USB_FS_PRESENT) == 0)
{
if (audio_player_get_state() == AUDIO_PLAYER_STATE_PLAYING)
{
audio_player_stop();
}
Play_Audio_File(concat_path(sounds_dir, filename));
KLOG_ERROR(TAG, "USB file system not present!");
result = SYSTEMK_RESULT_FILESYSTEM_NOT_PRESENT;
}
else
{
result = SYSTEMK_RESULT_FILE_NOT_FOUND;
const char *sounds_dir = "/usb/01";
char *filename = find_filename(sounds_dir, prefix);
if (filename != NULL)
{
if (audio_player_get_state() == AUDIO_PLAYER_STATE_PLAYING)
{
audio_player_stop();
}
Play_Audio_File(concat_path(sounds_dir, filename));
}
else
{
result = SYSTEMK_RESULT_FILE_NOT_FOUND;
}
}
return result;
@ -304,6 +321,7 @@ void I2SAudioTask(void *pvParameters)
if (xQueueReceive(xQueueAudio, &action, portMAX_DELAY) == pdPASS)
{
SystemKResult_T result = SYSTEMK_RESULT_SUCCESS;
switch (action.ID)
{
@ -318,23 +336,23 @@ void I2SAudioTask(void *pvParameters)
break;
case AUDIO_PLAY_STARTUP_SOUND:
Play_Sound_By_Prefix("001");
result = Play_Sound_By_Prefix("001");
break;
case AUDIO_PLAY_SHOT_FIRED:
Play_Sound_By_Prefix("002");
result = Play_Sound_By_Prefix("002");
break;
case AUDIO_PLAY_TAG_RECEIVED:
Play_Sound_By_Prefix("003");
result = Play_Sound_By_Prefix("003");
break;
case AUDIO_PLAY_TAGGED_OUT:
Play_Sound_By_Prefix("004");
result = Play_Sound_By_Prefix("004");
break;
case AUDIO_PLAY_MISFIRE:
Play_Sound_By_Prefix("005");
result = Play_Sound_By_Prefix("005");
break;
case AUDIO_PRONOUNCE_NUMBER_0_TO_100:
@ -347,115 +365,122 @@ void I2SAudioTask(void *pvParameters)
{
number = 101;
}
Play_Number_Sound(number);
result = Play_Number_Sound(number);
break;
case AUDIO_PLAY_MENU_PROMPT:
Play_Sound_By_Prefix("006");
result = Play_Sound_By_Prefix("006");
break;
case AUDIO_PLAY_SELECTION_INDICATOR:
Play_Sound_By_Prefix("007");
result = Play_Sound_By_Prefix("007");
break;
case AUDIO_PLAY_HEALTH_REMAINING:
Play_Sound_By_Prefix("008");
result = Play_Sound_By_Prefix("008");
break;
case AUDIO_PLAY_ELECTRONIC_DANCE_MUSIC:
Play_Sound_By_Prefix("009");
result = Play_Sound_By_Prefix("009");
break;
case AUDIO_PLAY_GENERIC_ERROR:
Play_Sound_By_Prefix("010");
result = Play_Sound_By_Prefix("010");
break;
case AUDIO_PLAY_VOLUME_PROMPT:
Play_Sound_By_Prefix("011");
result = Play_Sound_By_Prefix("011");
break;
case AUDIO_PLAY_RIGHT_HANDED:
Play_Sound_By_Prefix("012");
result = Play_Sound_By_Prefix("012");
break;
case AUDIO_PLAY_LEFT_HANDED:
Play_Sound_By_Prefix("013");
result = Play_Sound_By_Prefix("013");
break;
case AUDIO_PLAY_GAME_ON:
Play_Sound_By_Prefix("014");
result = Play_Sound_By_Prefix("014");
break;
case AUDIO_PLAY_HARDWARE_SETTINGS_PROMPT:
Play_Sound_By_Prefix("015");
result = Play_Sound_By_Prefix("015");
break;
case AUDIO_PLAY_GAME_SETTINGS_PROMPT:
Play_Sound_By_Prefix("016");
result = Play_Sound_By_Prefix("016");
break;
case AUDIO_PLAY_BONK:
Play_Sound_By_Prefix("017");
result = Play_Sound_By_Prefix("017");
break;
case AUDIO_PLAY_NEAR_MISS:
Play_Sound_By_Prefix("018");
result = Play_Sound_By_Prefix("018");
break;
case AUDIO_PLAY_PLAYER_ID_PROMPT:
Play_Sound_By_Prefix("019");
result = Play_Sound_By_Prefix("019");
break;
case AUDIO_PLAY_TEAM_ID_PROMPT:
Play_Sound_By_Prefix("020");
result = Play_Sound_By_Prefix("020");
break;
case AUDIO_PLAY_FRIENDLY_FIRE:
KLOG_WARN(TAG, "\"Friendly Fire\" audio is disabled in this build.");
//Play_Sound_By_Prefix("021");
// result = Play_Sound_By_Prefix("021");
break;
case AUDIO_PLAY_STARTING_THEME:
Play_Sound_By_Prefix("022");
result = Play_Sound_By_Prefix("022");
break;
case AUDIO_PLAY_BOOP:
Play_Sound_By_Prefix("023");
result = Play_Sound_By_Prefix("023");
break;
case AUDIO_PLAY_BEEP:
Play_Sound_By_Prefix("024");
result = Play_Sound_By_Prefix("024");
break;
case AUDIO_PLAY_REPROGRAMMING:
Play_Sound_By_Prefix("025");
result = Play_Sound_By_Prefix("025");
break;
case AUDIO_PLAY_BOMB:
Play_Sound_By_Prefix("026");
result = Play_Sound_By_Prefix("026");
break;
case AUDIO_PLAY_GAME_OVER:
Play_Sound_By_Prefix("027");
result = Play_Sound_By_Prefix("027");
break;
default:
Play_Audio_File("/spiffs/bad.wav");
Play_Audio_File("/spiffs/KTag_broken.mp3");
break;
}
if (action.Play_To_Completion == true)
if (result == SYSTEMK_RESULT_FILESYSTEM_NOT_PRESENT)
{
// Allow some time for the audio to start.
vTaskDelay(100 / portTICK_PERIOD_MS);
while (audio_player_get_state() != AUDIO_PLAYER_STATE_IDLE)
Play_Audio_File("/spiffs/KTag_broken.mp3");
}
else if (result == SYSTEMK_RESULT_SUCCESS)
{
if (action.Play_To_Completion == true)
{
// Allow some time for the audio to start.
vTaskDelay(100 / portTICK_PERIOD_MS);
}
KEvent_T command_received_event = {.ID = KEVENT_AUDIO_COMPLETED, .Data = (void *)action.ID};
Post_KEvent(&command_received_event);
while (audio_player_get_state() != AUDIO_PLAYER_STATE_IDLE)
{
vTaskDelay(100 / portTICK_PERIOD_MS);
}
KEvent_T command_received_event = {.ID = KEVENT_AUDIO_COMPLETED, .Data = (void *)action.ID};
Post_KEvent(&command_received_event);
}
}
}
}