Skip to content

Commit df5e379

Browse files
authored
Merge pull request mysensors#24 from itbeyond/master
Irrigation - goGetValveTimes() update + Manual button operation fix
2 parents 38f1279 + cd69c1c commit df5e379

File tree

1 file changed

+47
-52
lines changed

1 file changed

+47
-52
lines changed

examples/IrrigationController/IrrigationController.ino

Lines changed: 47 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ Contributed by Jim ([email protected]) with much contribution from Pete (p
100100

101101
#define NUMBER_OF_VALVES 8 // Change this to set your valve count up to 16.
102102
#define VALVE_RESET_TIME 7500UL // Change this (in milliseconds) for the time you need your valves to hydraulically reset and change state
103+
#define VALVE_TIMES_RELOAD 300000UL // Change this (in milliseconds) for how often to update all valves data from the controller (Loops at value/number valves)
104+
// ie: 300000 for 8 valves produces requests 37.5seconds with all valves updated every 5mins
103105

104106
#define SKETCH_NAME "MySprinkler"
105-
#define SKETCH_VERSION "2.0"
107+
#define SKETCH_VERSION "2.2"
106108
//
107109
#define CHILD_ID_SPRINKLER 0
108110
//
@@ -149,6 +151,7 @@ bool buttonPushed = false;
149151
bool showTime = true;
150152
bool clockUpdating = false;
151153
bool recentUpdate = true;
154+
int allVars[] = {V_VAR1, V_VAR2, V_VAR3};
152155
const char *dayOfWeek[] = {
153156
"Null", "Sunday ", "Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "
154157
};
@@ -175,6 +178,7 @@ MyMessage var1valve(CHILD_ID_SPRINKLER, V_VAR1);
175178
MyMessage var2valve(CHILD_ID_SPRINKLER, V_VAR2);
176179

177180
bool receivedInitialValue = false;
181+
bool inSetup = true;
178182
//
179183
void setup()
180184
{
@@ -241,45 +245,11 @@ void setup()
241245
}
242246
}
243247
//
244-
lcd.clear();
245-
//Update valve data when first powered on
246-
for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
248+
//Update valve data when first powered on
249+
for (byte i = 1; i <= NUMBER_OF_VALVES; i++)
247250
{
248-
lcd.print(F(" Updating "));
249-
lcd.setCursor(0, 1);
250-
lcd.print(F(" Valve Data: "));
251-
lcd.print(i);
252-
bool flashIcon = false;
253-
DEBUG_PRINT(F("Calling for Valve "));
254-
DEBUG_PRINT(i);
255-
DEBUG_PRINTLN(F(" Data..."));
256-
receivedInitialValue = false;
257-
while (!receivedInitialValue)
258-
{
259-
lcd.setCursor(15, 0);
260-
flashIcon = !flashIcon;
261-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
262-
request(i, V_VAR1);
263-
wait(500);
264-
}
265-
receivedInitialValue = false;
266-
while (!receivedInitialValue)
267-
{
268-
lcd.setCursor(15, 0);
269-
flashIcon = !flashIcon;
270-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
271-
request(i, V_VAR2);
272-
wait(500);
273-
}
274-
receivedInitialValue = false;
275-
while (!receivedInitialValue)
276-
{
277-
lcd.setCursor(15, 0);
278-
flashIcon = !flashIcon;
279-
flashIcon ? lcd.write(byte(1)) : lcd.print(F(" "));
280-
request(i, V_VAR3);
281-
wait(500);
282-
}
251+
lcd.clear();
252+
goGetValveTimes();
283253
}
284254
lcd.clear();
285255
}
@@ -360,6 +330,7 @@ void loop()
360330
{
361331
send(msg1valve.setSensor(i).set(false), false);
362332
}
333+
wait(50);
363334
}
364335
}
365336
lastValve = valveNumber;
@@ -395,6 +366,7 @@ void loop()
395366
for (byte i = 0; i <= NUMBER_OF_VALVES; i++)
396367
{
397368
send(msg1valve.setSensor(i).set(false), false);
369+
wait(50);
398370
}
399371
DEBUG_PRINT(F("State = "));
400372
DEBUG_PRINTLN(state);
@@ -417,6 +389,7 @@ void loop()
417389
{
418390
send(msg1valve.setSensor(i).set(false), false);
419391
}
392+
wait(50);
420393
}
421394
DEBUG_PRINTLN(F("State Changed, Single Zone Running..."));
422395
DEBUG_PRINT(F("Zone: "));
@@ -456,11 +429,14 @@ void loop()
456429
state = STAND_BY_ALL_OFF;
457430
}
458431
}
459-
else if (state == ZONE_SELECT_MENU)
432+
if (state == ZONE_SELECT_MENU)
460433
{
461434
displayMenu();
435+
}
436+
else
437+
{
438+
lastState = state;
462439
}
463-
lastState = state;
464440
}
465441
//
466442
void displayMenu(void)
@@ -625,9 +601,9 @@ void receive(const MyMessage &message)
625601
}
626602
valveNickName[i] = "";
627603
valveNickName[i] += newMessage;
628-
DEBUG_PRINT(F("Recieved new name for zone "));
604+
DEBUG_PRINT(F("Recieved variable3 valve: "));
629605
DEBUG_PRINT(i);
630-
DEBUG_PRINT(F(" and it is now called: "));
606+
DEBUG_PRINT(F(" = "));
631607
DEBUG_PRINTLN(valveNickName[i]);
632608
}
633609
receivedInitialValue = true;
@@ -646,7 +622,9 @@ void receive(const MyMessage &message)
646622
DEBUG_PRINT(F(" individual time: "));
647623
DEBUG_PRINT(valveSoloTime[i]);
648624
DEBUG_PRINT(F(" group time: "));
649-
DEBUG_PRINTLN(allZoneTime[i]);
625+
DEBUG_PRINT(allZoneTime[i]);
626+
DEBUG_PRINT(F(" name: "));
627+
DEBUG_PRINTLN(valveNickName[i]);
650628
recentUpdate = true;
651629
}
652630
}
@@ -869,17 +847,34 @@ void goGetValveTimes()
869847
{
870848
static unsigned long valveUpdateTime;
871849
static byte valveIndex = 1;
872-
if (millis() - valveUpdateTime >= 300000UL / NUMBER_OF_VALVES)// update each valve once every 5 mins (distributes the traffic)
850+
if (inSetup || millis() - valveUpdateTime >= VALVE_TIMES_RELOAD / NUMBER_OF_VALVES) // update each valve once every 5 mins (distributes the traffic)
873851
{
874-
DEBUG_PRINTLN(F("Calling for Valve Data..."));
875-
lcd.setCursor(15, 0);
876-
lcd.write(byte(1)); //lcd.write(1);
877-
request(valveIndex, V_VAR1);
878-
request(valveIndex, V_VAR2);
879-
request(valveIndex, V_VAR3);
852+
if (inSetup) {
853+
lcd.print(F(" Updating "));
854+
lcd.setCursor(0, 1);
855+
lcd.print(F(" Valve Data: "));
856+
lcd.print(valveIndex);
857+
}
858+
bool flashIcon = false;
859+
DEBUG_PRINT(F("Calling for Valve "));
860+
DEBUG_PRINT(valveIndex);
861+
DEBUG_PRINTLN(F(" Data..."));
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+
}
874+
}
880875
valveUpdateTime = millis();
881876
valveIndex++;
882-
if (valveIndex > NUMBER_OF_VALVES + 1)
877+
if (valveIndex > NUMBER_OF_VALVES)
883878
{
884879
valveIndex = 1;
885880
}

0 commit comments

Comments
 (0)