pump refactor round 1
This commit is contained in:
parent
d00517ec1e
commit
af618e73f3
@ -82,12 +82,12 @@
|
||||
/** \addtogroup Configuration
|
||||
* @{
|
||||
*/
|
||||
#define FIRMWARE_VERSION "sw 2.0 hw 0.10b"
|
||||
#define FIRMWARE_VERSION "sw 2.1 hw 0.10b"
|
||||
|
||||
#define TIMED_LIGHT_PIN CUSTOM1_PIN5
|
||||
//#define FLOWMETER_PIN CUSTOM1_PIN1
|
||||
#define FLOWMETER_PIN CUSTOM1_PIN1
|
||||
#ifdef FLOWMETER_PIN
|
||||
#define FLOWMETER_FLOWFACTOR 22 /** F = 22 * Q;Q = L/min */
|
||||
#define FLOWMETER_FLOWFACTOR 23 /** F = 22 * Q;Q = L/min */
|
||||
#endif
|
||||
|
||||
#define MOIST_SENSOR_MAX_FRQ 60000 // 60kHz (500Hz margin)
|
||||
|
@ -105,9 +105,10 @@ HomieSetting<const char *> ntpServer("ntpServer", "NTP server (pool.ntp.org as d
|
||||
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"); \
|
||||
HomieSetting<long> mPumpCooldownInMinutes##plant = HomieSetting<long>("delay" strplant, "Plant" strplant " - How long to wait until the pump is activated again (minutes)"); \
|
||||
HomieSetting<long> pPumpDuration##plant = HomieSetting<long>("pumpDuration" strplant, "Plant" strplant " - time seconds or ml (if using flowmeter) to water when pump is active"); \
|
||||
HomieSetting<long> pPumpDuration##plant = HomieSetting<long>("pumpDuration" strplant, "Plant" strplant " - time seconds to water when pump is active"); \
|
||||
HomieSetting<long> pPumpMl##plant = HomieSetting<long>("pumpAmount" strplant, "Plant" strplant " - ml (if using flowmeter) to water when pump is active"); \
|
||||
HomieSetting<long> pPowerLevel##plant = HomieSetting<long>("powerLevel" strplant, "Plant" strplant " - pwm duty cycle in percent"); \
|
||||
PlantSettings_t mSetting##plant = {&mSensorDry##plant, &mPumpAllowedHourRangeStart##plant, &mPumpAllowedHourRangeEnd##plant, &mPumpOnlyWhenLowLight##plant, &mPumpCooldownInMinutes##plant, &pPumpDuration##plant, &pPowerLevel##plant}; \
|
||||
PlantSettings_t mSetting##plant = {&mSensorDry##plant, &mPumpAllowedHourRangeStart##plant, &mPumpAllowedHourRangeEnd##plant, &mPumpOnlyWhenLowLight##plant, &mPumpCooldownInMinutes##plant, &pPumpDuration##plant, &pPowerLevel##plant, &pPumpMl##plant}; \
|
||||
/**< Generate all settings for one plant \
|
||||
* \
|
||||
* Feature to start pumping only at morning: @link{SOLAR_CHARGE_MIN_VOLTAGE} and @link{SOLAR_CHARGE_MAX_VOLTAGE} \
|
||||
|
@ -29,6 +29,7 @@ typedef struct PlantSettings_t
|
||||
HomieSetting<long> *pPumpCooldownInSeconds;
|
||||
HomieSetting<long> *pPumpDuration;
|
||||
HomieSetting<long> *pPumpPowerLevel;
|
||||
HomieSetting<long> *pPumpMl;
|
||||
} PlantSettings_t;
|
||||
|
||||
#endif
|
@ -69,7 +69,7 @@ RTC_DATA_ATTR long consecutiveWateringPlant[MAX_PLANTS] = {0};
|
||||
bool volatile mDownloadMode = false; /**< Controller must not sleep */
|
||||
bool volatile mSensorsRead = false; /**< Sensors are read without Wifi or MQTT */
|
||||
int volatile pumpToRun = -1; /** pump to run at the end of the cycle */
|
||||
int volatile selfTestPumpRun = -1; /** pump to run at the end of the cycle */
|
||||
int volatile selfTestPumpRun = -1; /** pump to run at the end of the cycle */
|
||||
|
||||
bool mConfigured = false;
|
||||
long nextBlink = 0; /**< Time needed in main loop to support expected blink code */
|
||||
@ -80,6 +80,7 @@ unsigned long setupFinishedTimestamp;
|
||||
|
||||
bool pumpStarted = false;
|
||||
long pumpTarget = -1;
|
||||
long lastSendPumpUpdate = 0;
|
||||
#ifdef FLOWMETER_PIN
|
||||
long pumpTargetMl = -1;
|
||||
#endif
|
||||
@ -568,10 +569,10 @@ void initPumpLogic()
|
||||
|
||||
pcnt_counter_clear(unit); // Zera o contador PCNT
|
||||
pcnt_counter_resume(unit);
|
||||
#else
|
||||
#endif
|
||||
pumpTarget = millis() + (mPlants[pumpToRun].getPumpDuration() * 1000);
|
||||
log(LOG_LEVEL_INFO, "Starting pump " + String(pumpToRun) + " for " + String(mPlants[pumpToRun].getPumpDuration()) + "s", LOG_PUMP_STARTED_CODE);
|
||||
#endif
|
||||
|
||||
//enable power
|
||||
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
|
||||
digitalWrite(OUTPUT_ENABLE_PUMP, HIGH);
|
||||
@ -592,6 +593,13 @@ void pumpActiveLoop()
|
||||
rtcLastWateringPlant[pumpToRun] = getCurrentTime();
|
||||
}
|
||||
|
||||
bool mqttUpdateTick = false;
|
||||
if (lastSendPumpUpdate + 1000 < millis())
|
||||
{
|
||||
lastSendPumpUpdate = millis();
|
||||
mqttUpdateTick = true;
|
||||
}
|
||||
|
||||
#ifdef FLOWMETER_PIN
|
||||
int16_t pulses;
|
||||
pcnt_unit_t unit = (pcnt_unit_t)(PCNT_UNIT_7);
|
||||
@ -612,14 +620,25 @@ void pumpActiveLoop()
|
||||
{
|
||||
targetReached = true;
|
||||
pcnt_counter_pause(unit);
|
||||
mPlants[pumpToRun].setProperty("waterusage").send(String(pumped));
|
||||
}
|
||||
else if (mqttUpdateTick)
|
||||
{
|
||||
mPlants[pumpToRun].setProperty("waterusage").send(String(pumped));
|
||||
}
|
||||
mPlants[pumpToRun].setProperty("waterusage").send(String(pumped));
|
||||
}
|
||||
#else
|
||||
|
||||
long duration = pumpTarget - millis();
|
||||
if (millis() > pumpTarget)
|
||||
{
|
||||
mPlants[pumpToRun].setProperty("watertime").send(String(duration));
|
||||
targetReached = true;
|
||||
}
|
||||
else if (mqttUpdateTick)
|
||||
{
|
||||
mPlants[pumpToRun].setProperty("watertime").send(String(duration));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (targetReached)
|
||||
@ -831,7 +850,7 @@ void setup()
|
||||
|
||||
void selfTest()
|
||||
{
|
||||
|
||||
|
||||
if (selfTestPumpRun >= 0 && selfTestPumpRun < MAX_PLANTS)
|
||||
{
|
||||
Serial << "self test mode pump deactivate " << pumpToRun << endl;
|
||||
|
Loading…
Reference in New Issue
Block a user