@@ -43,14 +43,14 @@ void setup() {
43
43
boolean commandMode = false ;
44
44
45
45
void 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?
49
49
if (commandMode == false ) { // if we aren't in command mode...
50
50
if (c == ' ~' ) { // Tilde '~' key pressed?
51
51
commandMode = true ; // enter in command mode
52
52
} else {
53
- Serial1.write (c); // otherwise write char to Linino
53
+ Serial1.write (c); // otherwise write char to UART
54
54
}
55
55
} else { // if we are in command mode...
56
56
if (c == ' 0' ) { // '0' key pressed?
@@ -65,18 +65,21 @@ void loop() {
65
65
} else if (c == ' 3' ) { // '3' key pressed?
66
66
Serial1.begin (500000 ); // set speed to 500000
67
67
Serial.println (" Speed set to 500000" );
68
- } else if (c == ' ~' ) {
68
+ } else if (c == ' ~' ) { // '~` key pressed?
69
+ // send "bridge shutdown" command
69
70
Serial1.write ((uint8_t *)" \xff\0\0\x05 XXXXX\x7f\xf9 " , 11 );
70
71
Serial.println (" Sending bridge's shutdown command" );
71
72
} 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
74
75
}
75
76
commandMode = false ; // in all cases exit from command mode
76
77
}
77
78
}
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
81
84
}
82
85
}
0 commit comments