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

#define MAX_VOLUME 30
#define MIN_VOLUME 5

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

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

static void OnFocus(bool IncludeDetails)
{
    AudioAction_T audio_action = {.ID = AUDIO_PLAY_VOLUME_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_VOLUME};
        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_VOLUME < MAX_VOLUME)
    {
        NVM_VOLUME++;
    }
    
    AudioAction_T set_volume_action = {.ID = AUDIO_SET_VOLUME, .Data = (void *)&NVM_VOLUME};
    xQueueSend(xQueueAudio, &set_volume_action, 0);
    
    AudioAction_T audio_action = {.ID = AUDIO_PLAY_VOLUME_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_VOLUME};
    xQueueSend(xQueueAudio, &volume_action, 0);
}

static void OnDecrement()
{
    if (NVM_VOLUME > MIN_VOLUME)
    {
        NVM_VOLUME--;
    }
    
    AudioAction_T set_volume_action = {.ID = AUDIO_SET_VOLUME, .Data = (void *)&NVM_VOLUME};
    xQueueSend(xQueueAudio, &set_volume_action, 0);
    
    AudioAction_T audio_action = {.ID = AUDIO_PLAY_VOLUME_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_VOLUME};
    xQueueSend(xQueueAudio, &volume_action, 0);
}