2020-09-07 18:18:46 +02:00
|
|
|
/**
|
|
|
|
* @file PlantCtrl.cpp
|
|
|
|
* @author your name (you@domain.com)
|
|
|
|
* @brief
|
|
|
|
* @version 0.1
|
|
|
|
* @date 2020-05-27
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PlantCtrl.h"
|
|
|
|
|
2020-10-16 18:25:02 +02:00
|
|
|
Plant::Plant(int pinSensor, int pinPump,int plantId, HomieNode* plant, PlantSettings_t* setting) {
|
2020-10-14 20:07:56 +02:00
|
|
|
this->mPinSensor = pinSensor;
|
|
|
|
this->mPinPump = pinPump;
|
2020-10-16 16:22:48 +02:00
|
|
|
this->mPlant = plant;
|
2020-10-16 18:25:02 +02:00
|
|
|
this->mSetting = setting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Plant::init(void) {
|
|
|
|
this->mSetting->pSensorDry->setDefaultValue(4095);
|
|
|
|
this->mSetting->pSensorDry->setValidator([] (long candidate) {
|
2020-10-16 16:22:48 +02:00
|
|
|
return ((candidate >= 0) && (candidate <= 4095) );
|
|
|
|
});
|
2020-10-16 18:25:02 +02:00
|
|
|
this->mSetting->pSensorWet->setDefaultValue(0);
|
|
|
|
this->mSetting->pSensorWet->setValidator([] (long candidate) {
|
2020-10-16 16:22:48 +02:00
|
|
|
return ((candidate >= 0) && (candidate <= 4095) );
|
|
|
|
});
|
2020-10-16 18:25:02 +02:00
|
|
|
this->mSetting->pPumpAllowedHourRangeStart->setDefaultValue(8);
|
|
|
|
this->mSetting->pPumpAllowedHourRangeStart->setValidator([] (long candidate) {
|
2020-10-16 16:22:48 +02:00
|
|
|
return ((candidate >= 0) && (candidate <= 23) );
|
|
|
|
});
|
2020-10-16 18:25:02 +02:00
|
|
|
this->mSetting->pPumpAllowedHourRangeEnd->setDefaultValue(20);
|
|
|
|
this->mSetting->pPumpAllowedHourRangeEnd->setValidator([] (long candidate) {
|
2020-10-16 16:22:48 +02:00
|
|
|
return ((candidate >= 0) && (candidate <= 23) );
|
|
|
|
});
|
2020-10-16 18:25:02 +02:00
|
|
|
this->mSetting->pPumpOnlyWhenLowLight->setDefaultValue(true);
|
|
|
|
this->mSetting->pPumpCooldownInHours->setDefaultValue(20);
|
|
|
|
this->mSetting->pPumpCooldownInHours->setValidator([] (long candidate) {
|
2020-10-16 16:22:48 +02:00
|
|
|
return ((candidate >= 0) && (candidate <= 1024) );
|
|
|
|
});
|
2020-10-16 18:25:02 +02:00
|
|
|
|
2020-09-07 18:18:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Plant::addSenseValue(int analog) {
|
|
|
|
this->mAnalogValue += analog;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Plant::calculateSensorValue(int amountMeasurePoints) {
|
|
|
|
this->mValue = this->mAnalogValue / amountMeasurePoints;
|
|
|
|
this->mAnalogValue = 0;
|
|
|
|
}
|