1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Improved YunSerialTerminal

Removing calls to Serial.available() adds more CPU time to better
handle a sustained 250kbps flow
This commit is contained in:
Cristian Maglie
2014-05-30 11:21:50 +02:00
parent 82fe44d76d
commit 74b853bf99

View File

@ -43,14 +43,14 @@ void setup() {
boolean commandMode = false; boolean commandMode = false;
void loop() { void loop() {
// copy from virtual serial line to uart and vice versa // copy from USB-CDC to UART
if (Serial.available()) { // got anything from USB-Serial? int c = Serial.read(); // read from USB-CDC
char c = (char)Serial.read(); // read from USB-serial if (c != -1) { // got anything?
if (commandMode == false) { // if we aren't in command mode... if (commandMode == false) { // if we aren't in command mode...
if (c == '~') { // Tilde '~' key pressed? if (c == '~') { // Tilde '~' key pressed?
commandMode = true; // enter in command mode commandMode = true; // enter in command mode
} else { } else {
Serial1.write(c); // otherwise write char to Linino Serial1.write(c); // otherwise write char to UART
} }
} else { // if we are in command mode... } else { // if we are in command mode...
if (c == '0') { // '0' key pressed? if (c == '0') { // '0' key pressed?
@ -65,18 +65,21 @@ void loop() {
} else if (c == '3') { // '3' key pressed? } else if (c == '3') { // '3' key pressed?
Serial1.begin(500000); // set speed to 500000 Serial1.begin(500000); // set speed to 500000
Serial.println("Speed set to 500000"); Serial.println("Speed set to 500000");
} else if (c == '~') { } else if (c == '~') { // '~` key pressed?
// send "bridge shutdown" command
Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11); Serial1.write((uint8_t *)"\xff\0\0\x05XXXXX\x7f\xf9", 11);
Serial.println("Sending bridge's shutdown command"); Serial.println("Sending bridge's shutdown command");
} else { // any other key pressed? } else { // any other key pressed?
Serial1.write('~'); // write '~' to Linino Serial1.write('~'); // write '~' to UART
Serial1.write(c); // write char to Linino Serial1.write(c); // write char to UART
} }
commandMode = false; // in all cases exit from command mode commandMode = false; // in all cases exit from command mode
} }
} }
if (Serial1.available()) { // got anything from Linino?
char c = (char)Serial1.read(); // read from Linino // copy from UART to USB-CDC
Serial.write(c); // write to USB-serial c = Serial1.read(); // read from UART
if (c != -1) { // got anything?
Serial.write(c); // write to USB-CDC
} }
} }