@@ -76,46 +76,67 @@ inline void __attribute__((optimize("O3"))) update_output(const int level) {
76
76
void setup (void ) {
77
77
Serial.begin (115200 );
78
78
String mode;
79
+ char buff[10 ];
79
80
80
81
// indicator
81
82
pinMode (LED_BUILTIN, OUTPUT);
82
83
digitalWrite (LED_BUILTIN, LOW);
83
84
84
85
// run until we get a valid input mode string from the computer
85
86
while (1 ) {
86
-
87
- // Wait for input from the capture program to determine which
88
- while (Serial.available () == 0 ) {}
89
- if (Serial.available ()) {
90
- mode = Serial.readString (); // using C++ strings for input
91
- mode.trim ();
92
- } else {
93
- continue ;
87
+ //
88
+ // // Wait for input from the capture program to determine which
89
+ // while(Serial.available() == 0) {}
90
+ // if(Serial.available()) {
91
+ // mode = Serial.readString(); // using C++ strings for input
92
+ // mode.trim();
93
+ // } else {
94
+ // continue;
95
+ // }
96
+ BYTE idx = 0 ;
97
+ BYTE do_read = 1 ;
98
+ while (do_read != 0 ) {
99
+ Serial.flush ();
100
+ if (Serial.available () == 0 )
101
+ continue ;
102
+ char c = Serial.read ();
103
+ if (c != ' $' )
104
+ continue ;
105
+ delay (1000 );
106
+ while (Serial.available () != 0 ) {
107
+ c = Serial.read ();
108
+ if (c == ' \n ' or c == ' \r ' ) {
109
+ do_read = 0 ;
110
+ buff[idx] = 0 ;
111
+ break ;
112
+ }
113
+ buff[idx] = c;
114
+ idx++;
115
+ }
94
116
}
95
117
96
118
// use input from serial to select ADC channel
97
- if (mode == " NORMAL" ) {
119
+ if (strcmp (buff, " NORMAL" ) == 0 ) {
98
120
channel_select = 0 ;
99
121
break ;
100
122
}
101
- else if (mode == " WAVE" ) {
123
+ else if (strcmp (buff, " WAVE" ) == 0 ) {
102
124
channel_select = 1 ;
103
125
break ;
104
126
} else {
105
127
106
128
// input mode string was invalid, send error message to program,
107
129
// clear buffers, and try again
108
130
Serial.print (" INVALID \" " );
109
- Serial.print (mode );
131
+ Serial.print (buff );
110
132
Serial.println (" \" " );
111
133
Serial.flush ();
112
- while (!Serial.available ()) {
113
- Serial.read ();
114
- }
115
134
continue ;
116
135
}
117
136
}
118
-
137
+ while (Serial.available () > 0 ) {
138
+ Serial.read ();
139
+ }
119
140
Serial.println (" READY" );
120
141
Serial.flush ();
121
142
0 commit comments