From 0f60762cefe37f367b25c30f7f79668ef6d007c6 Mon Sep 17 00:00:00 2001 From: Angus Ainslie Date: Tue, 2 Apr 2024 07:59:12 -0700 Subject: [PATCH] CommandLine: act more like a regular command line Wait for a carriage return or newline to process a command --- esp32_marauder/CommandLine.cpp | 22 +++++++++++++++++----- esp32_marauder/CommandLine.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/esp32_marauder/CommandLine.cpp b/esp32_marauder/CommandLine.cpp index 704cffe03..a646920f9 100644 --- a/esp32_marauder/CommandLine.cpp +++ b/esp32_marauder/CommandLine.cpp @@ -19,19 +19,31 @@ String CommandLine::getSerialInput() { String input = ""; if (Serial.available() > 0) - input = Serial.readStringUntil('\n'); + input = Serial.readString(); - input.trim(); return input; } void CommandLine::main(uint32_t currentTime) { String input = this->getSerialInput(); - this->runCommand(input); + if (input == "") + return; + + this->cmdLine = this->cmdLine + input; - if (input != "") - Serial.print("> "); + for (int i=0; irunCommand(cmdLine.substring(0,i)); + if (i < (cmdLine.length() - 1)) + this->cmdLine = cmdLine.substring(i+1); + else + this->cmdLine = ""; + Serial.print("> "); + return; + } + } } LinkedList CommandLine::parseCommand(String input, char* delim) { diff --git a/esp32_marauder/CommandLine.h b/esp32_marauder/CommandLine.h index a17ab8202..3b5960a16 100644 --- a/esp32_marauder/CommandLine.h +++ b/esp32_marauder/CommandLine.h @@ -154,6 +154,7 @@ class CommandLine { bool hasSSIDs(); void showCounts(int selected, int unselected = -1); int argSearch(LinkedList* cmd_args, String key); + String cmdLine; const char* ascii_art = "\r\n"