-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmodeInteractive.ino
110 lines (85 loc) · 2.36 KB
/
modeInteractive.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "tester_wires.h"
void tUsage() {
INFOLN(F("usage:"));
INFOLN(F(" t:testpattern[:desc] - perform test using given pattern"));
}
void usage() {
tUsage();
INFOLN(F(" ? - test all pins - uses the pullup/down test"));
INFOLN(F(" s - sample all pins - just sample the value of the pin"));
INFOLN(F(" 1 - set all pins to 1"));
INFOLN(F(" 0 - set all pins to 0"));
INFOLN(F(" i - identify chip - stop on first match"));
INFOLN(F(" I - identify chip - exhaustive"));
INFOLN(F(" l - led array test pattern"));
INFOLN(F(" d - decay test for capacitance on pins - leave socket empty"));
INFOLN(F(" / - repeat last action"));
}
void interactive() {
const int INPUT_MAX_LEN = 100;
INFOLN(F("INTERACTIVE MODE:"));
usage();
char op;
char prevCommand[INPUT_MAX_LEN + 1] = "";
char command[INPUT_MAX_LEN + 1] = "";
do {
readline(command, INPUT_MAX_LEN);
op = command[0];
// if this command is / then just repeat whatever the previous op was
if (op == '/') {
strcpy(command, prevCommand);
op = command[0];
}
// keep a copy of this operation in case the next operation is a command to repeat this one
strcpy(prevCommand, command);
// start parsing the command - make a
char* token = strtok(command, ":");
switch (op) {
case 'h': {
usage();
break;
}
case 't': {
char* testcase = strtok(NULL, ":");
if (testcase == NULL) {
ERRORLN(F("missing testcase"));
tUsage();
break;
}
char* desc = strtok(NULL, ":");
if (desc == NULL) desc = (char*)"";
test_ic(testcase, desc);
} break;
case 'i':
identify(false, true, true);
break;
case 'I':
identify(false, true, false);
break;
case 'l':
barLedTestPattern();
break;
case 'd':
decay();
break;
case '?':
testX('?', "status of all pins");
break;
case 's':
testX('S', "sample all pins");
break;
case '1':
testX('1', "all pins 1");
break;
case '0':
testX('0', "all pins 0");
break;
default: {
ERRORLN("invalid command '", op, "'")
usage();
break;
}
}
} while (op != 'q');
HALTLN(F("quit"));
}