2020-09-07 18:18:46 +02:00
|
|
|
/**
|
|
|
|
* @file PlantCtrl.h
|
|
|
|
* @author your name (you@domain.com)
|
|
|
|
* @brief Abstraction to handle the Sensors
|
|
|
|
* @version 0.1
|
|
|
|
* @date 2020-05-27
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLANT_CTRL_H
|
|
|
|
#define PLANT_CTRL_H
|
|
|
|
|
2020-10-16 16:22:48 +02:00
|
|
|
#include "HomieTypes.h"
|
2020-10-21 20:46:09 +02:00
|
|
|
#include "RunningMedian.h"
|
2020-09-21 19:40:01 +02:00
|
|
|
|
2020-09-07 18:18:46 +02:00
|
|
|
class Plant {
|
|
|
|
|
|
|
|
private:
|
2020-10-21 20:46:09 +02:00
|
|
|
RunningMedian moistureRaw = RunningMedian(5);
|
2020-10-16 18:25:02 +02:00
|
|
|
HomieNode* mPlant = NULL;
|
2020-09-07 18:18:46 +02:00
|
|
|
|
|
|
|
public:
|
2020-10-20 18:06:37 +02:00
|
|
|
//FIXME visibility
|
|
|
|
int mPinSensor=0; /**< Pin of the moist sensor */
|
|
|
|
int mPinPump=0; /**< Pin of the pump */
|
2020-10-19 01:39:56 +02:00
|
|
|
PlantSettings_t* mSetting;
|
2020-09-07 18:18:46 +02:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Plant object
|
|
|
|
*
|
|
|
|
* @param pinSensor Pin of the Sensor to use to measure moist
|
|
|
|
* @param pinPump Pin of the Pump to use
|
|
|
|
*/
|
2020-09-21 19:40:01 +02:00
|
|
|
Plant(int pinSensor, int pinPump,
|
2020-10-16 16:22:48 +02:00
|
|
|
int plantId,
|
|
|
|
HomieNode* plant,
|
|
|
|
PlantSettings_t* setting);
|
2020-09-07 18:18:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add a value, to be measured
|
|
|
|
*
|
|
|
|
* @param analogValue
|
|
|
|
*/
|
|
|
|
void addSenseValue(int analogValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the Sensor Pin of the analog measuring
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
int getSensorPin() { return mPinSensor; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the Pump Pin object
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
int getPumpPin() { return mPinPump; }
|
|
|
|
|
2020-10-21 20:46:09 +02:00
|
|
|
int getSensorValue() { return moistureRaw.getMedian(); }
|
2020-09-07 18:18:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if a plant is too dry and needs some water.
|
|
|
|
*
|
|
|
|
* @return true
|
|
|
|
* @return false
|
|
|
|
*/
|
2020-09-21 19:40:01 +02:00
|
|
|
bool isPumpRequired() {
|
2020-10-21 20:46:09 +02:00
|
|
|
return (this->mSetting->pSensorDry != NULL) && (this->moistureRaw.getMedian() < this->mSetting->pSensorDry->get());
|
2020-09-21 19:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HomieInternals::SendingPromise& setProperty(const String& property) const {
|
|
|
|
return mPlant->setProperty(property);
|
|
|
|
}
|
2020-10-16 18:25:02 +02:00
|
|
|
|
|
|
|
void init(void);
|
2020-09-07 18:18:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|