Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for output capacity before reading serial i/o, and order clients by descending interactivity. #984

Open
wants to merge 2 commits into
base: Devt
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions Grbl_Esp32/src/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,39 +130,44 @@ void client_init() {

static uint8_t getClientChar(uint8_t* data) {
int res;
#ifdef REVERT_TO_ARDUINO_SERIAL
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (res = Serial.read()) != -1) {
#else
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (res = Uart0.read()) != -1) {
#endif
*data = res;
return CLIENT_SERIAL;
}
if (WebUI::inputBuffer.available()) {
// An earlier client will block i/o for a later client while it has data available.
// So clients should be ordered by likelihood of being used interactively.
if (client_buffer[CLIENT_INPUT].availableforwrite() && WebUI::inputBuffer.available()) {
*data = WebUI::inputBuffer.read();
return CLIENT_INPUT;
}
//currently is wifi or BT but better to prepare both can be live
#ifdef ENABLE_BLUETOOTH
if (WebUI::SerialBT.hasClient()) {
if (client_buffer[CLIENT_BT].availableforwrite() && WebUI::SerialBT.hasClient()) {
if ((res = WebUI::SerialBT.read()) != -1) {
*data = res;
return CLIENT_BT;
}
}
#endif
#if defined(ENABLE_WIFI) && defined(ENABLE_HTTP) && defined(ENABLE_SERIAL2SOCKET_IN)
if (WebUI::Serial2Socket.available()) {
if (client_buffer[CLIENT_WEBUI].availableforwrite() && WebUI::Serial2Socket.available()) {
*data = WebUI::Serial2Socket.read();
return CLIENT_WEBUI;
}
#endif

// The clients below here are most likely to be non-interactive, or have
// interactive complementary clients.
#if defined(ENABLE_WIFI) && defined(ENABLE_TELNET)
if (WebUI::telnet_server.available()) {
if (client_buffer[CLIENT_TELNET].availableforwrite() && WebUI::telnet_server.available()) {
*data = WebUI::telnet_server.read();
return CLIENT_TELNET;
}
#endif
#ifdef REVERT_TO_ARDUINO_SERIAL
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (res = Serial.read()) != -1) {
#else
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (res = Uart0.read()) != -1) {
#endif
*data = res;
return CLIENT_SERIAL;
}
return CLIENT_ALL;
}

Expand Down