Skip to content

Commit

Permalink
Verify bytes read are actually delimiter. (#201)
Browse files Browse the repository at this point in the history
* ADC_ATTEN_DB_12 is only defined in some versions? #198

* Verify what's read is actually a delimiter. #200
  • Loading branch information
SmittyHalibut authored Jan 28, 2025
1 parent b772e35 commit f4ae70c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,16 @@ void loop() {
uint8_t tempBuffer[100]; // Big enough for a command and params, won't hold audio data
int bytesRead = 0;

while (bytesRead < (DELIMITER_LENGTH + 1)) { // Read the delimiter and the command byte only (no params yet)
if (Serial.available()) {
tempBuffer[bytesRead++] = Serial.read();
while (bytesRead < (DELIMITER_LENGTH)) { // Read the delimiter and the command byte only (no params yet)
uint8_t tmp = Serial.read();
if (tmp != COMMAND_DELIMITER[bytesRead]) {
// Not a delimiter. Reset.
bytesRead = 0;
continue;
}
tempBuffer[bytesRead++] = tmp;
}
tempBuffer[DELIMITER_LENGTH] = Serial.read();
switch (tempBuffer[DELIMITER_LENGTH]) {

case COMMAND_STOP:
Expand Down

0 comments on commit f4ae70c

Please sign in to comment.