///////////////////////////////////////////////////////////////////////////////
//
// Demo Audio Media Player (ezPod!) Program for ADSP-BF533 EZ-KIT
//
// Author: Dr Martin Knott
// 		   ADI Edinburgh
//
// Uses File System on attached extender card
// Console I/O (stdin,stdout,stderr) connected to UART port
//
///////////////////////////////////////////////////////////////////////////////

#include <cli.h>
#include <assert.h>
#include <cplbtab.h>
#include <file_ops.h>
#include <AudioPlayer.h>

/* Local function protoypes */
static void DisplayHelpText( u32 index );
static void print_prompt(void);

/* Command index enumeration values */
enum {
    CLI_CMD_CD,
    CLI_CMD_PWD,
    CLI_CMD_LS,
    CLI_CMD_DATE,
    CLI_CMD_DF,
    CLI_CMD_MKDIR,
    CLI_CMD_RMDIR,
    CLI_CMD_PLAY,
    CLI_CMD_CP,
    CLI_CMD_RM
};



static void FileTestHelp_test(void)
{

    printf("\nHelp\n");
    printf("----\n");
    printf("cd      - Changes the current working directory.\n");
    printf("df      - Scans for new partitions and lists mounted volumes\n");
    printf("ls      - Lists contents of named directory.\n");
    printf("mkdir   - Creates a new directory.\n");
    printf("rmdir   - Removes a directory.\n");
    printf("play    - Plays audio file(s).\n");
    printf("date    - Displays/changes date.\n");
    printf("cp      - Copies files.\n");
    printf("rm      - Deletes a file.\n");
    printf("\nType <cmd> -h to display help on each command.\n");   
    return;
}

/*********************************************************************

    Function:       DisplayHelpText

    Description:    Displays the help text for the command index

*********************************************************************/
static void DisplayHelpText( u32 index )
{
    switch (index) {
        case CLI_CMD_CD :
            printf("\nUsage: cd [<dir>]\n");
            printf("       Change Current Working Directory to <dir>.\n");
            printf("       Changes to root directory of current volume if <dir> omitted.\n");
            break;
        case CLI_CMD_PWD :
            printf("\nUsage: pwd\n");
            printf("       Displays Current Working Directory.\n");
            break;
        case CLI_CMD_LS :
            printf("\nUsage: ls [<dir>]\n");
            printf("       Lists contents of directory <dir>.\n");
            printf("       Lists Current Working Directory if <dir> omitted.\n");
            break;
        case CLI_CMD_DATE :
            printf("\nUsage: date [dow MMDDhhmmYYYY]\n");
            printf("       Sets the RTC to the specified date; nomenclature is:\n");
            printf("            dow:  Day of week: 3 letters, lower case\n");
            printf("            MM:   Month: 2 digits\n");
            printf("            DD:   Day of Month: 2 digits\n");
            printf("            hh:   Hour: 2 digits; 24 hour clock\n");
            printf("            mm:   Minutes: 2 digits\n");
            printf("            YYYY: Year: 4 digits\n");
            break;
        case CLI_CMD_DF :
            printf("\nUsage: df\n");
            printf("       Lists the mounted volumes in format:\n");
            printf("       drive letter, label, type, size, mount status\n");
            break;
        case CLI_CMD_MKDIR:
            printf("\nUsage: mkdir <dir>\n");
            printf("       Creates the specified directory.\n");
            break;
        case CLI_CMD_RMDIR:
            printf("\nUsage: rmdir <dir>\n");
            printf("       Deletes the specified directory.\n");
            break;
        case CLI_CMD_PLAY:
            printf("\nUsage: Play [<audio> | <list>]\n");
            printf("       Plays either the <audio> file or the files listed in <list>.\n");
            printf("       Supports file extensions: .WAV for wave files, .MP3 for MP3 files and .LST for lists.\n");
            printf("       Press Pushbutton PB4 on the Ez-Kit to terminate audio playback\n");
            break;
        case CLI_CMD_CP:
            printf("\nUsage: cp <file1> <file2>\n");
            printf("       Copies contents of <file1> to <file2>.\n");
            break;
        case CLI_CMD_RM:
            printf("\nUsage: rm <file>\n");
            printf("       Deletes <file>.\n");
            break;
    }
}

/*********************************************************************
*	Function:		print_prompt
*	Description:	writes a command line prompt to the console
*********************************************************************/
static void print_prompt(void)
{
	char path[80];
	getcwd(path, 80);
	if (path[0])
		printf("%s%% ",path);
	else
		printf("blackfin%% ");
	
	fflush(stdout);
}


/*********************************************************************
*********************************************************************/

/*****/
