From f0127921b1bc13c13bf3e158a623bd676eb63322 Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 26 May 2021 20:19:27 +0200 Subject: [PATCH] Handle different start and end times to water plants --- esp32/src/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 8a8d213..5ce649b 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -367,9 +367,17 @@ int determineNextPump() } if (plant.isPumpRequired()) { - if ((plant.getHoursStart() > getCurrentHour() && plant.getHoursEnd() < getCurrentHour()) || - (getCurrentTime() < 10000) /* no time from NTP received */) - {todotdotdotodtodtoedot + /* Handle e.g. start = 21, end = 8 */ + if (((plant.getHoursStart() > plant.getHoursEnd()) && + (getCurrentHour() >= plant.getHoursStart() || getCurrentHour() <= plant.getHoursEnd())) + || + /* Handle e.g. start = 8, end = 21 */ + ((plant.getHoursStart() < plant.getHoursEnd()) && + (getCurrentHour() >= plant.getHoursStart() && getCurrentHour() <= plant.getHoursEnd())) + || + /* no time from NTP received */ + (getCurrentTime() < 10000) ) + { Serial.printf("%d Requested pumping\r\n", i); pumpToUse = i; } else {