Skip to content

Commit

Permalink
Remove xon/xoff flow control, now that we have more proper usb-level …
Browse files Browse the repository at this point in the history
…flow control.

This reverts commit 81851f7.
This reverts commit 601a023.
This reverts commit 92de6c0.
This reverts commit 3490984.
  • Loading branch information
obra committed Dec 14, 2023
1 parent db675ec commit f971566
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -109,51 +107,34 @@ 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 */
EventHandlerResult afterEachCycle();
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);
Expand Down

0 comments on commit f971566

Please sign in to comment.