Skip to content

Commit

Permalink
fixed commands sent by Arduino IDE
Browse files Browse the repository at this point in the history
  • Loading branch information
barry-ha committed Mar 12, 2024
1 parent 36c5d63 commit faaf919
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,25 @@ void run_unittest() {
runUnitTest(); // see "unit_test.cpp"
}

void removeCRLF(char *pBuffer) {
// remove 0x0d and 0x0a from character arrays, shortening the array in-place
const char key[] = "\r\n";
char *pch = strpbrk(pBuffer, key);
while (pch != NULL) {
strcpy(pch, pch + 1);
pch = strpbrk(pBuffer, key);
}
}

// do the thing
void processCommand(char *cmd) {

for (char *p = cmd; *p != '\0'; ++p) { // convert to lower case
*p = tolower(*p);
}

removeCRLF(cmd); // Arduino IDE can optionally add \r\n

Serial.print(cmd);
Serial.print(": ");

Expand Down

0 comments on commit faaf919

Please sign in to comment.