Skip to content

Commit 71b011c

Browse files
committed
1.1.0-alpha.3 test build
1 parent 8416bba commit 71b011c

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

diyemg_sketch/diyemg_sketch.ino renamed to diyemg_sketch_1.1-a.1/diyemg_sketch_1.1-a.1.ino

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,46 +76,67 @@ inline void __attribute__((optimize("O3"))) update_output(const int level) {
7676
void setup(void) {
7777
Serial.begin(115200);
7878
String mode;
79+
char buff[10];
7980

8081
// indicator
8182
pinMode(LED_BUILTIN, OUTPUT);
8283
digitalWrite(LED_BUILTIN, LOW);
8384

8485
// run until we get a valid input mode string from the computer
8586
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+
}
94116
}
95117

96118
// use input from serial to select ADC channel
97-
if(mode == "NORMAL") {
119+
if(strcmp(buff, "NORMAL") == 0) {
98120
channel_select = 0;
99121
break;
100122
}
101-
else if(mode == "WAVE") {
123+
else if(strcmp(buff, "WAVE") == 0) {
102124
channel_select = 1;
103125
break;
104126
} else {
105127

106128
// input mode string was invalid, send error message to program,
107129
// clear buffers, and try again
108130
Serial.print("INVALID \"");
109-
Serial.print(mode);
131+
Serial.print(buff);
110132
Serial.println("\"");
111133
Serial.flush();
112-
while(!Serial.available()) {
113-
Serial.read();
114-
}
115134
continue;
116135
}
117136
}
118-
137+
while(Serial.available() > 0) {
138+
Serial.read();
139+
}
119140
Serial.println("READY");
120141
Serial.flush();
121142

0 commit comments

Comments
 (0)