From d69feb4143afdf3f7d42f431842e238b05a3499f Mon Sep 17 00:00:00 2001 From: Empire Date: Fri, 3 Dec 2021 18:36:10 +0000 Subject: [PATCH] basic pump ml calculation --- esp32/src/PlantCtrl.cpp | 6 +++++- esp32/src/main.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index 68f1a22..5a1808d 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -51,10 +51,14 @@ void Plant::init(void) return (candidate >= 0); }); - this->mSetting->pPumpDuration->setDefaultValue(5); + this->mSetting->pPumpDuration->setDefaultValue(30); this->mSetting->pPumpDuration->setValidator([](long candidate) { return ((candidate >= 0) && (candidate <= 1000)); }); + this->mSetting->pPumpMl->setDefaultValue(0); + this->mSetting->pPumpMl->setValidator([](long candidate) { + return ((candidate >= 0) && (candidate <= 5000)); + }); this->mSetting->pPumpPowerLevel->setDefaultValue(100); this->mSetting->pPumpPowerLevel->setValidator([](long candidate) { return ((candidate >= 0) && (candidate <= 100)); diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 2f39f71..9565308 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -601,6 +601,7 @@ void pumpActiveLoop() } #ifdef FLOWMETER_PIN + int16_t pulses; pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_7); esp_err_t result = pcnt_get_counter_value(unit, &pulses); @@ -627,8 +628,10 @@ void pumpActiveLoop() mPlants[pumpToRun].setProperty("waterusage").send(String(pumped)); } } +#endif - long duration = pumpTarget - millis(); + long pumpStarted = pumpTarget - (mPlants[pumpToRun].getPumpDuration() * 1000); + long duration = millis()-pumpStarted; if (millis() > pumpTarget) { mPlants[pumpToRun].setProperty("watertime").send(String(duration)); @@ -639,11 +642,8 @@ void pumpActiveLoop() mPlants[pumpToRun].setProperty("watertime").send(String(duration)); } -#endif - if (targetReached) { - //disable all digitalWrite(OUTPUT_ENABLE_PUMP, LOW); for (int i = 0; i < MAX_PLANTS; i++) @@ -660,7 +660,7 @@ void pumpActiveLoop() void safeSetup() { - throw std::runtime_error("Shit happened"); + //throw std::runtime_error("Shit happened"); /* reduce power consumption */ setCpuFrequencyMhz(80);