basic pump ml calculation

This commit is contained in:
Empire 2021-12-03 18:36:10 +00:00
parent 61fad8e14c
commit d69feb4143
2 changed files with 10 additions and 6 deletions

View File

@ -51,10 +51,14 @@ void Plant::init(void)
return (candidate >= 0); return (candidate >= 0);
}); });
this->mSetting->pPumpDuration->setDefaultValue(5); this->mSetting->pPumpDuration->setDefaultValue(30);
this->mSetting->pPumpDuration->setValidator([](long candidate) { this->mSetting->pPumpDuration->setValidator([](long candidate) {
return ((candidate >= 0) && (candidate <= 1000)); 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->setDefaultValue(100);
this->mSetting->pPumpPowerLevel->setValidator([](long candidate) { this->mSetting->pPumpPowerLevel->setValidator([](long candidate) {
return ((candidate >= 0) && (candidate <= 100)); return ((candidate >= 0) && (candidate <= 100));

View File

@ -601,6 +601,7 @@ void pumpActiveLoop()
} }
#ifdef FLOWMETER_PIN #ifdef FLOWMETER_PIN
int16_t pulses; int16_t pulses;
pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_7); pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_7);
esp_err_t result = pcnt_get_counter_value(unit, &pulses); esp_err_t result = pcnt_get_counter_value(unit, &pulses);
@ -627,8 +628,10 @@ void pumpActiveLoop()
mPlants[pumpToRun].setProperty("waterusage").send(String(pumped)); 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) if (millis() > pumpTarget)
{ {
mPlants[pumpToRun].setProperty("watertime").send(String(duration)); mPlants[pumpToRun].setProperty("watertime").send(String(duration));
@ -639,11 +642,8 @@ void pumpActiveLoop()
mPlants[pumpToRun].setProperty("watertime").send(String(duration)); mPlants[pumpToRun].setProperty("watertime").send(String(duration));
} }
#endif
if (targetReached) if (targetReached)
{ {
//disable all //disable all
digitalWrite(OUTPUT_ENABLE_PUMP, LOW); digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
for (int i = 0; i < MAX_PLANTS; i++) for (int i = 0; i < MAX_PLANTS; i++)
@ -660,7 +660,7 @@ void pumpActiveLoop()
void safeSetup() void safeSetup()
{ {
throw std::runtime_error("Shit happened"); //throw std::runtime_error("Shit happened");
/* reduce power consumption */ /* reduce power consumption */
setCpuFrequencyMhz(80); setCpuFrequencyMhz(80);