refactor: improved freeze protection & overheat protection; added desc for OT options

This commit is contained in:
Yurii
2025-06-30 02:41:44 +03:00
parent 792c6a6668
commit e63a0dc7eb
9 changed files with 299 additions and 193 deletions

View File

@@ -29,6 +29,7 @@ protected:
enum class PumpStartReason {NONE, HEATING, ANTISTUCK};
Blinker* blinker = nullptr;
unsigned long miscRunned = 0;
unsigned long lastHeapInfo = 0;
unsigned int minFreeHeap = 0;
unsigned int minMaxFreeBlockHeap = 0;
@@ -42,6 +43,8 @@ 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 {
@@ -150,18 +153,16 @@ protected:
Sensors::setConnectionStatusByType(Sensors::Type::MANUAL, false, false);
}
this->yield();
this->heating();
this->emergency();
this->yield();
if (this->misc()) {
this->yield();
}
this->ledStatus();
this->cascadeControl();
this->externalPump();
this->yield();
// telnet
if (this->telnetStarted) {
this->yield();
telnetStream->loop();
this->yield();
}
@@ -180,14 +181,27 @@ protected:
// heap info
this->heap();
}
bool misc() {
if (millis() - this->miscRunned < 1000) {
return false;
}
// restart
// restart if required
if (this->restartSignalReceived && millis() - this->restartSignalReceivedTime > 15000) {
this->restartSignalReceived = false;
ESP.restart();
}
this->heating();
this->emergency();
this->cascadeControl();
this->externalPump();
this->miscRunned = millis();
return true;
}
void heap() {
@@ -230,15 +244,15 @@ protected:
}
void heating() {
// anti freeze protection
// freeze protection
if (!settings.heating.enabled) {
float minTemp = 255.0f;
float lowTemp = 255.0f;
uint8_t availableSensors = 0;
if (Sensors::existsConnectedSensorsByPurpose(Sensors::Purpose::INDOOR_TEMP)) {
auto value = Sensors::getMeanValueByPurpose(Sensors::Purpose::INDOOR_TEMP, Sensors::ValueType::PRIMARY);
if (value < minTemp) {
minTemp = value;
if (value < lowTemp) {
lowTemp = value;
}
availableSensors++;
@@ -246,8 +260,8 @@ protected:
if (Sensors::existsConnectedSensorsByPurpose(Sensors::Purpose::HEATING_TEMP)) {
auto value = Sensors::getMeanValueByPurpose(Sensors::Purpose::HEATING_TEMP, Sensors::ValueType::PRIMARY);
if (value < minTemp) {
minTemp = value;
if (value < lowTemp) {
lowTemp = value;
}
availableSensors++;
@@ -255,23 +269,36 @@ protected:
if (Sensors::existsConnectedSensorsByPurpose(Sensors::Purpose::HEATING_RETURN_TEMP)) {
auto value = Sensors::getMeanValueByPurpose(Sensors::Purpose::HEATING_RETURN_TEMP, Sensors::ValueType::PRIMARY);
if (value < minTemp) {
minTemp = value;
if (value < lowTemp) {
lowTemp = value;
}
availableSensors++;
}
if (availableSensors && minTemp <= settings.heating.antiFreezeTemp) {
settings.heating.enabled = true;
fsSettings.update();
if (availableSensors && lowTemp <= settings.heating.freezeProtection.lowTemp) {
if (!this->freezeDetected) {
this->freezeDetected = true;
this->freezeDetectedTime = millis();
Log.sinfoln(
FPSTR(L_MAIN),
F("Heating turned on by anti freeze protection, current min temp: %.2f, threshold: %hhu"),
minTemp, settings.heating.antiFreezeTemp
);
} 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("Heating turned on by freeze protection, current low temp: %.2f, threshold: %hhu"),
lowTemp, settings.heating.freezeProtection.lowTemp
);
}
} else if (this->freezeDetected) {
this->freezeDetected = false;
}
} else if (this->freezeDetected) {
this->freezeDetected = false;
}
}