mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-05-18 23:38:16 +05:00
refactor: reworking the freeze protection algorithm (#242)
* refactor: impoved freeze protection * refactor: reworked freeze protection
This commit is contained in:
+30
-21
@@ -43,8 +43,6 @@ protected:
|
||||
bool telnetStarted = false;
|
||||
bool emergencyDetected = false;
|
||||
unsigned long emergencyFlipTime = 0;
|
||||
bool freezeDetected = false;
|
||||
unsigned long freezeDetectedTime = 0;
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
const char* getTaskName() override {
|
||||
@@ -243,7 +241,7 @@ protected:
|
||||
|
||||
void heating() {
|
||||
// freeze protection
|
||||
if (!settings.heating.enabled) {
|
||||
{
|
||||
float lowTemp = 255.0f;
|
||||
uint8_t availableSensors = 0;
|
||||
|
||||
@@ -274,29 +272,40 @@ protected:
|
||||
availableSensors++;
|
||||
}
|
||||
|
||||
if (availableSensors && lowTemp <= settings.heating.freezeProtection.lowTemp) {
|
||||
if (!this->freezeDetected) {
|
||||
this->freezeDetected = true;
|
||||
this->freezeDetectedTime = millis();
|
||||
if (availableSensors) {
|
||||
if (vars.master.heating.freezing) {
|
||||
if (lowTemp - (float) settings.heating.freezeProtection.highTemp + 0.0001f >= 0.0f) {
|
||||
vars.master.heating.freezing = false;
|
||||
|
||||
} else if (millis() - this->freezeDetectedTime > (settings.heating.freezeProtection.thresholdTime * 1000)) {
|
||||
this->freezeDetected = false;
|
||||
settings.heating.enabled = true;
|
||||
fsSettings.update();
|
||||
Log.sinfoln(
|
||||
FPSTR(L_MAIN),
|
||||
F("No freezing detected. Current low temp: %.2f, threshold (high): %hhu"),
|
||||
lowTemp, settings.heating.freezeProtection.highTemp
|
||||
);
|
||||
}
|
||||
|
||||
Log.sinfoln(
|
||||
FPSTR(L_MAIN),
|
||||
F("Heating turned on by freeze protection, current low temp: %.2f, threshold: %hhu"),
|
||||
lowTemp, settings.heating.freezeProtection.lowTemp
|
||||
);
|
||||
} else {
|
||||
if ((float) settings.heating.freezeProtection.lowTemp - lowTemp + 0.0001f >= 0.0f) {
|
||||
vars.master.heating.freezing = true;
|
||||
|
||||
if (!settings.heating.enabled) {
|
||||
settings.heating.enabled = true;
|
||||
fsSettings.update();
|
||||
}
|
||||
|
||||
Log.sinfoln(
|
||||
FPSTR(L_MAIN),
|
||||
F("Freezing detected! Current low temp: %.2f, threshold (low): %hhu"),
|
||||
lowTemp, settings.heating.freezeProtection.lowTemp
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (this->freezeDetected) {
|
||||
this->freezeDetected = false;
|
||||
}
|
||||
} else if (vars.master.heating.freezing) {
|
||||
vars.master.heating.freezing = false;
|
||||
|
||||
} else if (this->freezeDetected) {
|
||||
this->freezeDetected = false;
|
||||
Log.sinfoln(FPSTR(L_MAIN), F("No sensors available, freeze protection unavailable!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user