From 74b853bf99eaf8bdfa7933626a0bcc1c495f7a74 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 30 May 2014 11:21:50 +0200 Subject: [PATCH] Improved YunSerialTerminal Removing calls to Serial.available() adds more CPU time to better handle a sustained 250kbps flow --- .../YunSerialTerminal/YunSerialTerminal.ino | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino index d369f3656..19e85df0b 100644 --- a/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino +++ b/libraries/Bridge/examples/YunSerialTerminal/YunSerialTerminal.ino @@ -43,14 +43,14 @@ void setup() { boolean commandMode = false; void loop() { - // copy from virtual serial line to uart and vice versa - if (Serial.available()) { // got anything from USB-Serial? - char c = (char)Serial.read(); // read from USB-serial + // copy from USB-CDC to UART + int c = Serial.read(); // read from USB-CDC + if (c != -1) { // got anything? if (commandMode == false) { // if we aren't in command mode... if (c == '~') { // Tilde '~' key pressed? commandMode = true; // enter in command mode } else { - Serial1.write(c); // otherwise write char to Linino + Serial1.write(c); // otherwise write char to UART } } else { // if we are in command mode... if (c == '0') { // '0' key pressed? @@ -65,18 +65,21 @@ void loop() { } else if (c == '3') { // '3' key pressed? Serial1.begin(500000); // set speed 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); Serial.println("Sending bridge's shutdown command"); } else { // any other key pressed? - Serial1.write('~'); // write '~' to Linino - Serial1.write(c); // write char to Linino + Serial1.write('~'); // write '~' to UART + Serial1.write(c); // write char to UART } commandMode = false; // in all cases exit from command mode } } - if (Serial1.available()) { // got anything from Linino? - char c = (char)Serial1.read(); // read from Linino - Serial.write(c); // write to USB-serial + + // copy from UART to USB-CDC + c = Serial1.read(); // read from UART + if (c != -1) { // got anything? + Serial.write(c); // write to USB-CDC } }