editable serial input line buffer

Dependents:   MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more

Revision:
15:34b039027e5f
Parent:
14:9abcdf4eb4e4
Child:
16:592df067fe14
--- a/CmdLine.cpp	Fri May 08 05:32:36 2020 +0000
+++ b/CmdLine.cpp	Tue Apr 27 03:47:33 2021 -0700
@@ -47,6 +47,7 @@
     memset(buf, 0, COMMAND_BUFFER_LENGTH);
     chSeparator = 0;
     match_is_case_sensitive = false;
+    quiet = false;
 }
 /** CmdLine::clear empties the command-line buffer */
 void CmdLine::clear(void)
@@ -82,13 +83,13 @@
             if (indexOfNextEmptyCell > 0)
             {
                 buf[--indexOfNextEmptyCell] = '\0'; // pre-decrement index, overwrite with null
-                associatedSerialPort.printf("\b \b"); // tty: backspace, overwrite with space, backspace
+                if (!quiet) associatedSerialPort.printf("\b \b"); // tty: backspace, overwrite with space, backspace
             }
             break;
         case '\r': // Unicode (U+000D) CR CARRIAGE RETURN(CR) as EOL end of line
         case '\n': // Unicode (U+000A) LF LINE FEED(LF) as EOL end of line
             //associatedSerialPort.printf("%c", ch); // echo line end
-            associatedSerialPort.printf("\r\n"); // echo line end
+            if (!quiet) associatedSerialPort.printf("\r\n"); // echo line end
             //~ associatedSerialPort.printf("\r\n~%s~\r\n", buf); // DIAGNOSTIC: print line buffer
             // parse and handle the command by invoking onEOLcommandParser callback
             if (onEOLcommandParser) {
@@ -101,9 +102,9 @@
         case '\x04': // Unicode (U+0004) EOT END OF TRANSMISSION = CTRL+D as EOF end of file
             if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
             //~ main_menu_status(*this);
-            associatedSerialPort.printf("** U+0004 EOT = EOF **"); // immediately echo EOF for test scripting
+            if (!quiet) associatedSerialPort.printf("** U+0004 EOT = EOF **"); // immediately echo EOF for test scripting
             if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
-            associatedSerialPort.printf("\r\n\x04\r\n"); // immediately echo EOF for test scripting
+            if (!quiet) associatedSerialPort.printf("\r\n\x04\r\n"); // immediately echo EOF for test scripting
             //~ associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
             //~ associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
             //~ associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
@@ -112,12 +113,12 @@
         case '\x1a': // Unicode (U+001A) SUB SUBSTITUTE = CTRL+Z as EOF end of file
             if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
             //~ main_menu_status(*this);
-            associatedSerialPort.printf("** U+001A SUB = EOF **"); // immediately echo EOF for test scripting
+            if (!quiet) associatedSerialPort.printf("** U+001A SUB = EOF **"); // immediately echo EOF for test scripting
             if (diagnostic_led_EOF) { diagnostic_led_EOF(); }
-            associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
-            associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
-            associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
-            associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
+            if (!quiet) associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
+            if (!quiet) associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
+            if (!quiet) associatedSerialPort.printf("\x1a"); // immediately echo EOF for test scripting
+            if (!quiet) associatedSerialPort.printf("\x04"); // immediately echo EOF for test scripting
             clear(); // EOF discard any pending commands, to avoid surprise
             break;
 #endif
@@ -306,7 +307,7 @@
             buf[indexOfNextEmptyCell++] = ch; // append character, post-increment index
             buf[indexOfNextEmptyCell] = '\0'; // null-terminate the buffer
             MBED_ASSERT(indexOfNextEmptyCell <= COMMAND_BUFFER_LENGTH - 1);
-            associatedSerialPort.printf("%c", ch); // echo
+            if (!quiet) associatedSerialPort.printf("%c", ch); // echo
             if (indexOfNextEmptyCell == COMMAND_BUFFER_LENGTH - 1)
             {
                 // buffer is full, parse what we've got