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:
- 12:b846b64e3980
- Parent:
- 11:4c6c6d6c0ebe
- Child:
- 13:019e24491f32
--- a/shell.cpp Wed Apr 16 03:41:12 2014 +0000 +++ b/shell.cpp Thu Apr 17 15:38:08 2014 +0000 @@ -21,10 +21,14 @@ } //----------------------------------------------------------------------------- -void Shell::sendHelloWorld() +void Shell::sendStartMessage() { // sends the first greeting - sendText(" ** K64 shell **\n>\n> "); + sendText("> ** K64 LED controller **\n"); + sendText(">\n"); + sendText("> use commands like: turn blue LED on\n"); + sendText("> or: turn red LED off\n"); + sendText(">\n> "); } //----------------------------------------------------------------------------- @@ -153,11 +157,11 @@ if(findString("Stefan")) sendText(" -- Hi \"Stefan\"!"); if(findString("Ralph")) sendText(" -- Hey, that's me!"); - if(findString("turn")) parseLED(); + if(findString("turn")) parseLEDState(); } //----------------------------------------------------------------------------- -void Shell::parseLED() +void Shell::parseLEDState() { // example text: turn blue LED on @@ -166,27 +170,47 @@ if(findString("blue")) ledColor = lcBlue; if(findString("green")) ledColor = lcGreen; + // check if color is specified if(ledColor == lcNone) { sendText(" -- missing LED color: red, blue or green"); sendExample(); } else { + + // check if LED is specified if(findString("LED")) { + // check for state eState state = stNone; if(findString("on")) state = stOn; if(findString("off")) state = stOff; if(state == stNone) { + + // state not specified sendText(" -- missing state: on or off"); sendExample(); } else { - sendText(" -- done!"); - ledColors->turn(ledColor, state); + + // check if state has changed + if(ledColors->getState(ledColor) == state) { + + // state not changed + sendText(" -- already "); + (state == stOn) ? sendText("on") : sendText("off"); + } + else { + + // state has changed + sendText(" -- done!"); + ledColors->turn(ledColor, state); + } } } else { + + // LED was not specified sendText(" -- specify LED"); sendExample(); }