@@ -43,14 +43,14 @@ void setup() {
4343boolean commandMode = false ;
4444
4545void loop () {
46- // copy from virtual serial line to uart and vice versa
47- if ( Serial.available ()) { // got anything from USB-Serial?
48- char c = ( char )Serial. read (); // read from USB-serial
46+ // copy from USB-CDC to UART
47+ int c = Serial.read (); // read from USB-CDC
48+ if (c != - 1 ) { // got anything?
4949 if (commandMode == false ) { // if we aren't in command mode...
5050 if (c == ' ~' ) { // Tilde '~' key pressed?
5151 commandMode = true ; // enter in command mode
5252 } else {
53- Serial1.write (c); // otherwise write char to Linino
53+ Serial1.write (c); // otherwise write char to UART
5454 }
5555 } else { // if we are in command mode...
5656 if (c == ' 0' ) { // '0' key pressed?
@@ -65,18 +65,21 @@ void loop() {
6565 } else if (c == ' 3' ) { // '3' key pressed?
6666 Serial1.begin (500000 ); // set speed to 500000
6767 Serial.println (" Speed set to 500000" );
68- } else if (c == ' ~' ) {
68+ } else if (c == ' ~' ) { // '~` key pressed?
69+ // send "bridge shutdown" command
6970 Serial1.write ((uint8_t *)" \xff\0\0\x05 XXXXX\x7f\xf9 " , 11 );
7071 Serial.println (" Sending bridge's shutdown command" );
7172 } else { // any other key pressed?
72- Serial1.write (' ~' ); // write '~' to Linino
73- Serial1.write (c); // write char to Linino
73+ Serial1.write (' ~' ); // write '~' to UART
74+ Serial1.write (c); // write char to UART
7475 }
7576 commandMode = false ; // in all cases exit from command mode
7677 }
7778 }
78- if (Serial1.available ()) { // got anything from Linino?
79- char c = (char )Serial1.read (); // read from Linino
80- Serial.write (c); // write to USB-serial
79+
80+ // copy from UART to USB-CDC
81+ c = Serial1.read (); // read from UART
82+ if (c != -1 ) { // got anything?
83+ Serial.write (c); // write to USB-CDC
8184 }
8285}
0 commit comments