remove unneeded files
use different functions in heater to provide code readability
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 8.7 KiB  | 
@@ -1,12 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
  "name":"ESP8266 React",
 | 
			
		||||
  "icons":[
 | 
			
		||||
    {
 | 
			
		||||
      "src":"/app/icon.png",
 | 
			
		||||
      "sizes":"48x48 72x72 96x96 128x128 256x256"
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  "start_url":"/",
 | 
			
		||||
  "display":"fullscreen",
 | 
			
		||||
  "orientation":"any"
 | 
			
		||||
}
 | 
			
		||||
@@ -1,22 +0,0 @@
 | 
			
		||||
/* Just supporting latin due to size constrains on the esp chip */
 | 
			
		||||
@font-face {
 | 
			
		||||
  font-family: 'Roboto';
 | 
			
		||||
  font-style: normal;
 | 
			
		||||
  font-weight: 300;
 | 
			
		||||
  src: local('Roboto Light'), local('Roboto-Light'), url(../fonts/li.woff2) format('woff2');
 | 
			
		||||
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2212, U+2215;
 | 
			
		||||
}
 | 
			
		||||
@font-face {
 | 
			
		||||
  font-family: 'Roboto';
 | 
			
		||||
  font-style: normal;
 | 
			
		||||
  font-weight: 400;
 | 
			
		||||
  src: local('Roboto'), local('Roboto-Regular'), url(../fonts/re.woff2) format('woff2');
 | 
			
		||||
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2212, U+2215;
 | 
			
		||||
}
 | 
			
		||||
@font-face {
 | 
			
		||||
  font-family: 'Roboto';
 | 
			
		||||
  font-style: normal;
 | 
			
		||||
  font-weight: 500;
 | 
			
		||||
  src: local('Roboto Medium'), local('Roboto-Medium'), url(../fonts/me.woff2) format('woff2');
 | 
			
		||||
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2212, U+2215;
 | 
			
		||||
}
 | 
			
		||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 1.1 KiB  | 
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										135
									
								
								src/Heating.cpp
									
									
									
									
									
								
							
							
						
						
									
										135
									
								
								src/Heating.cpp
									
									
									
									
									
								
							@@ -5,37 +5,21 @@
 | 
			
		||||
#include "Heating.h"
 | 
			
		||||
#include "Pins.h"
 | 
			
		||||
 | 
			
		||||
Heating::Heating() : mHeizungTicker(),
 | 
			
		||||
                     mLuefterTicker(),
 | 
			
		||||
                     mTurnOffTicker(),
 | 
			
		||||
                     msettings(nullptr),
 | 
			
		||||
                     mHeatingStatus(),
 | 
			
		||||
                     lasttemp(0),
 | 
			
		||||
                     lasthum(0),
 | 
			
		||||
                     sensor() {}
 | 
			
		||||
 | 
			
		||||
void Heating::init(unsigned mode, const SettingState *settings) {
 | 
			
		||||
    msettings = settings;
 | 
			
		||||
 | 
			
		||||
void Heating::init(unsigned mode, const SettingState* settings) {
 | 
			
		||||
    switch (mode) {
 | 
			
		||||
        case TIME: {
 | 
			
		||||
            const unsigned percentOn = 20;
 | 
			
		||||
            const unsigned refreshperiod = 900;
 | 
			
		||||
 | 
			
		||||
            const auto func = [this]() {
 | 
			
		||||
                mLuefterTicker.detach();
 | 
			
		||||
 | 
			
		||||
                // every minute turn on the heating
 | 
			
		||||
                digitalWrite(LuefterPin, HIGH);
 | 
			
		||||
                digitalWrite(HeizungPin, HIGH);
 | 
			
		||||
 | 
			
		||||
                Serial.println("Turning on heating");
 | 
			
		||||
 | 
			
		||||
                mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
 | 
			
		||||
                    digitalWrite(HeizungPin, LOW);
 | 
			
		||||
 | 
			
		||||
                    Serial.println("Turned off heating!");
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
                mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
 | 
			
		||||
                    digitalWrite(LuefterPin, LOW);
 | 
			
		||||
 | 
			
		||||
                    Serial.println("Turned off fan!");
 | 
			
		||||
                });
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            func();
 | 
			
		||||
            mHeizungTicker.attach(refreshperiod, func);
 | 
			
		||||
            this->handleTimeHeater();
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        case HUMIDITY:
 | 
			
		||||
@@ -51,31 +35,7 @@ void Heating::init(unsigned mode, const SettingState* settings) {
 | 
			
		||||
                    this->lasttemp = temp;
 | 
			
		||||
                    this->lasthum = hum;
 | 
			
		||||
 | 
			
		||||
                    if (hum > (float)settings->heatUp) {
 | 
			
		||||
                        // turn off active turnoff timers
 | 
			
		||||
                        mLuefterTicker.detach();
 | 
			
		||||
                        Serial.println("heating should run now!");
 | 
			
		||||
                        // turn on heating and fan
 | 
			
		||||
                        digitalWrite(LuefterPin, HIGH);
 | 
			
		||||
                        digitalWrite(HeizungPin, HIGH);
 | 
			
		||||
                        mHeatingStatus = true;
 | 
			
		||||
                    } else if (hum < (float)settings->heatLow) {
 | 
			
		||||
                        // if humidity too low turn off heating and fan after 60secs
 | 
			
		||||
                        digitalWrite(HeizungPin, LOW);
 | 
			
		||||
                        Serial.println("heating should NOT run now!");
 | 
			
		||||
 | 
			
		||||
                        // if heating status in on set ticker to turn of fan in 60sec
 | 
			
		||||
                        if (mHeatingStatus) {
 | 
			
		||||
                            mLuefterTicker.once((float)settings->fanRuntime, []() {
 | 
			
		||||
                                // turn off fan
 | 
			
		||||
                                digitalWrite(LuefterPin, LOW);
 | 
			
		||||
                                schedule_function([]() {
 | 
			
		||||
                                    Serial.println("turning off fan");
 | 
			
		||||
                                });
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                        mHeatingStatus = false;
 | 
			
		||||
                    }
 | 
			
		||||
                    this->handleHeatingEvents();
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
@@ -83,6 +43,11 @@ void Heating::init(unsigned mode, const SettingState* settings) {
 | 
			
		||||
                this->lasttemp = -1.0;
 | 
			
		||||
                this->lasthum = -1.0;
 | 
			
		||||
 | 
			
		||||
                // emergency turnoff of heating
 | 
			
		||||
                if(mHeatingStatus){
 | 
			
		||||
                    digitalWrite(HeizungPin, LOW);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                schedule_function([e]() {
 | 
			
		||||
                    Serial.printf("Error: %d\n", e);
 | 
			
		||||
                });
 | 
			
		||||
@@ -106,10 +71,60 @@ float *Heating::getLastHum() {
 | 
			
		||||
    return &lasthum;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Heating::Heating() : mHeizungTicker(),
 | 
			
		||||
                     mLuefterTicker(),
 | 
			
		||||
                     mTurnOffTicker(),
 | 
			
		||||
                     mHeatingStatus(),
 | 
			
		||||
                     lasttemp(0),
 | 
			
		||||
                     lasthum(0),
 | 
			
		||||
                     sensor() {}
 | 
			
		||||
void Heating::handleHeatingEvents() {
 | 
			
		||||
    if (this->lasthum > (float) msettings->heatUp) {
 | 
			
		||||
        // turn off active turnoff timers
 | 
			
		||||
        mLuefterTicker.detach();
 | 
			
		||||
        Serial.println("heating should run now!");
 | 
			
		||||
        // turn on heating and fan
 | 
			
		||||
        digitalWrite(LuefterPin, HIGH);
 | 
			
		||||
        digitalWrite(HeizungPin, HIGH);
 | 
			
		||||
        mHeatingStatus = true;
 | 
			
		||||
    } else if (this->lasthum < (float) msettings->heatLow) {
 | 
			
		||||
        // if humidity too low turn off heating and fan after 60secs
 | 
			
		||||
        digitalWrite(HeizungPin, LOW);
 | 
			
		||||
        Serial.println("heating should NOT run now!");
 | 
			
		||||
 | 
			
		||||
        // if heating status in on set ticker to turn of fan in 60sec
 | 
			
		||||
        if (mHeatingStatus) {
 | 
			
		||||
            mLuefterTicker.once((float) msettings->fanRuntime, []() {
 | 
			
		||||
                // turn off fan
 | 
			
		||||
                digitalWrite(LuefterPin, LOW);
 | 
			
		||||
                schedule_function([]() {
 | 
			
		||||
                    Serial.println("turning off fan");
 | 
			
		||||
                });
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
        mHeatingStatus = false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Heating::handleTimeHeater() {
 | 
			
		||||
    const unsigned percentOn = 20;
 | 
			
		||||
    const unsigned refreshperiod = 900;
 | 
			
		||||
 | 
			
		||||
    const auto func = [this]() {
 | 
			
		||||
        mLuefterTicker.detach();
 | 
			
		||||
 | 
			
		||||
        // every minute turn on the heating
 | 
			
		||||
        digitalWrite(LuefterPin, HIGH);
 | 
			
		||||
        digitalWrite(HeizungPin, HIGH);
 | 
			
		||||
 | 
			
		||||
        Serial.println("Turning on heating");
 | 
			
		||||
 | 
			
		||||
        mTurnOffTicker.once((int) ((float) refreshperiod * (float) percentOn / 100.0), []() {
 | 
			
		||||
            digitalWrite(HeizungPin, LOW);
 | 
			
		||||
 | 
			
		||||
            Serial.println("Turned off heating!");
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        mLuefterTicker.once((int) (((float) refreshperiod * (float) percentOn / 100.0) + 30.0), []() {
 | 
			
		||||
            digitalWrite(LuefterPin, LOW);
 | 
			
		||||
 | 
			
		||||
            Serial.println("Turned off fan!");
 | 
			
		||||
        });
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    func();
 | 
			
		||||
    mHeizungTicker.attach(refreshperiod, func);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -13,9 +13,23 @@ class Heating {
 | 
			
		||||
public:
 | 
			
		||||
    Heating();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * initialize the heater
 | 
			
		||||
     * @param mode select the operating mode
 | 
			
		||||
     * @param settings a settings object is needed for HUMIDITY mode to get percent values set by user
 | 
			
		||||
     */
 | 
			
		||||
    void init(unsigned mode, const SettingState* settings);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * get the last captured humidity value
 | 
			
		||||
     * @return humidity value
 | 
			
		||||
     */
 | 
			
		||||
    float* getLastHum();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * get the last captured temperature value
 | 
			
		||||
     * @return temperature value
 | 
			
		||||
     */
 | 
			
		||||
    float* getLastTemp();
 | 
			
		||||
 | 
			
		||||
    enum MODES {TIME, HUMIDITY};
 | 
			
		||||
@@ -24,10 +38,25 @@ private:
 | 
			
		||||
    Ticker mLuefterTicker;
 | 
			
		||||
    Ticker mTurnOffTicker;
 | 
			
		||||
 | 
			
		||||
    const SettingState* msettings;
 | 
			
		||||
 | 
			
		||||
    bool mHeatingStatus;
 | 
			
		||||
 | 
			
		||||
    float lasttemp;
 | 
			
		||||
    float lasthum;
 | 
			
		||||
 | 
			
		||||
    DHT22 sensor;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * handle events after successfully received a humidity value
 | 
			
		||||
     * - turn on/off of heating
 | 
			
		||||
     * - afterrun of fan
 | 
			
		||||
     */
 | 
			
		||||
    void handleHeatingEvents();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * handle events for time-heating mode
 | 
			
		||||
     * when to turn on/off heating + fan
 | 
			
		||||
     */
 | 
			
		||||
    void handleTimeHeater();
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,6 @@
 | 
			
		||||
#define TempSensorPin  D4
 | 
			
		||||
 | 
			
		||||
// version info
 | 
			
		||||
#define VERSION "v1.2.0"
 | 
			
		||||
#define VERSION "v1.2.1"
 | 
			
		||||
 | 
			
		||||
#endif //PUMPENSTEUERUNG_PINS_H
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user