void runScript(char *script) { char *lineStart = script; commandAp.reset(); // break response into individual lines to feed to command parser while(*lineStart != '\0') { commandAp.appendLine(lineStart); Serial.print(F("script> ")); doCommand(commandBuffer); lineStart += commandAp.len(); commandAp.reset(); // skip any control chars at & after line break eg when \r\n linebreaks while(*lineStart && *lineStart < ' ') { lineStart++; } } }
// gather command from serial input // this may be performed in multiple passes - only a newline (not stored) marks command ready to process void processSerialCommands() { int inch; // append any newly arrived chars & execute command if return received while ((inch = Serial.read()) >= 0) { if (inch == '\n') { // end of line if(doCommand(commandBuffer)) { showPrompt(); } commandAp.reset(); return; // process at most one command per loop } else { // continue line commandAp.append((char) inch); } } }