Replace 'drain' with a slightly more correct implementation

pull/1105/head
Jesse Vincent 3 years ago
parent 5ca95d0deb
commit 1d3c7b3399
No known key found for this signature in database
GPG Key ID: 122F5DF7108E4046

@ -26,12 +26,6 @@ namespace plugin {
char FocusSerial::command_[32]; char FocusSerial::command_[32];
void FocusSerial::drain(void) {
if (Runtime.serialPort().available())
while (Runtime.serialPort().peek() != '\n')
Runtime.serialPort().read();
}
EventHandlerResult FocusSerial::afterEachCycle() { 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)
@ -51,12 +45,16 @@ EventHandlerResult FocusSerial::afterEachCycle() {
Runtime.onFocusEvent(command_); Runtime.onFocusEvent(command_);
while (Runtime.serialPort().available()) {
char c = Runtime.serialPort().read();
if (c == NEWLINE) {
// newline serves as an end-of-command marker
// don't drain the buffer past there
break;
}
}
Runtime.serialPort().println(F("\r\n.")); Runtime.serialPort().println(F("\r\n."));
drain();
if (Runtime.serialPort().peek() == '\n')
Runtime.serialPort().read();
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -97,7 +97,6 @@ class FocusSerial : public kaleidoscope::Plugin {
private: private:
static char command_[32]; static char command_[32];
static void drain(void);
static void printBool(bool b); static void printBool(bool b);
}; };
} }

Loading…
Cancel
Save