/* Include Files */
#include "KTag.h"

#define MIN_PLAYER_ID 0b0000000
#define MAX_PLAYER_ID 0b1111111

static void OnFocus(bool IncludeDetails);
static MenuItem_T const * OnSelect();
static void OnIncrement();
static void OnDecrement();

const MenuItem_T PlayerIDMenuItem =
{
    .OnFocus = OnFocus,
    .OnSelect = OnSelect,
    .OnIncrement = OnIncrement,
    .OnDecrement = OnDecrement
    
};

static void OnFocus(bool IncludeDetails)
{
    AudioAction_T audio_action = {.ID = AUDIO_PLAY_PLAYER_ID_PROMPT, .Play_To_Completion = true, .Data = (void *)0x00};
    xQueueSend(xQueueAudio, &audio_action, 0);
    
    if (IncludeDetails == true)
    {                    
        AudioAction_T volume_action = {.ID = AUDIO_PRONOUNCE_NUMBER_0_TO_100, .Play_To_Completion = true, .Data = (void *)&NVM_PLAYER_ID};
        xQueueSend(xQueueAudio, &volume_action, 0);
    }
}

static MenuItem_T const * OnSelect()
{
    AudioAction_T audio_action = {.ID = AUDIO_PLAY_SELECTION_INDICATOR, .Data = (void *)0x00};
    xQueueSend(xQueueAudio, &audio_action, 0);
    return NULL;
}

static void OnIncrement()
{
    if (NVM_PLAYER_ID < MAX_PLAYER_ID)
    {
        NVM_PLAYER_ID++;
    }
    
    AudioAction_T audio_action = {.ID = AUDIO_PLAY_PLAYER_ID_PROMPT, .Play_To_Completion = true, .Data = (void *)0x00};
    xQueueSend(xQueueAudio, &audio_action, 0);
                        
    AudioAction_T volume_action = {.ID = AUDIO_PRONOUNCE_NUMBER_0_TO_100, .Play_To_Completion = true, .Data = (void *)&NVM_PLAYER_ID};
    xQueueSend(xQueueAudio, &volume_action, 0);
}

static void OnDecrement()
{
    if (NVM_PLAYER_ID > MIN_PLAYER_ID)
    {
        NVM_PLAYER_ID--;
    }
    
    AudioAction_T audio_action = {.ID = AUDIO_PLAY_PLAYER_ID_PROMPT, .Play_To_Completion = true, .Data = (void *)0x00};
    xQueueSend(xQueueAudio, &audio_action, 0);
                        
    AudioAction_T volume_action = {.ID = AUDIO_PRONOUNCE_NUMBER_0_TO_100, .Play_To_Completion = true, .Data = (void *)&NVM_PLAYER_ID};
    xQueueSend(xQueueAudio, &volume_action, 0);
}