Skip to content

Commit cd69c1c

Browse files
authored
Irrigation: Final refactor of goGetValveTimes()
Final updates to goGetValveTimes() added timeouts for the controller variables system, reduced code to use new allVars int array declared at the top, reduces code base to smaller than the original 2.0 code.
1 parent b239f18 commit cd69c1c

File tree

1 file changed

+13
-26
lines changed

1 file changed

+13
-26
lines changed

examples/IrrigationController/IrrigationController.ino

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ bool buttonPushed = false;
151151
bool showTime = true;
152152
bool clockUpdating = false;
153153
bool recentUpdate = true;
154+
int allVars[] = {V_VAR1, V_VAR2, V_VAR3};
154155
const char *dayOfWeek[] = {
155156
"Null", "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "
156157
};
@@ -858,32 +859,18 @@ void goGetValveTimes()
858859
DEBUG_PRINT(F("Calling for Valve "));
859860
DEBUG_PRINT(valveIndex);
860861
DEBUG_PRINTLN(F(" Data..."));
861-
receivedInitialValue = false;
862-
while (!receivedInitialValue)
863-
{
864-
lcd.setCursor(15, 0);
865-
flashIcon = !flashIcon;
866-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
867-
request(valveIndex, V_VAR1);
868-
wait(50);
869-
}
870-
receivedInitialValue = false;
871-
while (!receivedInitialValue)
872-
{
873-
lcd.setCursor(15, 0);
874-
flashIcon = !flashIcon;
875-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
876-
request(valveIndex, V_VAR2);
877-
wait(50);
878-
}
879-
receivedInitialValue = false;
880-
while (!receivedInitialValue)
881-
{
882-
lcd.setCursor(15, 0);
883-
flashIcon = !flashIcon;
884-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
885-
request(valveIndex, V_VAR3);
886-
wait(50);
862+
for (int a = 0; a < (sizeof(allVars)/sizeof(int)); a++) {
863+
receivedInitialValue = false;
864+
byte timeout = 10;
865+
while (!receivedInitialValue && timeout > 0)
866+
{
867+
lcd.setCursor(15, 0);
868+
flashIcon = !flashIcon;
869+
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
870+
request(valveIndex, allVars[a]);
871+
wait(50);
872+
timeout--;
873+
}
887874
}
888875
valveUpdateTime = millis();
889876
valveIndex++;

0 commit comments

Comments
 (0)