Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of frdm_echo by
Diff: shell.cpp
- Revision:
- 11:4c6c6d6c0ebe
- Parent:
- 10:85a8da3b7e5e
- Child:
- 12:b846b64e3980
diff -r 85a8da3b7e5e -r 4c6c6d6c0ebe shell.cpp --- a/shell.cpp Tue Apr 15 03:12:29 2014 +0000 +++ b/shell.cpp Wed Apr 16 03:41:12 2014 +0000 @@ -42,13 +42,14 @@ finishCharacterBuffer(); parseCommands(); usbSerial->printf("\n> "); - ledColors->flashWhite(10); + // ledColors->flashWhite(10); + ledColors->flash(lcBlue, 10); } // if not, just print the character else if(addCharacterToBuffer(character)) { usbSerial->printf("%c", character); - ledColors->flashGreen(10); + ledColors->flash(lcGreen, 10); } } } @@ -73,38 +74,50 @@ } //----------------------------------------------------------------------------- -bool Shell::findString(char *thisString, uint32_t stringLength) +char Shell::lowercase(char thisChar) +{ + // check if this character is uppercase + if((thisChar >= 'A') && (thisChar <= 'Z')) thisChar += 32; + + return thisChar; +} +//----------------------------------------------------------------------------- + +bool Shell::findString(char *thisString) { bool found = false; - uint32_t startPointer = 0, characterPointer, newStartLocation; + uint32_t startPointer = 0, characterPointer, newStartLocation, stringLength = 0; char firstChar, secondChar; - + + // determine the length of thisString + while(thisString[stringLength]) stringLength++; + // start at the start position (0) on the input buffer - while(!found - && (characterCount >= stringLength) - && (startPointer <= characterCount - stringLength)) { - + while(!found + && (characterCount >= stringLength) + && (startPointer <= characterCount - stringLength)) { + // start at the beginning of the compare string (thisString) found = true; characterPointer = 0; while(found && (characterPointer < stringLength)) { - + // get and compare characters firstChar = inputBuffer[startPointer + characterPointer]; secondChar = thisString[characterPointer]; - found = (firstChar == secondChar); - + found = (lowercase(firstChar) == lowercase(secondChar)); + // for debugging // usbSerial->printf("(compare %c with %c)\n", firstChar, secondChar); - + // move up to next characters characterPointer++; } - + // move start position if(found) { newStartLocation = startPointer + stringLength; - + // clean up from buffer characterPointer = newStartLocation; while(characterPointer < characterCount) { @@ -114,7 +127,7 @@ } characterCount -= newStartLocation; inputBuffer[characterCount] = 0; - + // for debugging send buffer /* if(characterCount) { @@ -124,10 +137,10 @@ } */ } - + startPointer++; } - + // report return found; } @@ -135,6 +148,54 @@ void Shell::parseCommands() { - if(findString("set", 3)) sendText(" -- \"set\" found!"); + if(findString("set")) sendText(" -- \"set\" found!"); + if(findString("Clark")) sendText(" -- \"Clark\" found!"); + if(findString("Stefan")) sendText(" -- Hi \"Stefan\"!"); + if(findString("Ralph")) sendText(" -- Hey, that's me!"); + + if(findString("turn")) parseLED(); } //----------------------------------------------------------------------------- + +void Shell::parseLED() +{ + // example text: turn blue LED on + + eLEDColor ledColor = lcNone; + if(findString("red")) ledColor = lcRed; + if(findString("blue")) ledColor = lcBlue; + if(findString("green")) ledColor = lcGreen; + + if(ledColor == lcNone) { + sendText(" -- missing LED color: red, blue or green"); + sendExample(); + } + else { + if(findString("LED")) { + + eState state = stNone; + if(findString("on")) state = stOn; + if(findString("off")) state = stOff; + + if(state == stNone) { + sendText(" -- missing state: on or off"); + sendExample(); + } + else { + sendText(" -- done!"); + ledColors->turn(ledColor, state); + } + } + else { + sendText(" -- specify LED"); + sendExample(); + } + } +} +//----------------------------------------------------------------------------- + +void Shell::sendExample() +{ + sendText(" -> example: turn red LED on"); +} +//----------------------------------------------------------------------------- \ No newline at end of file