-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathio.ino
41 lines (31 loc) · 823 Bytes
/
io.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "io.h"
/* truncates line if exceeds maxLen */
char * readlineI(char* buffer, int maxLen) {
static boolean lastWasCr = false; // used to allow skipping empty lines
buffer[0] = '\0';
while (1) {
while (Serial.available() > 0) {
int c = Serial.read();
if (c == '\n' || c == '\r') {
if (lastWasCr) break; // read again
lastWasCr = true;
return buffer;
}
lastWasCr = false;
int l = strlen(buffer);
if (l < maxLen) {
buffer[l] = c;
buffer[l+1] = '\0';
}
}
delay(10);
}
// not reached
}
/* truncates line if exceeds maxLen */
char * readline(char* buffer, int maxLen) {
Serial.print(F("READY > "));
char* ret = readlineI(buffer, maxLen);
//Serial.println(ret);
return ret;
}