Issuing the following sequence of commands results in a motion downsampling query turning into a set:
The issue is that once a sentinel character is found, the buffer is passed to run as-is:
|
// a string to hold incoming data |
|
while (serial.available()) { |
|
// get the new byte: |
|
int ch = serial.read(); |
|
received_chars[rec_cnt++] = (char)ch; |
|
// end of user input |
|
if(echo) |
|
print((char)ch); |
|
if (isSentinel(ch)) { |
|
// execute the user command |
|
run(received_chars); |
Later atof reads past the sentinel and picks up the trailing 5 in the buffer, and the downsampling is set to 5. The least invasive solution might be to null out the character after the sentinel (if we're not at the end of the buffer).