fixed wrong indes for pump determination
improved pump status output fixed led blinking in mode3 random
This commit is contained in:
parent
329a228b2d
commit
fb907f9b12
@ -60,9 +60,24 @@ public:
|
|||||||
* @return false
|
* @return false
|
||||||
*/
|
*/
|
||||||
bool isPumpRequired() {
|
bool isPumpRequired() {
|
||||||
return (this->mSetting->pSensorDry != NULL)
|
bool isDry = getCurrentMoisture() > getSettingsMoisture();
|
||||||
&& (this->moistureRaw.getMedian() > this->mSetting->pSensorDry->get())
|
bool isActive = isPumpTriggerActive();
|
||||||
&& (this->mSetting->pSensorDry->get() != DEACTIVATED_PLANT);
|
return isDry && isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isPumpTriggerActive(){
|
||||||
|
return this->mSetting->pSensorDry->get() != DEACTIVATED_PLANT;
|
||||||
|
}
|
||||||
|
|
||||||
|
float getCurrentMoisture(){
|
||||||
|
return this->moistureRaw.getMedian();
|
||||||
|
}
|
||||||
|
long getSettingsMoisture(){
|
||||||
|
if(this->mSetting->pSensorDry != NULL){
|
||||||
|
return this->mSetting->pSensorDry->get();
|
||||||
|
} else {
|
||||||
|
return DEACTIVATED_PLANT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HomieInternals::SendingPromise& setProperty(const String& property) const {
|
HomieInternals::SendingPromise& setProperty(const String& property) const {
|
||||||
|
@ -441,28 +441,36 @@ int determineNextPump(){
|
|||||||
bool isLowLight =(solarValue > SOLAR_CHARGE_MIN_VOLTAGE || solarValue < SOLAR_CHARGE_MAX_VOLTAGE);
|
bool isLowLight =(solarValue > SOLAR_CHARGE_MIN_VOLTAGE || solarValue < SOLAR_CHARGE_MAX_VOLTAGE);
|
||||||
|
|
||||||
//FIXME instead of for, use sorted by last activation index to ensure equal runtime?
|
//FIXME instead of for, use sorted by last activation index to ensure equal runtime?
|
||||||
|
|
||||||
|
int pumpToUse = -1;
|
||||||
for(int i=0; i < MAX_PLANTS; i++) {
|
for(int i=0; i < MAX_PLANTS; i++) {
|
||||||
|
Plant plant = mPlants[i];
|
||||||
long lastActivation = getLastActivationForPump(i);
|
long lastActivation = getLastActivationForPump(i);
|
||||||
long sinceLastActivation = getCurrentTime()-lastActivation;
|
long sinceLastActivation = getCurrentTime()-lastActivation;
|
||||||
//this pump is in cooldown skip it and disable low power mode trigger for it
|
//this pump is in cooldown skip it and disable low power mode trigger for it
|
||||||
if(mPlants[i].isInCooldown(sinceLastActivation) ){
|
if(plant.isInCooldown(sinceLastActivation) ){
|
||||||
Serial.printf("%d Skipping due to cooldown\r\n", i);
|
Serial.printf("%d Skipping due to cooldown\r\n", i);
|
||||||
setMoistureTrigger(i, DEACTIVATED_PLANT);
|
setMoistureTrigger(i, DEACTIVATED_PLANT);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//skip as it is not low light
|
//skip as it is not low light
|
||||||
if(!isLowLight && mPlants[i].isAllowedOnlyAtLowLight()){
|
if(!isLowLight && plant.isAllowedOnlyAtLowLight()){
|
||||||
Serial.println("Skipping due to light");
|
Serial.printf("%d No pump required: due to light\r\n", i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mPlants->isPumpRequired()){
|
if(plant.isPumpRequired()){
|
||||||
Serial.printf("%d Requested pumping\r\n", i);
|
Serial.printf("%d Requested pumping\r\n", i);
|
||||||
return i;
|
pumpToUse = i;
|
||||||
}
|
}
|
||||||
Serial.printf("%d No pump required\r\n", i);
|
if(plant.isPumpTriggerActive()){
|
||||||
|
Serial.printf("%d No pump required: disabled trigger %f / %ld\r\n", i, plant.getCurrentMoisture(), plant.getSettingsMoisture());
|
||||||
|
}else {
|
||||||
|
Serial.printf("%d No pump required: disabled trigger\r\n", i);
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
|
}
|
||||||
|
return pumpToUse;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -658,7 +666,7 @@ void setup() {
|
|||||||
* @brief Cyclic call
|
* @brief Cyclic call
|
||||||
* Executs the Homie base functionallity or triggers sleeping, if requested.
|
* Executs the Homie base functionallity or triggers sleeping, if requested.
|
||||||
*/
|
*/
|
||||||
|
long nextBlink = 0;
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!mDeepsleep || mode3Active) {
|
if (!mDeepsleep || mode3Active) {
|
||||||
Homie.loop();
|
Homie.loop();
|
||||||
@ -675,7 +683,10 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Toggel Senor LED to visualize mode 3 */
|
/* Toggel Senor LED to visualize mode 3 */
|
||||||
if (mode3Active && (millis() % 100) == 0) {
|
if(mode3Active){
|
||||||
|
if (nextBlink < millis()) {
|
||||||
|
nextBlink = millis() + 500;
|
||||||
digitalWrite(OUTPUT_SENSOR, ! digitalRead(OUTPUT_SENSOR));
|
digitalWrite(OUTPUT_SENSOR, ! digitalRead(OUTPUT_SENSOR));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user