The Accessory button now selects team in the Configuring state. #1

Merged
Joe merged 1 commit from Select_Team_In_Configuring_State into main 2025-01-28 02:06:22 +00:00
4 changed files with 189 additions and 141 deletions

View file

@ -30,17 +30,48 @@
typedef enum
{
TEAM_PURPLE = 0,
BASIC_TEAMS_MINIMUM = 0,
TEAM_RED = 1,
TEAM_BLUE = 2,
BASIC_TEAMS_MAXIMUM = 2,
TEAM_WHITE = 3,
COMMON_TEAM_ID_MASK = 3,
TEAM_ORANGE = 4,
TEAM_GREEN = 5,
TEAM_YELLOW = 6,
TEAM_BLACK = 7,
EXTENDED_TEAM_ID_MASK = 7
EXTENDED_TEAM_ID_MASK = 7,
MAXIMUM_TEAM_ID = 7
} TeamID_t;
__attribute__((always_inline)) static inline SystemKResult_T Set_Team_With_Audio_Feedback(uint8_t team_ID)
{
static uint8_t Team_ID = 0; // This is static because AUDIO_PRONOUNCE_NUMBER_0_TO_100 needs a *pointer*.
SystemKResult_T result = SYSTEMK_RESULT_SUCCESS;
Team_ID = team_ID;
if (Team_ID > MAXIMUM_TEAM_ID)
{
result = SYSTEMK_RESULT_OVERFLOW;
}
else
{
result = SETTINGS_set_uint8_t(SYSTEMK_SETTING_TEAMID, Team_ID);
if (result == SYSTEMK_RESULT_SUCCESS)
{
AudioAction_T audio_action = {.ID = AUDIO_PLAY_TEAM_ID_PROMPT, .Play_To_Completion = true, .Data = (void *)0x00};
Perform_Audio_Action(&audio_action);
AudioAction_T volume_action = {.ID = AUDIO_PRONOUNCE_NUMBER_0_TO_100, .Play_To_Completion = true, .Data = (void *)&Team_ID};
Perform_Audio_Action(&volume_action);
}
}
return result;
}
__attribute__((always_inline)) inline TeamID_t Resolve_Common_Team_ID(uint8_t team_ID)
{
return (team_ID & COMMON_TEAM_ID_MASK);

View file

@ -22,8 +22,10 @@
#include "SystemK.h"
#define MIN_TEAM_ID 0
#define MAX_TEAM_ID 3
#define MIN_TEAM_ID BASIC_TEAMS_MINIMUM
#define MAX_TEAM_ID BASIC_TEAMS_MAXIMUM
static const char * KLOG_TAG = "Team ID Menu";
static uint8_t Team_ID;
@ -73,13 +75,11 @@ static void OnIncrement()
{
Team_ID = MAX_TEAM_ID;
}
(void) SETTINGS_set_uint8_t(SYSTEMK_SETTING_TEAMID, Team_ID);
AudioAction_T audio_action = {.ID = AUDIO_PLAY_TEAM_ID_PROMPT, .Play_To_Completion = true, .Data = (void *)0x00};
Perform_Audio_Action(&audio_action);
AudioAction_T volume_action = {.ID = AUDIO_PRONOUNCE_NUMBER_0_TO_100, .Play_To_Completion = true, .Data = (void *)&Team_ID};
Perform_Audio_Action(&volume_action);
if (Set_Team_With_Audio_Feedback(Team_ID) != SYSTEMK_RESULT_SUCCESS)
{
KLOG_WARN(KLOG_TAG, "Failed to increment team!");
}
}
static void OnDecrement()
@ -94,11 +94,9 @@ static void OnDecrement()
{
Team_ID = MIN_TEAM_ID;
}
(void) SETTINGS_set_uint8_t(SYSTEMK_SETTING_TEAMID, Team_ID);
AudioAction_T audio_action = {.ID = AUDIO_PLAY_TEAM_ID_PROMPT, .Play_To_Completion = true, .Data = (void *)0x00};
Perform_Audio_Action(&audio_action);
AudioAction_T volume_action = {.ID = AUDIO_PRONOUNCE_NUMBER_0_TO_100, .Play_To_Completion = true, .Data = (void *)&Team_ID};
Perform_Audio_Action(&volume_action);
if (Set_Team_With_Audio_Feedback(Team_ID) != SYSTEMK_RESULT_SUCCESS)
{
KLOG_WARN(KLOG_TAG, "Failed to decrement team!");
}
}

View file

@ -40,8 +40,7 @@ const StateActivity_T STATE_CONFIGURING_Activities =
{
.Entry = Configuring_Entry,
.Do = Configuring_Do,
.Exit = Configuring_Exit
};
.Exit = Configuring_Exit};
//! Sets up the Configuring state.
/*!
@ -164,6 +163,26 @@ static void Configuring_Do(StateMachineContext_T * context)
}
break;
case KEVENT_ACCESSORY_SWITCH_PRESSED:
{
uint8_t Team_ID;
(void)SETTINGS_get_uint8_t(SYSTEMK_SETTING_TEAMID, &Team_ID);
Team_ID++;
if (Team_ID > BASIC_TEAMS_MAXIMUM)
{
Team_ID = BASIC_TEAMS_MINIMUM;
}
if (Set_Team_With_Audio_Feedback(Team_ID) != SYSTEMK_RESULT_SUCCESS)
{
KLOG_WARN(KLOG_TAG, "Failed to increment team!");
}
}
break;
case KEVENT_PLAY_PRESSED_ON_REMOTE:
Transition_For_Event(context, STATE_READY, &Event);
break;

View file

@ -93,8 +93,8 @@
#include "Logging/KLog.h"
#include "Protocols/Protocols.h"
#include "Settings/Settings_Interface.h"
#include "Game/Game.h"
#include "Audio/Audio_HW_Interface.h"
#include "Game/Game.h"
#include "NeoPixels/NeoPixels.h"
#include "BLE/BLE_Packets.h"
#include "BLE/BLE_Packet_Tracker.h"