-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiagnostics.h
201 lines (185 loc) · 6.05 KB
/
Diagnostics.h
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Diagnostics.h
/*
This file contains diagnostic settings and functions that can be used to test and manipulate the operation of the behavior box.
"Interactive" refers to the user's ability to control the arduino via the Processing proram while the Arduino is connected over USB.
The Processing sketch must be quit before the Arduino Serial Monitor can be used or a new sketch uploaded to the Arduino. This is because only one program can be using the Serial port at the same time.
*/
char diagnostic_val; // Data received from the serial port
unsigned long lastDiagnosticSerialReadTimer = 0; // This variable keeps track of the last time diagnostic serial read was performed
bool diagnostic_disable_dispensing = false; //diagnostic_disable_dispensing: if true, dispense events are not performed as a result of beambreak events.
// Function Prototypes:
void loopDiagnostics(unsigned long currentLoopMillis);
void diagnostic_read_command();
void diagnostic_send_info();
void loopDiagnostics(unsigned long currentLoopMillis) {
if (currentLoopMillis - lastDiagnosticSerialReadTimer >= INTERACTIVE_DIAGNOSTIC_SERIAL_READ_TIMEOUT) {
diagnostic_read_command();
lastDiagnosticSerialReadTimer = currentLoopMillis;
}
#if ENABLE_DIAGNOSTIC_SERIAL
diagnostic_send_info();
#endif
}
// Called to read in a "command" that has been sent by the Processing sketch over serial.
void diagnostic_read_command() {
if (Serial.available()) { // If data is available to read,
diagnostic_val = Serial.read(); // read it and store it in val
// Check the character recieved
if (diagnostic_val == '0') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 0");
}
}
else if (diagnostic_val == '1') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 1");
}
#if ENABLE_FOOD_DISPENSE
clockwiseDispense(motor1);
#endif
}
else if (diagnostic_val == '2') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 2");
}
#if ENABLE_FOOD_DISPENSE
unjamDispenseBySimpleReverse(motor1);
#endif
}
else if (diagnostic_val == '3') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 3");
}
#if ENABLE_FOOD_DISPENSE
unjamDispenseByTickTock(motor1);
#endif
}
else if (diagnostic_val == '4') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 4");
}
#if ENABLE_FOOD_DISPENSE
dispenseFeeder1();
#endif
}
else if (diagnostic_val == '5') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 5");
}
#if ENABLE_WATER_DISPENSE
//normal dispense
#endif
}
else if (diagnostic_val == '6') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 6");
}
#if ENABLE_WATER_DISPENSE
openSolenoid(1);
#endif
}
else if (diagnostic_val == '7') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: 7");
}
#if ENABLE_WATER_DISPENSE
closeSolenoid(1);
#endif
}
else if (diagnostic_val == 'A') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: A");
}
#if ENABLE_FOOD_DISPENSE
clockwiseDispense(motor2);
#endif
}
else if (diagnostic_val == 'B') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: B");
}
#if ENABLE_FOOD_DISPENSE
unjamDispenseBySimpleReverse(motor2);
#endif
}
else if (diagnostic_val == 'C') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: C");
}
#if ENABLE_FOOD_DISPENSE
unjamDispenseByTickTock(motor2);
#endif
}
else if (diagnostic_val == 'D') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: D");
}
#if ENABLE_FOOD_DISPENSE
dispenseFeeder2();
#endif
}
else if (diagnostic_val == 'E') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: E");
}
#if ENABLE_WATER_DISPENSE
//normal dispense
#endif
}
else if (diagnostic_val == 'F') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: F");
}
#if ENABLE_WATER_DISPENSE
openSolenoid(2);
#endif
}
else if (diagnostic_val == 'G') {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("diagnostic_val: G");
}
#if ENABLE_WATER_DISPENSE
closeSolenoid(2);
#endif
}
else {
if (IS_DIAGNOSTIC_MODE && ENABLE_DIAGNOSTIC_SERIAL) {
Serial.println("Unknown diagnostic_val");
}
} // end cases
}
//delay(10); // Wait 10 milliseconds for next reading
}
// Called to send stats/info over serial to the Processing sketch running on a computer connected to the Arduino via USB.
void diagnostic_send_info() {
// Food Sensors
#if ENABLE_FOOD_DISPENSE
Serial.print("INFO://");
Serial.print("sensor1State//");
Serial.println(sensor1State);
Serial.print("INFO://");
Serial.print("moveOperationCounter1//");
Serial.println(moveOperationCounter1);
Serial.print("INFO://");
Serial.print("sensor2State//");
Serial.println(sensor2State);
Serial.print("INFO://");
Serial.print("moveOperationCounter2//");
Serial.println(moveOperationCounter2);
#endif
// Water Sensors:
#if ENABLE_WATER_DISPENSE
Serial.print("INFO://");
Serial.print("sensor3State//");
Serial.println(sensor3State);
Serial.print("INFO://");
Serial.print("moveOperationCounter3//");
Serial.println(moveOperationCounter3);
Serial.print("INFO://");
Serial.print("sensor4State//");
Serial.println(sensor4State);
Serial.print("INFO://");
Serial.print("moveOperationCounter4//");
Serial.println(moveOperationCounter4);
#endif
}