Don't block waiting for input blindly. Be more efficient about how we check for a newline to end processing. Replace a magic value with what it really means.

TODO: We may want to block for a few fractions of a to make sure that we don't read half a command
Signed-off-by: Jesse Vincent <jesse@keyboard.io>
pull/1105/head
Jesse Vincent 3 years ago
parent c9943057f4
commit 62f668fd25
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -31,15 +31,17 @@ EventHandlerResult FocusSerial::afterEachCycle() {
if (Runtime.serialPort().available() == 0) if (Runtime.serialPort().available() == 0)
return EventHandlerResult::OK; return EventHandlerResult::OK;
uint8_t i = 0; uint8_t i = 0;
memset(command_, 0, sizeof(command_)); memset(command_, 0, sizeof(command_));
do { do {
command_[i++] = Runtime.serialPort().read(); command_[i++] = Runtime.serialPort().read();
} while (command_[i - 1] != SEPARATOR
&& i < sizeof(command_)
&& Runtime.serialPort().available()
&& (Runtime.serialPort().peek() != NEWLINE ));
if (Runtime.serialPort().peek() == '\n')
break;
} while (command_[i - 1] != ' ' && i < 32);
// If this was a command with a space-delimited payload, strip the space delimiter off // If this was a command with a space-delimited payload, strip the space delimiter off
if (command_[i - 1] == SEPARATOR ) if (command_[i - 1] == SEPARATOR )

Loading…
Cancel
Save