code cleanups
This commit is contained in:
@@ -80,8 +80,8 @@
|
||||
*/
|
||||
#define FIRMWARE_VERSION "sw 1.3 hw 0.10"
|
||||
|
||||
#define MOIST_SENSOR_MAX_ADC 1200 //swamp earth - 50 margin
|
||||
#define MOIST_SENSOR_MIN_ADC 1800 //dry earth + 1500 margin
|
||||
#define MOIST_SENSOR_MAX_ADC 2800 //swamp earth - 50 margin
|
||||
#define MOIST_SENSOR_MIN_ADC 1200 //dry earth + 1500 margin
|
||||
|
||||
#define SOLAR_VOLT_FACTOR 11
|
||||
#define BATTSENSOR_INDEX_SOLAR 0
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#define MAX_PLANTS 7
|
||||
|
||||
|
||||
/**
|
||||
* @name Homie Attributes
|
||||
* generated Information
|
||||
@@ -88,7 +89,7 @@ HomieSetting<const char *> ntpServer("ntpServer", "NTP server (pool.ntp.org as d
|
||||
**/
|
||||
|
||||
#define GENERATE_PLANT(plant, strplant) \
|
||||
HomieSetting<long> mSensorDry##plant = HomieSetting<long>("dry" strplant, "Plant " strplant "- Moist sensor dry threshold"); \
|
||||
HomieSetting<double> mSensorDry##plant = HomieSetting<double>("dry" strplant, "Plant " strplant "- Moist sensor dry %"); \
|
||||
HomieSetting<long> mPumpAllowedHourRangeStart##plant = HomieSetting<long>("hourstart" strplant, "Plant" strplant " - Range pump allowed hour start (0-23)"); \
|
||||
HomieSetting<long> mPumpAllowedHourRangeEnd##plant = HomieSetting<long>("hourend" strplant, "Plant" strplant " - Range pump allowed hour end (0-23)"); \
|
||||
HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("lowLight" strplant, "Plant" strplant " - Enable the Pump only, when there is no sunlight"); \
|
||||
|
@@ -13,12 +13,12 @@
|
||||
|
||||
#include <Homie.h>
|
||||
|
||||
#define DEACTIVATED_PLANT 5000
|
||||
#define MISSING_SENSOR 5001
|
||||
#define DEACTIVATED_PLANT -1
|
||||
#define MISSING_SENSOR -2
|
||||
|
||||
typedef struct PlantSettings_t
|
||||
{
|
||||
HomieSetting<long> *pSensorDry;
|
||||
HomieSetting<double> *pSensorDry;
|
||||
HomieSetting<long> *pPumpAllowedHourRangeStart;
|
||||
HomieSetting<long> *pPumpAllowedHourRangeEnd;
|
||||
HomieSetting<bool> *pPumpOnlyWhenLowLight;
|
||||
|
7
esp32/include/MathUtils.h
Normal file
7
esp32/include/MathUtils.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef MATHUTILS_H
|
||||
#define MATHUTILS_H
|
||||
|
||||
|
||||
bool equalish(double x, double y);
|
||||
|
||||
#endif
|
@@ -13,7 +13,9 @@
|
||||
#define PLANT_CTRL_H
|
||||
|
||||
#include "HomieTypes.h"
|
||||
#include "ControllerConfiguration.h"
|
||||
#include "RunningMedian.h"
|
||||
#include "MathUtils.h"
|
||||
|
||||
class Plant
|
||||
{
|
||||
@@ -62,14 +64,15 @@ public:
|
||||
*/
|
||||
bool isPumpRequired()
|
||||
{
|
||||
bool isDry = getCurrentMoisture() > getSettingsMoisture();
|
||||
bool isDry = getCurrentMoisture() > getSetting2Moisture();
|
||||
bool isActive = isPumpTriggerActive();
|
||||
return isDry && isActive;
|
||||
}
|
||||
|
||||
bool isPumpTriggerActive()
|
||||
{
|
||||
return this->mSetting->pSensorDry->get() != DEACTIVATED_PLANT;
|
||||
long current = this->mSetting->pSensorDry->get();
|
||||
return !equalish(current,DEACTIVATED_PLANT);
|
||||
}
|
||||
|
||||
float getCurrentMoisture()
|
||||
@@ -79,11 +82,13 @@ public:
|
||||
}
|
||||
return this->moistureRaw.getMedian();
|
||||
}
|
||||
long getSettingsMoisture()
|
||||
|
||||
long getSetting2Moisture()
|
||||
{
|
||||
if (this->mSetting->pSensorDry != NULL)
|
||||
{
|
||||
return this->mSetting->pSensorDry->get();
|
||||
float percent = (this->mSetting->pSensorDry->get());
|
||||
return MOIST_SENSOR_MIN_ADC + ((MOIST_SENSOR_MAX_ADC - MOIST_SENSOR_MIN_ADC) * percent);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user