Skip to content

Commit

Permalink
CommandLine: act more like a regular command line
Browse files Browse the repository at this point in the history
Wait for a carriage return or newline to process a command
  • Loading branch information
Angus Ainslie committed Apr 2, 2024
1 parent 6a5f95a commit 98d6d24
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
22 changes: 17 additions & 5 deletions esp32_marauder/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<cmdLine.length(); i++) {
char c = cmdLine.charAt(i);
if (c == '\n' || c == '\r') {
this->runCommand(cmdLine.substring(0,i));
if (i < (cmdLine.length() - 1))
this->cmdLine = cmdLine.substring(i+1);
else
this->cmdLine = "";
Serial.print("> ");
return;
}
}
}

LinkedList<String> CommandLine::parseCommand(String input, char* delim) {
Expand Down
1 change: 1 addition & 0 deletions esp32_marauder/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class CommandLine {
bool hasSSIDs();
void showCounts(int selected, int unselected = -1);
int argSearch(LinkedList<String>* cmd_args, String key);
String cmdLine;

const char* ascii_art =
"\r\n"
Expand Down

0 comments on commit 98d6d24

Please sign in to comment.