Read up to 8 debounced switches from serial port

Dependencies:   mbed

Committer:
jm
Date:
Sat Feb 12 16:46:49 2011 +0000
Revision:
0:f3a5f6fe1c03
jmSwitch Command Line Interface Module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jm 0:f3a5f6fe1c03 1 /*************************************************************************
jm 0:f3a5f6fe1c03 2 * @file jmInterpreter.c
jm 0:f3a5f6fe1c03 3 * @brief Command Line Interpreter
jm 0:f3a5f6fe1c03 4 *
jm 0:f3a5f6fe1c03 5 * @date December 27,2010
jm 0:f3a5f6fe1c03 6 */
jm 0:f3a5f6fe1c03 7
jm 0:f3a5f6fe1c03 8 #include "jmInterpreter.h"
jm 0:f3a5f6fe1c03 9 #include "jmRingBuffer.h"
jm 0:f3a5f6fe1c03 10 #include "jmCommands.h"
jm 0:f3a5f6fe1c03 11
jm 0:f3a5f6fe1c03 12 /** @brief Interpret a command line.
jm 0:f3a5f6fe1c03 13 * Interpreter uses Command Line Buffer to fecth command name
jm 0:f3a5f6fe1c03 14 * and redirects execution to associated function.
jm 0:f3a5f6fe1c03 15 * @param none
jm 0:f3a5f6fe1c03 16 * @returns none
jm 0:f3a5f6fe1c03 17 */
jm 0:f3a5f6fe1c03 18 void Interpret(void){
jm 0:f3a5f6fe1c03 19 unsigned int i,k;
jm 0:f3a5f6fe1c03 20 unsigned char Command, found;
jm 0:f3a5f6fe1c03 21 char Word[WordMaxSize];
jm 0:f3a5f6fe1c03 22 Command =0;
jm 0:f3a5f6fe1c03 23 found = 0;
jm 0:f3a5f6fe1c03 24
jm 0:f3a5f6fe1c03 25 if(NotEmpty(pLine)){
jm 0:f3a5f6fe1c03 26 ExtractWord(pLine,Word); // Command name extraction
jm 0:f3a5f6fe1c03 27 for(i=0, k=0;i<sizeof(cmdNames);i++){ // lookup in names array
jm 0:f3a5f6fe1c03 28 if(cmdNames[i]!=Word[k]){ // if different
jm 0:f3a5f6fe1c03 29 while(cmdNames[i]!=0)i++; // next entry in names array
jm 0:f3a5f6fe1c03 30 Command++; // update command index
jm 0:f3a5f6fe1c03 31 k=0;
jm 0:f3a5f6fe1c03 32 }
jm 0:f3a5f6fe1c03 33 else{
jm 0:f3a5f6fe1c03 34 if(Word[k]==0){
jm 0:f3a5f6fe1c03 35 found=1;
jm 0:f3a5f6fe1c03 36 }
jm 0:f3a5f6fe1c03 37 else k++;
jm 0:f3a5f6fe1c03 38 } //else
jm 0:f3a5f6fe1c03 39
jm 0:f3a5f6fe1c03 40 if(found)break;
jm 0:f3a5f6fe1c03 41 } //for
jm 0:f3a5f6fe1c03 42 }
jm 0:f3a5f6fe1c03 43
jm 0:f3a5f6fe1c03 44 // Command execution
jm 0:f3a5f6fe1c03 45 Action(Command);
jm 0:f3a5f6fe1c03 46 }