WIP: System Events
This commit is contained in:
parent
1c2f281579
commit
c979c38fd7
46 changed files with 647 additions and 470 deletions
|
|
@ -5,6 +5,7 @@ idf_component_register(
|
|||
"."
|
||||
REQUIRES
|
||||
"SystemK"
|
||||
"System_Events"
|
||||
"driver"
|
||||
"spiffs"
|
||||
"esp-audio-player"
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ idf_component_register(
|
|||
"."
|
||||
REQUIRES
|
||||
"SystemK"
|
||||
"System_Events"
|
||||
"spiffs"
|
||||
"driver"
|
||||
"usb"
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
#include <SystemK.h>
|
||||
#include <System_Events.h>
|
||||
#include <string.h>
|
||||
#include "esp_spiffs.h"
|
||||
|
||||
|
|
@ -80,5 +81,9 @@ void Initialize_SPIFFS(SemaphoreHandle_t init_complete)
|
|||
fclose(f);
|
||||
|
||||
KLOG_INFO(TAG, ">>> %s <<<", buf);
|
||||
|
||||
xEventGroupSetBits(Get_System_Events(), SYS_SPIFFS_READY);
|
||||
KLOG_INFO(TAG, "SPIFFS initialized.");
|
||||
|
||||
xSemaphoreGive(init_complete);
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
// From https://github.com/espressif/esp-idf/blob/master/examples/peripherals/usb/host/msc/main/msc_example_main.c
|
||||
|
||||
#include <SystemK.h>
|
||||
#include <System_Events.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
|
@ -262,13 +263,11 @@ static void usb_host_task(void *args)
|
|||
if (usb_host_device_free_all() == ESP_OK)
|
||||
{
|
||||
KLOG_INFO(TAG, "USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS");
|
||||
// break;
|
||||
};
|
||||
}
|
||||
if (event_flags & USB_HOST_LIB_EVENT_FLAGS_ALL_FREE)
|
||||
{
|
||||
KLOG_INFO(TAG, "USB_HOST_LIB_EVENT_FLAGS_ALL_FREE");
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -356,6 +355,7 @@ static void app_usb_task(void *args)
|
|||
else
|
||||
{
|
||||
Current_State = USB_STATE_VFS_REGISTERED;
|
||||
xEventGroupSetBits(Get_System_Events(), SYS_USB_FS_PRESENT);
|
||||
xSemaphoreGive(init_complete);
|
||||
}
|
||||
}
|
||||
|
|
@ -371,6 +371,7 @@ static void app_usb_task(void *args)
|
|||
if (msg.id == USB_DEVICE_DISCONNECTED)
|
||||
{
|
||||
Current_State = USB_STATE_PROCESSING_DISCONNECTION;
|
||||
xEventGroupClearBits(Get_System_Events(), SYS_USB_FS_PRESENT);
|
||||
}
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 6d8dab53e0c2efbb1aa17b3aaad556dc65005a4d
|
||||
Subproject commit edf80ba83b5924144bba611abdd3a54447ed92b0
|
||||
8
components/System_Events/CMakeLists.txt
Normal file
8
components/System_Events/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
idf_component_register(
|
||||
SRCS
|
||||
"System_Events.c"
|
||||
INCLUDE_DIRS
|
||||
"."
|
||||
REQUIRES
|
||||
"SystemK"
|
||||
)
|
||||
41
components/System_Events/System_Events.c
Normal file
41
components/System_Events/System_Events.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This program source code file is part of the KTag project, a DIY laser tag
|
||||
* game with customizable features and wide interoperability.
|
||||
*
|
||||
* 🛡️ <https://ktag.clubk.club> 🃞
|
||||
*
|
||||
* Copyright © 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 "System_Events.h"
|
||||
|
||||
static EventGroupHandle_t The_System_Events = NULL;
|
||||
|
||||
static const char *TAG = "System Events";
|
||||
|
||||
void Initialize_System_Events(void)
|
||||
{
|
||||
if (The_System_Events == NULL)
|
||||
{
|
||||
The_System_Events = xEventGroupCreate();
|
||||
KLOG_INFO(TAG, "System Events initialized.");
|
||||
}
|
||||
}
|
||||
|
||||
EventGroupHandle_t Get_System_Events(void)
|
||||
{
|
||||
return The_System_Events;
|
||||
}
|
||||
41
components/System_Events/System_Events.h
Normal file
41
components/System_Events/System_Events.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* This program source code file is part of the KTag project, a DIY laser tag
|
||||
* game with customizable features and wide interoperability.
|
||||
*
|
||||
* 🛡️ <https://ktag.clubk.club> 🃞
|
||||
*
|
||||
* Copyright © 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 SYSTEM_EVENTS_H
|
||||
#define SYSTEM_EVENTS_H
|
||||
|
||||
#include <SystemK.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/event_groups.h>
|
||||
|
||||
// System-wide event bits
|
||||
#define SYS_NVS_READY (1 << 0)
|
||||
#define SYS_SPIFFS_READY (1 << 1)
|
||||
#define SYS_USB_FS_PRESENT (1 << 2)
|
||||
#define SYS_BLE_READY (1 << 3)
|
||||
#define SYS_AUDIO_READY (1 << 4)
|
||||
#define SYS_CONFIG_LOADED (1 << 5)
|
||||
|
||||
EventGroupHandle_t Get_System_Events(void);
|
||||
void Initialize_System_Events(void);
|
||||
|
||||
#endif // SYSTEM_EVENTS_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue