new class for managing heating
This commit is contained in:
50
src/Heating.cpp
Normal file
50
src/Heating.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Created by lukas on 10.11.20.
|
||||
//
|
||||
|
||||
#include "Heating.h"
|
||||
#include "Pins.h"
|
||||
|
||||
void Heating::init(Temperature *tempsensor) {
|
||||
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) {
|
||||
// turn off active turnoff timers
|
||||
mLuefterTicker.detach();
|
||||
|
||||
// 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) {
|
||||
// if humidity too low turn off heating and fan after 60secs
|
||||
digitalWrite(HeizungPin, LOW);
|
||||
|
||||
if (!mFanWaiting) {
|
||||
mFanWaiting = true;
|
||||
mLuefterTicker.once(60, []() {
|
||||
// turn off fan
|
||||
digitalWrite(LuefterPin, LOW);
|
||||
Serial.println("turning off fan");
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user