Skip to content

Instantly share code, notes, and snippets.

@reefwing
Created April 17, 2023 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reefwing/a3c63b9ba5de23f82a2a8e627939f23c to your computer and use it in GitHub Desktop.
Save reefwing/a3c63b9ba5de23f82a2a8e627939f23c to your computer and use it in GitHub Desktop.
void checkForCommand() {
char buffer[BUFFER_SIZE];
// Check for xIMU3 Command Messages
if (Serial.available() > 0) {
// read the incoming bytes:
int blen = Serial.readBytesUntil(STOP_BYTE, buffer, BUFFER_SIZE);
bool cmdFound = false;
// Command character count
int index = 0;
for(int i = 0; i < blen; i++) {
// Extract Command
if (buffer[i] == CMD_BYTE) {
cmdFound = !cmdFound;
}
else if (cmdFound) {
cmd[index] = buffer[i];
index++;
}
}
cmd[index] = NULL_TERMINATOR;
}
else {
cmd[0] = NULL_TERMINATOR;
}
}
bool newCommand() {
if (cmd[0] == NULL_TERMINATOR) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment