From 39a8ecde85266c37bd30b23bbd596eed904025a9 Mon Sep 17 00:00:00 2001 From: lukas Date: Wed, 31 Mar 2021 17:28:54 +0200 Subject: [PATCH] turn of fan when pump cycle starts to prevent too much current draw --- src/Heating.cpp | 25 +++++++++++++++++++++---- src/Heating.h | 4 +++- src/main.cpp | 6 ++++++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Heating.cpp b/src/Heating.cpp index 8d63a27..53ae6ab 100644 --- a/src/Heating.cpp +++ b/src/Heating.cpp @@ -12,6 +12,7 @@ Heating::Heating() : mHeizungTicker(), msettings(nullptr), mheatingservice(nullptr), mHeatingStatus(false), + mPumpCycleActive(false), lasttemp(0), lasthum(0), sensor() {} @@ -32,8 +33,8 @@ void Heating::init(unsigned mode, const SettingState *settings, HeatingInfoServi sensor.onData([this](float hum, float temp) { schedule_function([hum, temp, this]() { - Serial.printf("Temp: %gdegC\n", temp); - Serial.printf("Humid: %g%%\n", hum); +// Serial.printf("Temp: %gdegC\n", temp); +// Serial.printf("Humid: %g%%\n", hum); mheatingservice->setSensorData(hum, temp); @@ -76,9 +77,12 @@ void Heating::handleHeatingEvents() { if (mHeatingStatus == false) { // turn off active turnoff timers mLuefterTicker.detach(); - ////Serial.println("heating should run now!"); + //Serial.println("heating should run now!"); // turn on heating and fan - digitalWrite(LuefterPin, HIGH); + if (!mPumpCycleActive) { + digitalWrite(LuefterPin, HIGH); + } + digitalWrite(HeizungPin, HIGH); mHeatingStatus = true; @@ -139,3 +143,16 @@ void Heating::handleTimeHeater() { func(); mHeizungTicker.attach(refreshperiod, func); } + +void Heating::setPumCycleActive(bool active) { + mPumpCycleActive = active; + + // turn off fan if pumpcycleactive + if (active) { + digitalWrite(LuefterPin, LOW); + } else { + if (mHeatingStatus) { + digitalWrite(LuefterPin, HIGH); + } + } +} diff --git a/src/Heating.h b/src/Heating.h index d4b5980..9896a9d 100644 --- a/src/Heating.h +++ b/src/Heating.h @@ -21,6 +21,8 @@ public: */ void init(unsigned mode, const SettingState* settings, HeatingInfoService *heatingservice); + void setPumCycleActive(bool active); + enum MODES {TIME, HUMIDITY}; private: Ticker mHeizungTicker; @@ -30,7 +32,7 @@ private: const SettingState* msettings; HeatingInfoService *mheatingservice; - bool mHeatingStatus; + bool mHeatingStatus, mPumpCycleActive; float lasttemp; float lasthum; diff --git a/src/main.cpp b/src/main.cpp index 41787c8..dd516c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,9 @@ void pumpeSchalten(bool on) { pumpcycles++; generalinfo.setPumpCycles(pumpcycles); + // pump cycle started + mHeat.setPumCycleActive(true); + pumpendauer.once((float) settingsservice.getSettings()->maxpumpduration + 1, []() { //erlaube keine einschaltung von mehr als 60 sek if (Timer::getSystemSeconds() - turnontime >= @@ -57,6 +60,9 @@ void pumpeSchalten(bool on) { }); } else { generalinfo.setPumpDuration(Timer::getSystemSeconds() - turnontime); + + // pump cycle stopped... + mHeat.setPumCycleActive(false); } // save pump start time