Signed-off-by: Jesse Vincent <jesse@keyboard.io>
pull/1105/head
Jesse Vincent 3 years ago
parent 54fbb04eb6
commit fbfede3566
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -31,11 +31,11 @@ EventHandlerResult FocusSerial::afterEachCycle() {
// If the serial buffer is empty, we don't have any work to do // If the serial buffer is empty, we don't have any work to do
if (Runtime.serialPort().available() == 0) { if (Runtime.serialPort().available() == 0) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
do { do {
command_[buf_cursor_++] = Runtime.serialPort().read(); command_[buf_cursor_++] = Runtime.serialPort().read();
} while ( command_[buf_cursor_ - 1] != SEPARATOR } while (command_[buf_cursor_ - 1] != SEPARATOR
&& buf_cursor_ < sizeof(command_) && buf_cursor_ < sizeof(command_)
&& Runtime.serialPort().available() && Runtime.serialPort().available()
&& (Runtime.serialPort().peek() != NEWLINE)); && (Runtime.serialPort().peek() != NEWLINE));
@ -48,17 +48,17 @@ EventHandlerResult FocusSerial::afterEachCycle() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
if ( (command_[buf_cursor_ - 1] != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE) if ((command_[buf_cursor_ - 1] != SEPARATOR) && (Runtime.serialPort().peek() != NEWLINE)
&& buf_cursor_ < sizeof(command_) && buf_cursor_ < sizeof(command_)
) { ) {
// We don't have enough command to work with yet. // We don't have enough command to work with yet.
// Let's leave the buffer around for another cycle // Let's leave the buffer around for another cycle
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
// If this was a command with a space-delimited payload, // If this was a command with a space-delimited payload,
// strip the space delimiter off // strip the space delimiter off
if ( (command_[buf_cursor_ - 1] == SEPARATOR) ) { if ((command_[buf_cursor_ - 1] == SEPARATOR)) {
command_[buf_cursor_ - 1] = '\0'; command_[buf_cursor_ - 1] = '\0';
} }

Loading…
Cancel
Save