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