From f9715661d5ce4e11c9e9be0170f851e17e166db5 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 13 Dec 2023 18:38:20 -0800 Subject: [PATCH] Remove xon/xoff flow control, now that we have more proper usb-level flow control. This reverts commit 81851f7878c9d3ca58bedbecaa16c3802fddf114. This reverts commit 601a0235879f0aa0679a7a4748e4760df12186f9. This reverts commit 92de6c0426d97d6db55563a4ae106f9c4cc1cea4. This reverts commit 3490984ce5df772238b5fa5b5c54e84f74c492ed. --- .../src/kaleidoscope/plugin/FocusSerial.cpp | 22 ------------------- .../src/kaleidoscope/plugin/FocusSerial.h | 19 ---------------- 2 files changed, 41 deletions(-) diff --git a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp index 30d7bb6741..8f7abc31eb 100644 --- a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp +++ b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.cpp @@ -32,30 +32,10 @@ namespace kaleidoscope { namespace plugin { -bool xon = true; - -void FocusSerial::manageFlowControl() { - uint8_t avail = Runtime.serialPort().available(); - if (xon == true) { - if (avail > RECV_BUFFER_THRESHOLD) { - Runtime.serialPort().write(XOFF); // Send XOFF to stop data - Runtime.serialPort().flush(); - xon = false; - } - } else { - if (avail < RECV_BUFFER_RESUME) { - Runtime.serialPort().write(XON); // Send XON to resume data - Runtime.serialPort().flush(); - xon = true; - } - } -} - EventHandlerResult FocusSerial::afterEachCycle() { int c; // GD32 doesn't currently autoflush the very last packet. So manually flush here Runtime.serialPort().flush(); - // If the serial buffer is empty, we don't have any work to do if (Runtime.serialPort().available() == 0) { return EventHandlerResult::OK; @@ -67,7 +47,6 @@ EventHandlerResult FocusSerial::afterEachCycle() { break; } c = Runtime.serialPort().read(); - manageFlowControl(); // Don't store the separator; just stash it if (c == SEPARATOR) { break; @@ -85,7 +64,6 @@ EventHandlerResult FocusSerial::afterEachCycle() { Runtime.onFocusEvent(input_); while (Runtime.serialPort().available()) { c = Runtime.serialPort().read(); - manageFlowControl(); if (c == NEWLINE) { // newline serves as an end-of-command marker // don't drain the buffer past there diff --git a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h index 862353cc4d..093a99bb12 100644 --- a/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h +++ b/plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h @@ -46,8 +46,6 @@ class FocusSerial : public kaleidoscope::Plugin { static constexpr char SEPARATOR = ' '; static constexpr char NEWLINE = '\n'; - void manageFlowControl(); - #ifndef NDEPRECATED DEPRECATED(FOCUS_HANDLEHELP) bool handleHelp(const char *input, const char *help_message); @@ -109,39 +107,27 @@ class FocusSerial : public kaleidoscope::Plugin { } const char peek() { - manageFlowControl(); return Runtime.serialPort().peek(); } void read(Key &key) { - manageFlowControl(); key.setRaw(Runtime.serialPort().parseInt()); - manageFlowControl(); } void read(cRGB &color) { - manageFlowControl(); color.r = Runtime.serialPort().parseInt(); color.g = Runtime.serialPort().parseInt(); color.b = Runtime.serialPort().parseInt(); - manageFlowControl(); } void read(char &c) { - manageFlowControl(); Runtime.serialPort().readBytes(&c, 1); - manageFlowControl(); } void read(uint8_t &u8) { - manageFlowControl(); u8 = Runtime.serialPort().parseInt(); - manageFlowControl(); } void read(uint16_t &u16) { - manageFlowControl(); u16 = Runtime.serialPort().parseInt(); - manageFlowControl(); } - bool isEOL(); /* Hooks */ @@ -149,11 +135,6 @@ class FocusSerial : public kaleidoscope::Plugin { EventHandlerResult onFocusEvent(const char *input); private: - static constexpr char XOFF = 0x13; - static constexpr char XON = 0x11; - static constexpr uint8_t RECV_BUFFER_RESUME = 4; - static constexpr uint8_t RECV_BUFFER_THRESHOLD = 32; - char input_[32]; uint8_t buf_cursor_ = 0; void printBool(bool b);