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
shell.cpp@7:19da09fe546b, 2014-04-14 (annotated)
- Committer:
- silverpanda
- Date:
- Mon Apr 14 03:04:28 2014 +0000
- Revision:
- 7:19da09fe546b
- Parent:
- 5:03b7c237c4c4
- Child:
- 8:b715912d684b
with LED flashes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
silverpanda | 5:03b7c237c4c4 | 1 | #include "mbed.h" |
silverpanda | 7:19da09fe546b | 2 | #include "LEDColors.h" |
silverpanda | 5:03b7c237c4c4 | 3 | #include "shell.h" |
silverpanda | 5:03b7c237c4c4 | 4 | |
silverpanda | 7:19da09fe546b | 5 | extern LEDColors *ledColors; |
silverpanda | 7:19da09fe546b | 6 | |
silverpanda | 5:03b7c237c4c4 | 7 | // create contructor |
silverpanda | 5:03b7c237c4c4 | 8 | Shell::Shell(uint32_t thisBaudRate) |
silverpanda | 5:03b7c237c4c4 | 9 | { |
silverpanda | 5:03b7c237c4c4 | 10 | usbSerial = new Serial(USBTX, USBRX); |
silverpanda | 5:03b7c237c4c4 | 11 | usbSerial->baud(115200); |
silverpanda | 5:03b7c237c4c4 | 12 | } |
silverpanda | 5:03b7c237c4c4 | 13 | //----------------------------------------------------------------------------- |
silverpanda | 5:03b7c237c4c4 | 14 | |
silverpanda | 5:03b7c237c4c4 | 15 | void Shell::sendText(char *thisText) |
silverpanda | 5:03b7c237c4c4 | 16 | { |
silverpanda | 5:03b7c237c4c4 | 17 | // this can send any text |
silverpanda | 5:03b7c237c4c4 | 18 | usbSerial->printf(thisText); |
silverpanda | 5:03b7c237c4c4 | 19 | } |
silverpanda | 5:03b7c237c4c4 | 20 | //----------------------------------------------------------------------------- |
silverpanda | 5:03b7c237c4c4 | 21 | |
silverpanda | 5:03b7c237c4c4 | 22 | void Shell::sendHelloWorld() |
silverpanda | 5:03b7c237c4c4 | 23 | { |
silverpanda | 5:03b7c237c4c4 | 24 | // sends the first greeting |
silverpanda | 5:03b7c237c4c4 | 25 | sendText("** Hello World **\n\n> "); |
silverpanda | 5:03b7c237c4c4 | 26 | } |
silverpanda | 5:03b7c237c4c4 | 27 | //----------------------------------------------------------------------------- |
silverpanda | 5:03b7c237c4c4 | 28 | |
silverpanda | 5:03b7c237c4c4 | 29 | void Shell::scanUSBSerialRx() |
silverpanda | 5:03b7c237c4c4 | 30 | { |
silverpanda | 5:03b7c237c4c4 | 31 | // check if there is something to read |
silverpanda | 5:03b7c237c4c4 | 32 | if(usbSerial->readable()) { |
silverpanda | 5:03b7c237c4c4 | 33 | |
silverpanda | 5:03b7c237c4c4 | 34 | // if so ... |
silverpanda | 5:03b7c237c4c4 | 35 | char character = usbSerial->getc(); |
silverpanda | 5:03b7c237c4c4 | 36 | |
silverpanda | 5:03b7c237c4c4 | 37 | // see if this is a semi colon or a carriage return |
silverpanda | 5:03b7c237c4c4 | 38 | // if so, give a new line cursor |
silverpanda | 7:19da09fe546b | 39 | if((character == ';') || (character == 13)) { |
silverpanda | 7:19da09fe546b | 40 | usbSerial->printf("\n> "); |
silverpanda | 7:19da09fe546b | 41 | ledColors->flashWhite(10); |
silverpanda | 7:19da09fe546b | 42 | } |
silverpanda | 5:03b7c237c4c4 | 43 | |
silverpanda | 5:03b7c237c4c4 | 44 | // if not, just print the character |
silverpanda | 7:19da09fe546b | 45 | else { |
silverpanda | 7:19da09fe546b | 46 | usbSerial->printf("%c", character); |
silverpanda | 7:19da09fe546b | 47 | ledColors->flashGreen(10); |
silverpanda | 7:19da09fe546b | 48 | } |
silverpanda | 5:03b7c237c4c4 | 49 | } |
silverpanda | 5:03b7c237c4c4 | 50 | } |
silverpanda | 5:03b7c237c4c4 | 51 | //----------------------------------------------------------------------------- |
silverpanda | 5:03b7c237c4c4 | 52 |