Interactive serial interface for sending commands to an embedded system using serial communications. This will be helpful if you want to send commands to serial port and be able to correct the wrong text entered at the terminal
Diff: main.cpp
- Revision:
- 5:bfc6c756c8e9
- Parent:
- 4:183056edc0f4
diff -r 183056edc0f4 -r bfc6c756c8e9 main.cpp --- a/main.cpp Wed Sep 20 06:18:04 2017 +0000 +++ b/main.cpp Mon Sep 02 12:28:53 2019 +0000 @@ -1,10 +1,11 @@ #include "mbed.h" /* - COPYWRITE Mariwan Jalal - This function will take a string from the terminal and save it in a buffer. + Author Mariwan Jalal + This function will take a string from the terminal and save it in a buffer. The string is editable during the time user input the string. This will be useful if any one want to have an interactive interface for an application. USE IT AT YOUR OWN RESPONSIBILITY .. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND + Free to use. */ @@ -20,27 +21,30 @@ stringBuf[i]=pc.getc(); if(stringBuf[i]=='\n') { stringBuf[i]='\0'; - if (i>0){ - i--; - if(stringBuf[i]=='\r') { - stringBuf[i]='\0'; + if (i>0) { + i--; + if(stringBuf[i]=='\r') { + stringBuf[i]='\0'; + } + return; } - return; } if(stringBuf[i]=='\b') { pc.puts("\b \b"); stringBuf[i]='\0'; - if (i>0){ - i--; + if (i>0) { + i--; } - stringBuf[i]='\0'; + stringBuf[i]='\0'; + } else { pc.putc(stringBuf[i]); i++; } - + } } + int main() { pc.baud(BAUD_RATE_); // DEFAULT IS 9600, THIS IS JUST FOR NOTIFICATION FOR THE READER.