-
Notifications
You must be signed in to change notification settings - Fork 2
/
serial.ino
96 lines (64 loc) · 1.43 KB
/
serial.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#if defined (SERIALON_STRINGS)
String command = "";
void handle_command() {
char action = command.charAt(0);
if ( (action >= '0') && (action <= '8') ) {
int index = action - '0';
txtMsg[index] = command.substring(1);
}
else if ( action == '>' ) {
for (int i = SEGMENTS; i > 0; i--) {
txtMsg[i] = txtMsg[i - 1];
}
txtMsg[0] = command.substring(1);
}
else if ( action == '<' ) {
for (int i = 1; i < SEGMENTS ; i++) {
txtMsg[i - 1] = txtMsg[i];
}
txtMsg[SEGMENTS - 1] = command.substring(1);
}
else if ( action == '-' ) {
for (int i = 0; i < SEGMENTS ; i++) {
txtMsg[i] = "";
}
}
else if ( action == '*' ) {
int tmp = command.charAt(1);
if ( tmp >= 'A' && tmp <= 'Z') {
curr_demo = tmp - 'A';
}
}
else txtMsg[0] = "SYNTAX ERROR";
}
void serialEvent() {
while ( Serial.available() ) {
handleSerial( (char)Serial.read() );
}
}
#if defined (SERIAL1ON)
void serialEvent1() {
while ( Serial1.available() ) {
handleSerial( (char)Serial1.read() );
}
}
#endif
void handleSerial( char inChar ) {
if ( inChar == '\n' || inChar == '\r') {
command.toUpperCase();
handle_command();
command = "";
}
else {
if ( command.length() > SERIAL_LINEMAX ) {
command.toUpperCase();
handle_command();
command = ">";
command += inChar;
}
else {
command += inChar;
}
}
}
#endif