two modes if no humidity sensor available

This commit is contained in:
Lukas Heiligenbrunner 2020-11-17 15:26:17 +01:00
parent 92e7089aef
commit 4a7a929dbc
3 changed files with 78 additions and 39 deletions

View File

@ -5,7 +5,39 @@
#include "Heating.h"
#include "Pins.h"
void Heating::init(Temperature *tempsensor) {
void Heating::init(Temperature *tempsensor, unsigned mode) {
switch (mode) {
case TIME: {
const unsigned percentOn = 20;
const unsigned refreshperiod = 60;
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(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]() {
@ -47,4 +79,8 @@ void Heating::init(Temperature *tempsensor) {
}
});
});
break;
default:
break;
}
}

View File

@ -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;
};

View File

@ -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);