two modes if no humidity sensor available
This commit is contained in:
		
							
								
								
									
										110
									
								
								src/Heating.cpp
									
									
									
									
									
								
							
							
						
						
									
										110
									
								
								src/Heating.cpp
									
									
									
									
									
								
							@@ -5,46 +5,82 @@
 | 
			
		||||
#include "Heating.h"
 | 
			
		||||
#include "Pins.h"
 | 
			
		||||
 | 
			
		||||
void Heating::init(Temperature *tempsensor) {
 | 
			
		||||
    mFanWaiting = false;
 | 
			
		||||
void Heating::init(Temperature *tempsensor, unsigned mode) {
 | 
			
		||||
    switch (mode) {
 | 
			
		||||
        case TIME: {
 | 
			
		||||
            const unsigned percentOn = 20;
 | 
			
		||||
            const unsigned refreshperiod = 60;
 | 
			
		||||
 | 
			
		||||
    mHeizungTicker.attach(10, [&tempsensor, this]() {
 | 
			
		||||
        // shedule this function because tempread is blocking
 | 
			
		||||
        schedule_function([this, &tempsensor](){
 | 
			
		||||
            // check temperature
 | 
			
		||||
            Serial.println("checking humidity");
 | 
			
		||||
            const float hum = tempsensor->getHum();
 | 
			
		||||
            if (hum == -1) return;
 | 
			
		||||
 | 
			
		||||
            Serial.print("humidity read: ");
 | 
			
		||||
            Serial.println(hum);
 | 
			
		||||
 | 
			
		||||
            if (hum > 65.0) {
 | 
			
		||||
                // turn off active turnoff timers
 | 
			
		||||
            const auto func = [this]() {
 | 
			
		||||
                mLuefterTicker.detach();
 | 
			
		||||
                Serial.println("heating should run now!");
 | 
			
		||||
                // turn on heating and fan
 | 
			
		||||
 | 
			
		||||
                // every minute turn on the heating
 | 
			
		||||
                digitalWrite(LuefterPin, HIGH);
 | 
			
		||||
                digitalWrite(HeizungPin, HIGH);
 | 
			
		||||
 | 
			
		||||
                // if fan waiting detach its ticker
 | 
			
		||||
                if (mFanWaiting) {
 | 
			
		||||
                    mLuefterTicker.detach();
 | 
			
		||||
                    mFanWaiting = false;
 | 
			
		||||
                }
 | 
			
		||||
            } else if (hum < 60.0) {
 | 
			
		||||
                // if humidity too low turn off heating and fan after 60secs
 | 
			
		||||
                digitalWrite(HeizungPin, LOW);
 | 
			
		||||
                Serial.println("heating should NOT run now!");
 | 
			
		||||
                if (!mFanWaiting) {
 | 
			
		||||
                    mFanWaiting = true;
 | 
			
		||||
                    mLuefterTicker.once(60, []() {
 | 
			
		||||
                        // turn off fan
 | 
			
		||||
                        digitalWrite(LuefterPin, LOW);
 | 
			
		||||
                        Serial.println("turning off fan");
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
                Serial.println("Turning on heating");
 | 
			
		||||
 | 
			
		||||
                mTurnOffTicker.once(refreshperiod * percentOn / 100, []() {
 | 
			
		||||
                    digitalWrite(HeizungPin, LOW);
 | 
			
		||||
 | 
			
		||||
                    Serial.println("Turned off heating!");
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                mLuefterTicker.once((refreshperiod * percentOn / 100) + 30, []() {
 | 
			
		||||
                    digitalWrite(LuefterPin, LOW);
 | 
			
		||||
 | 
			
		||||
                    Serial.println("Turned off fan!");
 | 
			
		||||
                });
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            func();
 | 
			
		||||
            mHeizungTicker.attach(60, func);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        case HUMIDITY:
 | 
			
		||||
            mFanWaiting = false;
 | 
			
		||||
 | 
			
		||||
            mHeizungTicker.attach(10, [&tempsensor, this]() {
 | 
			
		||||
                // shedule this function because tempread is blocking
 | 
			
		||||
                schedule_function([this, &tempsensor]() {
 | 
			
		||||
                    // check temperature
 | 
			
		||||
                    Serial.println("checking humidity");
 | 
			
		||||
                    const float hum = tempsensor->getHum();
 | 
			
		||||
                    if (hum == -1) return;
 | 
			
		||||
 | 
			
		||||
                    Serial.print("humidity read: ");
 | 
			
		||||
                    Serial.println(hum);
 | 
			
		||||
 | 
			
		||||
                    if (hum > 65.0) {
 | 
			
		||||
                        // turn off active turnoff timers
 | 
			
		||||
                        mLuefterTicker.detach();
 | 
			
		||||
                        Serial.println("heating should run now!");
 | 
			
		||||
                        // turn on heating and fan
 | 
			
		||||
                        digitalWrite(LuefterPin, HIGH);
 | 
			
		||||
                        digitalWrite(HeizungPin, HIGH);
 | 
			
		||||
 | 
			
		||||
                        // if fan waiting detach its ticker
 | 
			
		||||
                        if (mFanWaiting) {
 | 
			
		||||
                            mLuefterTicker.detach();
 | 
			
		||||
                            mFanWaiting = false;
 | 
			
		||||
                        }
 | 
			
		||||
                    } else if (hum < 60.0) {
 | 
			
		||||
                        // if humidity too low turn off heating and fan after 60secs
 | 
			
		||||
                        digitalWrite(HeizungPin, LOW);
 | 
			
		||||
                        Serial.println("heating should NOT run now!");
 | 
			
		||||
                        if (!mFanWaiting) {
 | 
			
		||||
                            mFanWaiting = true;
 | 
			
		||||
                            mLuefterTicker.once(60, []() {
 | 
			
		||||
                                // turn off fan
 | 
			
		||||
                                digitalWrite(LuefterPin, LOW);
 | 
			
		||||
                                Serial.println("turning off fan");
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,10 +9,13 @@
 | 
			
		||||
 | 
			
		||||
class Heating {
 | 
			
		||||
public:
 | 
			
		||||
    void init(Temperature* tempsensor);
 | 
			
		||||
    void init(Temperature* tempsensor, unsigned mode);
 | 
			
		||||
 | 
			
		||||
    enum MODES {TIME, HUMIDITY};
 | 
			
		||||
private:
 | 
			
		||||
    Ticker mHeizungTicker;
 | 
			
		||||
    Ticker mLuefterTicker;
 | 
			
		||||
    Ticker mTurnOffTicker;
 | 
			
		||||
 | 
			
		||||
    bool mFanWaiting;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -189,7 +189,7 @@ void setup() {
 | 
			
		||||
    mang.init(&temp);
 | 
			
		||||
 | 
			
		||||
    Serial.println("initializing heating service");
 | 
			
		||||
    mHeat.init(&temp);
 | 
			
		||||
    mHeat.init(&temp, Heating::TIME);
 | 
			
		||||
 | 
			
		||||
    Serial.println("startup sequence complete!\n");
 | 
			
		||||
    digitalWrite(LED_BUILTIN, HIGH);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user