mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-03-20 17:28:37 +05:00
refactor: reworked freeze protection
This commit is contained in:
@@ -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 {
|
||||
@@ -274,14 +272,20 @@ protected:
|
||||
availableSensors++;
|
||||
}
|
||||
|
||||
if (availableSensors && lowTemp <= settings.heating.freezeProtection.lowTemp) {
|
||||
if (!vars.master.heating.freezing) {
|
||||
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;
|
||||
Log.sinfoln(
|
||||
FPSTR(L_MAIN),
|
||||
F("No freezing detected. Current low temp: %.2f, threshold (high): %hhu"),
|
||||
lowTemp, settings.heating.freezeProtection.highTemp
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
if ((float) settings.heating.freezeProtection.lowTemp - lowTemp + 0.0001f >= 0.0f) {
|
||||
vars.master.heating.freezing = true;
|
||||
|
||||
if (!settings.heating.enabled) {
|
||||
@@ -291,26 +295,16 @@ protected:
|
||||
|
||||
Log.sinfoln(
|
||||
FPSTR(L_MAIN),
|
||||
F("Heating turned on by freeze protection, current low temp: %.2f, threshold: %hhu"),
|
||||
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;
|
||||
|
||||
if (vars.master.heating.freezing) {
|
||||
vars.master.heating.freezing = false;
|
||||
|
||||
Log.sinfoln(
|
||||
FPSTR(L_MAIN),
|
||||
F("No freezing detected, current low temp: %.2f, threshold: %hhu"),
|
||||
lowTemp, settings.heating.freezeProtection.lowTemp
|
||||
);
|
||||
}
|
||||
Log.sinfoln(FPSTR(L_MAIN), F("No sensors available, freeze protection unavailable!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ struct Settings {
|
||||
} overheatProtection;
|
||||
|
||||
struct {
|
||||
uint8_t highTemp = 15;
|
||||
uint8_t lowTemp = 10;
|
||||
unsigned short thresholdTime = 600;
|
||||
} freezeProtection;
|
||||
} heating;
|
||||
|
||||
|
||||
23
src/utils.h
23
src/utils.h
@@ -505,8 +505,8 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) {
|
||||
heatingOverheatProtection[FPSTR(S_LOW_TEMP)] = src.heating.overheatProtection.lowTemp;
|
||||
|
||||
auto freezeProtection = heating[FPSTR(S_FREEZE_PROTECTION)].to<JsonObject>();
|
||||
freezeProtection[FPSTR(S_HIGH_TEMP)] = src.heating.freezeProtection.highTemp;
|
||||
freezeProtection[FPSTR(S_LOW_TEMP)] = src.heating.freezeProtection.lowTemp;
|
||||
freezeProtection[FPSTR(S_THRESHOLD_TIME)] = src.heating.freezeProtection.thresholdTime;
|
||||
|
||||
auto dhw = dst[FPSTR(S_DHW)].to<JsonObject>();
|
||||
dhw[FPSTR(S_ENABLED)] = src.dhw.enabled;
|
||||
@@ -1426,6 +1426,15 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (!src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_HIGH_TEMP)].isNull()) {
|
||||
unsigned short value = src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_HIGH_TEMP)].as<uint8_t>();
|
||||
|
||||
if (isValidTemp(value, dst.system.unitSystem, 1, 50) && value != dst.heating.freezeProtection.highTemp) {
|
||||
dst.heating.freezeProtection.highTemp = value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_LOW_TEMP)].isNull()) {
|
||||
unsigned short value = src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_LOW_TEMP)].as<uint8_t>();
|
||||
|
||||
@@ -1435,15 +1444,9 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false
|
||||
}
|
||||
}
|
||||
|
||||
if (!src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_THRESHOLD_TIME)].isNull()) {
|
||||
unsigned short value = src[FPSTR(S_HEATING)][FPSTR(S_FREEZE_PROTECTION)][FPSTR(S_THRESHOLD_TIME)].as<unsigned short>();
|
||||
|
||||
if (value >= 30 && value <= 1800) {
|
||||
if (value != dst.heating.freezeProtection.thresholdTime) {
|
||||
dst.heating.freezeProtection.thresholdTime = value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (dst.heating.freezeProtection.highTemp < dst.heating.freezeProtection.lowTemp) {
|
||||
dst.heating.freezeProtection.highTemp = dst.heating.freezeProtection.lowTemp;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user