Examples‎ > ‎

Build your command

In order to create your own commands, you must select a name for it which doesn't exist already in the system. Then you must include its name, description and parameters in the commands static table.

const COMMAND commandTable[] =
{
SECTION_SYSTEM,
"play", "Play a WAV file", cmdPlay,
BEGIN_PARAMETERS
{ "filename", "WAV file name" }, 
END_PARAMETERS
},
{
SECTION_SYSTEM,
"stop", "Stop playing", cmdStop,
NO_PARAMETERS
},
}
And now, you must to implement the cmdPlay function to perform the action you want. 

ERROR_CODE cmdPlay(TERMINAL* pTerminal, INT num_args, STRING args[])
{
if (num_args==0)
{
TerminalPrintf(pTerminal, "Play OFF !" EOL);
audioStopPlayFile();
}
else
{
if (!audioPlayFile(args[0]))
{
TerminalPrintf(pTerminal, "Wrong wave file !" EOL);
}
else
{
TerminalPrintf(pTerminal, "Playing %s ..." EOL, args[0]);
}
}
return CODE_OK;
}

The parameters are passed to the command using the array of strings "args[]" and the number of arguments in the array in "num_args". You can use TerminalPrintf and other available API functions in order to send the response to the user.
Comments