mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-25 07:43:04 +05:00
refactor: simplify conditions and standardize formatting
This commit is contained in:
1 parent
d1a44de0df
commit
1d1a57ecad
9 files changed
+212
-187
No files matched your search
+44
-5
@@ -111,17 +111,56 @@ request
|
|||||||
vars.master.heating.enabled, settings.opentherm.heatingDisablingAction
|
vars.master.heating.enabled, settings.opentherm.heatingDisablingAction
|
||||||
))
|
))
|
||||||
.setHotWaterEnabled(
|
.setHotWaterEnabled(
|
||||||
settings.opentherm.options.dhwSupport &&
|
settings.opentherm.options.dhwSupport
|
||||||
getSlaveChannelEnabled(vars.master.dhw.enabled, settings.opentherm.dhwDisablingAction)
|
&& getSlaveChannelEnabled(vars.master.dhw.enabled, settings.opentherm.dhwDisablingAction)
|
||||||
)
|
)
|
||||||
.setCoolingEnabled(settings.opentherm.options.coolingSupport)
|
.setCoolingEnabled(settings.opentherm.options.coolingSupport)
|
||||||
.setDhwBlocking(dhwBlocking);
|
.setDhwBlocking(dhwBlocking);
|
||||||
```
|
```
|
||||||
|
|
||||||
Не считай это общим требованием переносить имя объекта перед любой цепочкой.
|
Не считай это общим требованием переносить имя объекта перед любой цепочкой.
|
||||||
В многострочных условиях сохраняй принятую рядом расстановку `&&` и `||`:
|
В многострочных логических условиях ставь `&&` и `||` в начале строки
|
||||||
в проекте встречаются оба варианта переноса. Группируй связанные условия
|
продолжения. Для `if`/`else if` отступ продолжения — четыре пробела
|
||||||
скобками и не меняй их порядок или приоритет ради выравнивания.
|
от начала исходной строки. Если первый операнд уже вынесен на отдельную строку
|
||||||
|
внутри аргумента вызова или группы в скобках, следующие строки с `&&`/`||`
|
||||||
|
выравнивай по нему без дополнительных
|
||||||
|
двух пробелов. Группируй связанные условия скобками и не меняй их порядок
|
||||||
|
или приоритет ради выравнивания.
|
||||||
|
|
||||||
|
В многострочных `return` ставь `&&` и `||` в конце предыдущей строки,
|
||||||
|
а продолжение выравнивай под началом выражения после `return`.
|
||||||
|
Во вложенных группах также выравнивай операнды по первому выражению группы.
|
||||||
|
|
||||||
|
В многострочных логических присваиваниях также оставляй `&&` и `||` в конце
|
||||||
|
предыдущей строки, а продолжение выравнивай под началом правой части.
|
||||||
|
При длинном типе или имени переменной переноси правую часть целиком после `=`:
|
||||||
|
её базовый отступ — четыре пробела от начала объявления.
|
||||||
|
|
||||||
|
Простые условия из нескольких коротких проверок оставляй на одной строке.
|
||||||
|
Несколько `&&`/`||` сами по себе не требуют переноса; разбивай выражение,
|
||||||
|
когда это помогает читать длинные или сложные условия.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
if (!response.isSuccess() || response.getRequestCode() != 10 || response.getResponseCode() < 128) {
|
||||||
|
ESP_LOGE(L_OT, "Boiler diagnostic reset failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return settings.mqtt.enabled && isNetworkConnected() && !isMqttBlocked() &&
|
||||||
|
!mqttConfigureTask.scheduled() && isMqttConnected();
|
||||||
|
|
||||||
|
const bool hasOutput = activeSerial.load(std::memory_order_relaxed) ||
|
||||||
|
activeWebSerial.load(std::memory_order_relaxed);
|
||||||
|
|
||||||
|
const bool hasOutput =
|
||||||
|
activeSerial.load(std::memory_order_relaxed) ||
|
||||||
|
activeWebSerial.load(std::memory_order_relaxed);
|
||||||
|
|
||||||
|
if (prevSettings && Sensors::hasEnabledAndValid(*prevSettings)
|
||||||
|
&& (metadataChanged || !settings.mqtt.homeAssistantDiscovery)) {
|
||||||
|
deleteConnectionDynamicSensor(*prevSettings);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Имена и структура файлов
|
## Имена и структура файлов
|
||||||
|
|
||||||
|
|||||||
+15
-15
@@ -193,24 +193,24 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool isDifferent(const Settings& previous, const Settings& current) {
|
static bool isDifferent(const Settings& previous, const Settings& current) {
|
||||||
return previous.enabled != current.enabled
|
return previous.enabled != current.enabled ||
|
||||||
|| strcmp(previous.name, current.name) != 0
|
strcmp(previous.name, current.name) != 0 ||
|
||||||
|| strcmp(previous.slug, current.slug) != 0
|
strcmp(previous.slug, current.slug) != 0 ||
|
||||||
|| previous.purpose != current.purpose
|
previous.purpose != current.purpose ||
|
||||||
|| previous.type != current.type
|
previous.type != current.type ||
|
||||||
|| previous.gpio != current.gpio
|
previous.gpio != current.gpio ||
|
||||||
|| !isEqualAddress(previous.address, current.address)
|
!isEqualAddress(previous.address, current.address) ||
|
||||||
|| isFloatDifferent(previous.offset, current.offset, 0.0001f)
|
isFloatDifferent(previous.offset, current.offset, 0.0001f) ||
|
||||||
|| isFloatDifferent(previous.factor, current.factor, 0.0001f)
|
isFloatDifferent(previous.factor, current.factor, 0.0001f) ||
|
||||||
|| previous.filtering != current.filtering
|
previous.filtering != current.filtering ||
|
||||||
|| isFloatDifferent(previous.filteringFactor, current.filteringFactor, 0.0001f);
|
isFloatDifferent(previous.filteringFactor, current.filteringFactor, 0.0001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hasEnabledAndValid(const Settings& sensor) {
|
static bool hasEnabledAndValid(const Settings& sensor) {
|
||||||
return sensor.enabled
|
return sensor.enabled &&
|
||||||
&& sensor.slug[0] != '\0'
|
sensor.slug[0] != '\0' &&
|
||||||
&& sensor.type != Type::NOT_CONFIGURED
|
sensor.type != Type::NOT_CONFIGURED &&
|
||||||
&& sensor.purpose != Purpose::NOT_CONFIGURED;
|
sensor.purpose != Purpose::NOT_CONFIGURED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hasEnabledAndValid(const uint8_t id) {
|
static bool hasEnabledAndValid(const uint8_t id) {
|
||||||
|
|||||||
+18
-15
@@ -1571,9 +1571,7 @@ static SettingResult applySetting(HeatingSettings& dst, std::string_view path, f
|
|||||||
|
|
||||||
unsigned char value = static_cast<unsigned char>(input);
|
unsigned char value = static_cast<unsigned char>(input);
|
||||||
|
|
||||||
if (value < vars.slave.heating.minTemp
|
if (value < vars.slave.heating.minTemp || value >= vars.slave.heating.maxTemp || value == dst.maxTemp) {
|
||||||
|| value >= vars.slave.heating.maxTemp
|
|
||||||
|| value == dst.maxTemp) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1594,9 +1592,7 @@ static SettingResult applySetting(HeatingSettings& dst, std::string_view path, f
|
|||||||
|
|
||||||
unsigned char value = static_cast<unsigned char>(input);
|
unsigned char value = static_cast<unsigned char>(input);
|
||||||
|
|
||||||
if (value <= vars.slave.heating.minTemp
|
if (value <= vars.slave.heating.minTemp || value > vars.slave.heating.maxTemp || value == dst.minTemp) {
|
||||||
|| value > vars.slave.heating.maxTemp
|
|
||||||
|| value == dst.minTemp) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1999,8 +1995,7 @@ static SettingResult applySetting(DhwSettings& dst, std::string_view path, float
|
|||||||
|
|
||||||
unsigned char value = static_cast<unsigned char>(input);
|
unsigned char value = static_cast<unsigned char>(input);
|
||||||
|
|
||||||
if (value < vars.slave.dhw.minTemp
|
if (value < vars.slave.dhw.minTemp || value >= vars.slave.dhw.maxTemp) {
|
||||||
|| value >= vars.slave.dhw.maxTemp) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2021,8 +2016,7 @@ static SettingResult applySetting(DhwSettings& dst, std::string_view path, float
|
|||||||
|
|
||||||
unsigned char value = static_cast<unsigned char>(input);
|
unsigned char value = static_cast<unsigned char>(input);
|
||||||
|
|
||||||
if (value <= vars.slave.dhw.minTemp
|
if (value <= vars.slave.dhw.minTemp || value > vars.slave.dhw.maxTemp) {
|
||||||
|| value > vars.slave.dhw.maxTemp) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3310,8 +3304,8 @@ SettingResult fromJson(const JsonVariantConst src, Sensors::Settings& dst) {
|
|||||||
|
|
||||||
// gpio
|
// gpio
|
||||||
if (!src[S_GPIO].isNull()) {
|
if (!src[S_GPIO].isNull()) {
|
||||||
if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type != Sensors::Type::NTC_10K_TEMP &&
|
if (dst.type != Sensors::Type::DALLAS_TEMP && dst.type != Sensors::Type::NTC_10K_TEMP
|
||||||
dst.type != Sensors::Type::DHT11 && dst.type != Sensors::Type::DHT22) {
|
&& dst.type != Sensors::Type::DHT11 && dst.type != Sensors::Type::DHT22) {
|
||||||
if (dst.gpio != GPIO_IS_NOT_CONFIGURED) {
|
if (dst.gpio != GPIO_IS_NOT_CONFIGURED) {
|
||||||
dst.gpio = GPIO_IS_NOT_CONFIGURED;
|
dst.gpio = GPIO_IS_NOT_CONFIGURED;
|
||||||
result.changed = true;
|
result.changed = true;
|
||||||
@@ -3327,9 +3321,18 @@ SettingResult fromJson(const JsonVariantConst src, Sensors::Settings& dst) {
|
|||||||
} else if (src[S_GPIO].is<uint8_t>()) {
|
} else if (src[S_GPIO].is<uint8_t>()) {
|
||||||
const auto value = src[S_GPIO].as<uint8_t>();
|
const auto value = src[S_GPIO].as<uint8_t>();
|
||||||
|
|
||||||
if (value == GPIO_IS_NOT_CONFIGURED
|
bool valid = false;
|
||||||
|| (GPIO_IS_VALID_INPUT(value)
|
if (value == GPIO_IS_NOT_CONFIGURED) {
|
||||||
&& (dst.type == Sensors::Type::NTC_10K_TEMP || GPIO_IS_VALID_OUTPUT(value)))) {
|
valid = true;
|
||||||
|
|
||||||
|
} else if (dst.type == Sensors::Type::NTC_10K_TEMP) {
|
||||||
|
valid = GPIO_IS_VALID_INPUT(value);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
valid = GPIO_IS_VALID_INPUT(value) && GPIO_IS_VALID_OUTPUT(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valid) {
|
||||||
result.accepted = true;
|
result.accepted = true;
|
||||||
if (value != dst.gpio) {
|
if (value != dst.gpio) {
|
||||||
dst.gpio = value;
|
dst.gpio = value;
|
||||||
|
|||||||
+13
-15
@@ -58,8 +58,8 @@ static bool isMqttBlocked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool isMqttReady() {
|
static bool isMqttReady() {
|
||||||
return settings.mqtt.enabled && isNetworkConnected() && !isMqttBlocked()
|
return settings.mqtt.enabled && isNetworkConnected() && !isMqttBlocked() &&
|
||||||
&& !mqttConfigureTask.scheduled() && isMqttConnected();
|
!mqttConfigureTask.scheduled() && isMqttConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isMqttReadyForPublish() {
|
static bool isMqttReadyForPublish() {
|
||||||
@@ -241,7 +241,6 @@ static void publishSlaveState() {
|
|||||||
publishValue(mqttTopic("state/slave/fault/available"), vars.slave.connected && vars.slave.fault.active);
|
publishValue(mqttTopic("state/slave/fault/available"), vars.slave.connected && vars.slave.fault.active);
|
||||||
publishValue(mqttTopic("state/slave/diag/active"), vars.slave.diag.active);
|
publishValue(mqttTopic("state/slave/diag/active"), vars.slave.diag.active);
|
||||||
publishValue(mqttTopic("state/slave/diag/code"), std::to_string(vars.slave.diag.code));
|
publishValue(mqttTopic("state/slave/diag/code"), std::to_string(vars.slave.diag.code));
|
||||||
// Preserve the diagnostic-code availability condition from async.
|
|
||||||
publishValue(mqttTopic("state/slave/diag/available"), (vars.slave.connected && vars.slave.fault.active) || vars.slave.diag.active);
|
publishValue(mqttTopic("state/slave/diag/available"), (vars.slave.connected && vars.slave.fault.active) || vars.slave.diag.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,8 +548,7 @@ static float mqttValueToMetric(std::string_view path, float value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto name = path.substr(path.find_last_of('/') + 1);
|
const auto name = path.substr(path.find_last_of('/') + 1);
|
||||||
if (name == S_TARGET || name == S_MIN_TEMP || name == S_MAX_TEMP
|
if (name == S_TARGET || name == S_MIN_TEMP || name == S_MAX_TEMP || name == S_HIGH_TEMP || name == S_LOW_TEMP) {
|
||||||
|| name == S_HIGH_TEMP || name == S_LOW_TEMP) {
|
|
||||||
return convertTemp(value, settings.system.unitSystem, UnitSystem::METRIC);
|
return convertTemp(value, settings.system.unitSystem, UnitSystem::METRIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -954,14 +952,14 @@ Task mqttConfigureTask("Configure MQTT", Task::Type::ONCE, [](void*) {
|
|||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
const auto& [sensorId, prevSettings] = change;
|
const auto& [sensorId, prevSettings] = change;
|
||||||
const bool metadataChanged = prevSettings && (
|
const bool metadataChanged =
|
||||||
!sensor
|
prevSettings &&
|
||||||
|| prevSettings->enabled != sensor->enabled
|
(!sensor ||
|
||||||
|| strcmp(prevSettings->name, sensor->name) != 0
|
prevSettings->enabled != sensor->enabled ||
|
||||||
|| strcmp(prevSettings->slug, sensor->slug) != 0
|
strcmp(prevSettings->name, sensor->name) != 0 ||
|
||||||
|| prevSettings->purpose != sensor->purpose
|
strcmp(prevSettings->slug, sensor->slug) != 0 ||
|
||||||
|| prevSettings->type != sensor->type
|
prevSettings->purpose != sensor->purpose ||
|
||||||
);
|
prevSettings->type != sensor->type);
|
||||||
|
|
||||||
// Metadata changes replace entities; disabling discovery removes them.
|
// Metadata changes replace entities; disabling discovery removes them.
|
||||||
if (prevSettings && Sensors::hasEnabledAndValid(*prevSettings)
|
if (prevSettings && Sensors::hasEnabledAndValid(*prevSettings)
|
||||||
@@ -995,8 +993,8 @@ Task mqttConfigureTask("Configure MQTT", Task::Type::ONCE, [](void*) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (settings.mqtt.homeAssistantDiscovery && sensor && Sensors::hasEnabledAndValid(*sensor)) {
|
if (settings.mqtt.homeAssistantDiscovery && sensor && Sensors::hasEnabledAndValid(*sensor)) {
|
||||||
if (sensor->type == Sensors::Type::BLUETOOTH || sensor->type == Sensors::Type::DALLAS_TEMP ||
|
if (sensor->type == Sensors::Type::BLUETOOTH || sensor->type == Sensors::Type::DALLAS_TEMP
|
||||||
sensor->type == Sensors::Type::DHT11 || sensor->type == Sensors::Type::DHT22) {
|
|| sensor->type == Sensors::Type::DHT11 || sensor->type == Sensors::Type::DHT22) {
|
||||||
publishConnectionDynamicSensor(*sensor);
|
publishConnectionDynamicSensor(*sensor);
|
||||||
publishSignalQualityDynamicSensor(*sensor);
|
publishSignalQualityDynamicSensor(*sensor);
|
||||||
|
|
||||||
|
|||||||
+17
-19
@@ -118,8 +118,8 @@ NetworkState getNetworkState(NetworkMode mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isNetworkConnected() {
|
bool isNetworkConnected() {
|
||||||
return getNetworkState(NetworkMode::STA) == NetworkState::NETWORK_CONNECTED
|
return getNetworkState(NetworkMode::STA) == NetworkState::NETWORK_CONNECTED ||
|
||||||
|| getNetworkState(NetworkMode::ETH) == NetworkState::NETWORK_CONNECTED;
|
getNetworkState(NetworkMode::ETH) == NetworkState::NETWORK_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkMode getNetworkMode() {
|
NetworkMode getNetworkMode() {
|
||||||
@@ -186,13 +186,14 @@ String getNetworkMac() {
|
|||||||
bool isEthernetConfigured(const NetworkSettings& config) {
|
bool isEthernetConfigured(const NetworkSettings& config) {
|
||||||
#if USE_ETHERNET
|
#if USE_ETHERNET
|
||||||
const auto& gpios = config.ethernet.w5500;
|
const auto& gpios = config.ethernet.w5500;
|
||||||
return config.ethernet.type == EthernetType::W5500
|
|
||||||
&& GPIO_IS_VALID_OUTPUT(gpios.clk)
|
return config.ethernet.type == EthernetType::W5500 &&
|
||||||
&& GPIO_IS_VALID_OUTPUT(gpios.mosi)
|
GPIO_IS_VALID_OUTPUT(gpios.clk) &&
|
||||||
&& GPIO_IS_VALID_INPUT(gpios.miso)
|
GPIO_IS_VALID_OUTPUT(gpios.mosi) &&
|
||||||
&& GPIO_IS_VALID_OUTPUT(gpios.cs)
|
GPIO_IS_VALID_INPUT(gpios.miso) &&
|
||||||
&& GPIO_IS_VALID_INPUT(gpios.irq)
|
GPIO_IS_VALID_OUTPUT(gpios.cs) &&
|
||||||
&& GPIO_IS_VALID_OUTPUT(gpios.rst);
|
GPIO_IS_VALID_INPUT(gpios.irq) &&
|
||||||
|
GPIO_IS_VALID_OUTPUT(gpios.rst);
|
||||||
#else
|
#else
|
||||||
(void)config;
|
(void)config;
|
||||||
return false;
|
return false;
|
||||||
@@ -706,13 +707,8 @@ static void stopMdns() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void updateNetworkServices() {
|
static void updateNetworkServices() {
|
||||||
const bool ready = webServerReady;
|
|
||||||
|
|
||||||
// Serve captive DNS only while HTTP is ready and no upstream connection exists.
|
// Serve captive DNS only while HTTP is ready and no upstream connection exists.
|
||||||
const bool captive = ready
|
const bool captive = webServerReady && apStarted.load() && apIp && !isNetworkConnected();
|
||||||
&& apStarted.load()
|
|
||||||
&& apIp
|
|
||||||
&& !isNetworkConnected();
|
|
||||||
|
|
||||||
if (!captive) {
|
if (!captive) {
|
||||||
stopCaptiveDns(isNetworkConnected());
|
stopCaptiveDns(isNetworkConnected());
|
||||||
@@ -735,7 +731,7 @@ static void updateNetworkServices() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mDNS tracks native interface/IP events without restarting the responder.
|
// mDNS tracks native interface/IP events without restarting the responder.
|
||||||
const bool enableMdns = ready && settings.portal.mdns;
|
const bool enableMdns = webServerReady && settings.portal.mdns;
|
||||||
|
|
||||||
if (!enableMdns) {
|
if (!enableMdns) {
|
||||||
stopMdns();
|
stopMdns();
|
||||||
@@ -879,9 +875,11 @@ static void processNetworkEvent(const PendingNetworkEvent& pending) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NetworkEvent::ETH_GOT_IP:
|
case NetworkEvent::ETH_GOT_IP:
|
||||||
if (!ethStarted.load() || networkSettings.type != NetworkMode::ETH
|
if (!ethStarted.load() || networkSettings.type != NetworkMode::ETH) {
|
||||||
|| !pending.value || !ETH.connected() || !ETH.hasIP()
|
return;
|
||||||
) {
|
}
|
||||||
|
|
||||||
|
if (!pending.value || !ETH.connected() || !ETH.hasIP()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+79
-90
@@ -33,10 +33,9 @@ static std::atomic<uint8_t> configuredRxLedGpio{GPIO_IS_NOT_CONFIGURED};
|
|||||||
|
|
||||||
|
|
||||||
static bool canUseBus() {
|
static bool canUseBus() {
|
||||||
return !restartTask.scheduled()
|
return !restartTask.scheduled() && slave.isInitialized() &&
|
||||||
&& slave.isInitialized()
|
slave.getConfig().rxGpio == settings.opentherm.inGpio &&
|
||||||
&& slave.getConfig().rxGpio == settings.opentherm.inGpio
|
slave.getConfig().txGpio == settings.opentherm.outGpio;
|
||||||
&& slave.getConfig().txGpio == settings.opentherm.outGpio;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isMasterReady() {
|
static bool isMasterReady() {
|
||||||
@@ -86,33 +85,33 @@ static float getCh2ChannelSetpoint() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool needWriteRoomSetpoint(const float target) {
|
static bool needWriteRoomSetpoint(const float target) {
|
||||||
return !roomSetpointWriteTime
|
return !roomSetpointWriteTime ||
|
||||||
|| millis() - roomSetpointWriteTime > roomSetpointWriteInterval
|
millis() - roomSetpointWriteTime > roomSetpointWriteInterval ||
|
||||||
|| isFloatDifferent(target, vars.slave.heating.roomTargetTemp, 0.05f);
|
isFloatDifferent(target, vars.slave.heating.roomTargetTemp, 0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool needWriteRoomSetpointCh2(const float target) {
|
static bool needWriteRoomSetpointCh2(const float target) {
|
||||||
return !ch2RoomSetpointWriteTime
|
return !ch2RoomSetpointWriteTime ||
|
||||||
|| millis() - ch2RoomSetpointWriteTime > roomSetpointWriteInterval
|
millis() - ch2RoomSetpointWriteTime > roomSetpointWriteInterval ||
|
||||||
|| isFloatDifferent(target, vars.slave.ch2.roomTargetTemp, 0.05f);
|
isFloatDifferent(target, vars.slave.ch2.roomTargetTemp, 0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool needWriteDhwSetpoint(const float target) {
|
static bool needWriteDhwSetpoint(const float target) {
|
||||||
return !dhwSetpointWriteTime
|
return !dhwSetpointWriteTime ||
|
||||||
|| millis() - dhwSetpointWriteTime > dhwSetpointWriteInterval
|
millis() - dhwSetpointWriteTime > dhwSetpointWriteInterval ||
|
||||||
|| isFloatDifferent(target, vars.slave.dhw.targetTemp, 0.05f);
|
isFloatDifferent(target, vars.slave.dhw.targetTemp, 0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool needWriteHeatingSetpoint(const float target) {
|
static bool needWriteHeatingSetpoint(const float target) {
|
||||||
return !heatingSetpointWriteTime
|
return !heatingSetpointWriteTime ||
|
||||||
|| millis() - heatingSetpointWriteTime > heatingSetpointWriteInterval
|
millis() - heatingSetpointWriteTime > heatingSetpointWriteInterval ||
|
||||||
|| isFloatDifferent(target, vars.slave.heating.targetTemp, 0.05f);
|
isFloatDifferent(target, vars.slave.heating.targetTemp, 0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool needWriteCh2Setpoint(const float target) {
|
static bool needWriteCh2Setpoint(const float target) {
|
||||||
return !ch2SetpointWriteTime
|
return !ch2SetpointWriteTime ||
|
||||||
|| millis() - ch2SetpointWriteTime > ch2SetpointWriteInterval
|
millis() - ch2SetpointWriteTime > ch2SetpointWriteInterval ||
|
||||||
|| isFloatDifferent(target, vars.slave.ch2.targetTemp, 0.05f);
|
isFloatDifferent(target, vars.slave.ch2.targetTemp, 0.05f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ONCE identification steps keep their own callbacks and completion handling.
|
// ONCE identification steps keep their own callbacks and completion handling.
|
||||||
@@ -143,9 +142,7 @@ static Task writeMasterVersionTask("Write master version", Task::Type::ONCE, [](
|
|||||||
);
|
);
|
||||||
const auto response = slave.sendRequest(request);
|
const auto response = slave.sendRequest(request);
|
||||||
|
|
||||||
if (!response.isSuccess() ||
|
if (!response.isSuccess() || response.getVersion() != request.getVersion() || response.getProductType() != request.getProductType()) {
|
||||||
response.getVersion() != request.getVersion() ||
|
|
||||||
response.getProductType() != request.getProductType()) {
|
|
||||||
ESP_LOGW(L_OT, "Failed set master version");
|
ESP_LOGW(L_OT, "Failed set master version");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -312,22 +309,25 @@ static bool isInitializingSlave() {
|
|||||||
|
|
||||||
static void updateMasterState() {
|
static void updateMasterState() {
|
||||||
// Heating settings
|
// Heating settings
|
||||||
vars.master.heating.enabled = isMasterReady()
|
vars.master.heating.enabled =
|
||||||
&& settings.heating.enabled
|
isMasterReady() &&
|
||||||
&& (vars.master.heating.freezing || (vars.cascadeControl.input && !vars.master.heating.blocking))
|
settings.heating.enabled &&
|
||||||
&& !vars.master.heating.overheat;
|
(vars.master.heating.freezing || (vars.cascadeControl.input && !vars.master.heating.blocking)) &&
|
||||||
|
!vars.master.heating.overheat;
|
||||||
|
|
||||||
// DHW settings
|
// DHW settings
|
||||||
vars.master.dhw.enabled = isMasterReady()
|
vars.master.dhw.enabled =
|
||||||
&& settings.opentherm.options.dhwSupport
|
isMasterReady() &&
|
||||||
&& settings.dhw.enabled
|
settings.opentherm.options.dhwSupport &&
|
||||||
&& !vars.master.dhw.overheat;
|
settings.dhw.enabled &&
|
||||||
|
!vars.master.dhw.overheat;
|
||||||
vars.master.dhw.targetTemp = settings.dhw.target;
|
vars.master.dhw.targetTemp = settings.dhw.target;
|
||||||
|
|
||||||
// CH2 settings
|
// CH2 settings
|
||||||
vars.master.ch2.enabled = settings.opentherm.options.ch2AlwaysEnabled
|
vars.master.ch2.enabled =
|
||||||
|| (settings.opentherm.options.heatingToCh2 && vars.master.heating.enabled)
|
settings.opentherm.options.ch2AlwaysEnabled ||
|
||||||
|| (settings.opentherm.options.dhwToCh2 && vars.master.dhw.enabled);
|
(settings.opentherm.options.heatingToCh2 && vars.master.heating.enabled) ||
|
||||||
|
(settings.opentherm.options.dhwToCh2 && vars.master.dhw.enabled);
|
||||||
|
|
||||||
if (settings.opentherm.options.heatingToCh2) {
|
if (settings.opentherm.options.heatingToCh2) {
|
||||||
vars.master.ch2.targetTemp = !settings.opentherm.options.nativeOTC
|
vars.master.ch2.targetTemp = !settings.opentherm.options.nativeOTC
|
||||||
@@ -429,8 +429,7 @@ static Task configureDriverTask("Configure OpenTherm driver", Task::Type::ONCE,
|
|||||||
});
|
});
|
||||||
|
|
||||||
static Task maintainOpenThermTask("Maintain OpenTherm", [](void*) {
|
static Task maintainOpenThermTask("Maintain OpenTherm", [](void*) {
|
||||||
if (slave.getConfig().rxGpio != settings.opentherm.inGpio ||
|
if (slave.getConfig().rxGpio != settings.opentherm.inGpio || slave.getConfig().txGpio != settings.opentherm.outGpio) {
|
||||||
slave.getConfig().txGpio != settings.opentherm.outGpio) {
|
|
||||||
// Apply changed GPIO before any bus exchange in this manager pass.
|
// Apply changed GPIO before any bus exchange in this manager pass.
|
||||||
configureDriverTask.resume().tryRun();
|
configureDriverTask.resume().tryRun();
|
||||||
|
|
||||||
@@ -446,8 +445,7 @@ static Task maintainOpenThermTask("Maintain OpenTherm", [](void*) {
|
|||||||
// Apply channel settings even while the bus is unavailable.
|
// Apply channel settings even while the bus is unavailable.
|
||||||
updateMasterState();
|
updateMasterState();
|
||||||
|
|
||||||
if (slave.getConfig().rxGpio != settings.opentherm.inGpio ||
|
if (slave.getConfig().rxGpio != settings.opentherm.inGpio || slave.getConfig().txGpio != settings.opentherm.outGpio) {
|
||||||
slave.getConfig().txGpio != settings.opentherm.outGpio) {
|
|
||||||
maintainOpenThermTask.setInterval(5000);
|
maintainOpenThermTask.setInterval(5000);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -515,8 +513,8 @@ static Task readStatusTask("Read boiler status", [](void*) {
|
|||||||
vars.master.heating.enabled, settings.opentherm.heatingDisablingAction
|
vars.master.heating.enabled, settings.opentherm.heatingDisablingAction
|
||||||
))
|
))
|
||||||
.setHotWaterEnabled(
|
.setHotWaterEnabled(
|
||||||
settings.opentherm.options.dhwSupport &&
|
settings.opentherm.options.dhwSupport
|
||||||
getSlaveChannelEnabled(vars.master.dhw.enabled, settings.opentherm.dhwDisablingAction)
|
&& getSlaveChannelEnabled(vars.master.dhw.enabled, settings.opentherm.dhwDisablingAction)
|
||||||
)
|
)
|
||||||
.setCoolingEnabled(settings.opentherm.options.coolingSupport)
|
.setCoolingEnabled(settings.opentherm.options.coolingSupport)
|
||||||
.setOutsideTemperatureCompensationEnabled(settings.opentherm.options.nativeOTC)
|
.setOutsideTemperatureCompensationEnabled(settings.opentherm.options.nativeOTC)
|
||||||
@@ -898,9 +896,7 @@ static Task writeFaultResetTask("Write fault reset", [](void*) {
|
|||||||
// Diag reset action
|
// Diag reset action
|
||||||
static Task writeDiagnosticResetTask("Write diagnostic reset", [](void*) {
|
static Task writeDiagnosticResetTask("Write diagnostic reset", [](void*) {
|
||||||
const auto response = slave.sendRequest(ESP32OT::Messages::RemoteRequest(10));
|
const auto response = slave.sendRequest(ESP32OT::Messages::RemoteRequest(10));
|
||||||
if (!response.isSuccess() ||
|
if (!response.isSuccess() || response.getRequestCode() != 10 || response.getResponseCode() < 128) {
|
||||||
response.getRequestCode() != 10 ||
|
|
||||||
response.getResponseCode() < 128) {
|
|
||||||
ESP_LOGE(L_OT, "Boiler diagnostic reset failed");
|
ESP_LOGE(L_OT, "Boiler diagnostic reset failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1931,9 +1927,9 @@ void initOpenTherm() {
|
|||||||
// Write the DHW temperature setpoint.
|
// Write the DHW temperature setpoint.
|
||||||
writeDhwSetpointTask.setInterval(750)
|
writeDhwSetpointTask.setInterval(750)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& settings.opentherm.options.dhwSupport
|
settings.opentherm.options.dhwSupport &&
|
||||||
&& needWriteDhwSetpoint(getDhwChannelSetpoint());
|
needWriteDhwSetpoint(getDhwChannelSetpoint());
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(writeDhwSetpointTask);
|
openthermTaskManager.addTask(writeDhwSetpointTask);
|
||||||
@@ -1941,10 +1937,10 @@ void initOpenTherm() {
|
|||||||
// Write the CH2 water temperature setpoint.
|
// Write the CH2 water temperature setpoint.
|
||||||
writeCh2SetpointTask.setInterval(750)
|
writeCh2SetpointTask.setInterval(750)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& (settings.opentherm.options.heatingToCh2 || settings.opentherm.options.dhwToCh2
|
(settings.opentherm.options.heatingToCh2 || settings.opentherm.options.dhwToCh2 ||
|
||||||
|| (!vars.master.ch2.enabled && settings.opentherm.ch2DisablingAction != ChannelDisablingAction::OFF))
|
(!vars.master.ch2.enabled && settings.opentherm.ch2DisablingAction != ChannelDisablingAction::OFF)) &&
|
||||||
&& needWriteCh2Setpoint(getCh2ChannelSetpoint());
|
needWriteCh2Setpoint(getCh2ChannelSetpoint());
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(writeCh2SetpointTask);
|
openthermTaskManager.addTask(writeCh2SetpointTask);
|
||||||
@@ -1952,9 +1948,9 @@ void initOpenTherm() {
|
|||||||
// Write the heating room setpoint for native OTC.
|
// Write the heating room setpoint for native OTC.
|
||||||
writeRoomSetpointTask.setInterval(750)
|
writeRoomSetpointTask.setInterval(750)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& settings.opentherm.options.nativeOTC
|
settings.opentherm.options.nativeOTC &&
|
||||||
&& needWriteRoomSetpoint(vars.master.heating.targetTemp);
|
needWriteRoomSetpoint(vars.master.heating.targetTemp);
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(writeRoomSetpointTask);
|
openthermTaskManager.addTask(writeRoomSetpointTask);
|
||||||
@@ -1962,9 +1958,9 @@ void initOpenTherm() {
|
|||||||
// Write the mirrored CH2 room setpoint for native OTC.
|
// Write the mirrored CH2 room setpoint for native OTC.
|
||||||
writeRoomSetpointCh2Task.setInterval(750)
|
writeRoomSetpointCh2Task.setInterval(750)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& settings.opentherm.options.nativeOTC && settings.opentherm.options.heatingToCh2
|
settings.opentherm.options.nativeOTC && settings.opentherm.options.heatingToCh2 &&
|
||||||
&& needWriteRoomSetpointCh2(vars.master.heating.targetTemp);
|
needWriteRoomSetpointCh2(vars.master.heating.targetTemp);
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(writeRoomSetpointCh2Task);
|
openthermTaskManager.addTask(writeRoomSetpointCh2Task);
|
||||||
@@ -1986,9 +1982,8 @@ void initOpenTherm() {
|
|||||||
// Execute pending boiler fault reset requests.
|
// Execute pending boiler fault reset requests.
|
||||||
writeFaultResetTask.setInterval(750)
|
writeFaultResetTask.setInterval(750)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady() && vars.slave.fault.active && (
|
return isSlaveReady() && vars.slave.fault.active &&
|
||||||
vars.actions.resetFault || settings.opentherm.options.autoFaultReset
|
(vars.actions.resetFault || settings.opentherm.options.autoFaultReset);
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.onDone([](const Task& task, uint32_t elapsed) {
|
.onDone([](const Task& task, uint32_t elapsed) {
|
||||||
vars.actions.resetFault = false;
|
vars.actions.resetFault = false;
|
||||||
@@ -1999,9 +1994,8 @@ void initOpenTherm() {
|
|||||||
// Execute pending service reset requests.
|
// Execute pending service reset requests.
|
||||||
writeDiagnosticResetTask.setInterval(750)
|
writeDiagnosticResetTask.setInterval(750)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady() && vars.slave.diag.active && (
|
return isSlaveReady() && vars.slave.diag.active &&
|
||||||
vars.actions.resetDiagnostic || settings.opentherm.options.autoDiagReset
|
(vars.actions.resetDiagnostic || settings.opentherm.options.autoDiagReset);
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.onDone([](const Task& task, uint32_t elapsed) {
|
.onDone([](const Task& task, uint32_t elapsed) {
|
||||||
vars.actions.resetDiagnostic = false;
|
vars.actions.resetDiagnostic = false;
|
||||||
@@ -2012,9 +2006,8 @@ void initOpenTherm() {
|
|||||||
// Send the current indoor temperature.
|
// Send the current indoor temperature.
|
||||||
writeRoomTemperatureTask.setInterval(60000)
|
writeRoomTemperatureTask.setInterval(60000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady() && (
|
return isSlaveReady() &&
|
||||||
settings.opentherm.options.nativeOTC || settings.opentherm.options.alwaysSendIndoorTemp
|
(settings.opentherm.options.nativeOTC || settings.opentherm.options.alwaysSendIndoorTemp);
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.onDone([](const Task& task, uint32_t elapsed) {
|
.onDone([](const Task& task, uint32_t elapsed) {
|
||||||
writeRoomTemperatureTask.setInterval(60000);
|
writeRoomTemperatureTask.setInterval(60000);
|
||||||
@@ -2025,9 +2018,9 @@ void initOpenTherm() {
|
|||||||
// Send the current indoor temperature to CH2.
|
// Send the current indoor temperature to CH2.
|
||||||
writeRoomTemperatureCh2Task.setInterval(60000)
|
writeRoomTemperatureCh2Task.setInterval(60000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady() && (
|
return isSlaveReady() &&
|
||||||
settings.opentherm.options.nativeOTC || settings.opentherm.options.alwaysSendIndoorTemp
|
(settings.opentherm.options.nativeOTC || settings.opentherm.options.alwaysSendIndoorTemp) &&
|
||||||
) && settings.opentherm.options.heatingToCh2;
|
settings.opentherm.options.heatingToCh2;
|
||||||
})
|
})
|
||||||
.onDone([](const Task& task, uint32_t elapsed) {
|
.onDone([](const Task& task, uint32_t elapsed) {
|
||||||
writeRoomTemperatureCh2Task.setInterval(60000);
|
writeRoomTemperatureCh2Task.setInterval(60000);
|
||||||
@@ -2038,10 +2031,9 @@ void initOpenTherm() {
|
|||||||
// Read relative modulation and calculate current power.
|
// Read relative modulation and calculate current power.
|
||||||
readModulationTask.setInterval(15000)
|
readModulationTask.setInterval(15000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady() && (
|
return isSlaveReady() &&
|
||||||
Sensors::getAmountByType(Sensors::Type::OT_MODULATION_LEVEL, true) ||
|
(Sensors::getAmountByType(Sensors::Type::OT_MODULATION_LEVEL, true) ||
|
||||||
Sensors::getAmountByType(Sensors::Type::OT_CURRENT_POWER, true)
|
Sensors::getAmountByType(Sensors::Type::OT_CURRENT_POWER, true));
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(readModulationTask);
|
openthermTaskManager.addTask(readModulationTask);
|
||||||
@@ -2049,9 +2041,9 @@ void initOpenTherm() {
|
|||||||
// Read the primary DHW temperature.
|
// Read the primary DHW temperature.
|
||||||
readDhwTemperatureTask.setInterval(5000)
|
readDhwTemperatureTask.setInterval(5000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& settings.opentherm.options.dhwSupport
|
settings.opentherm.options.dhwSupport &&
|
||||||
&& Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP, true);
|
Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP, true);
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(readDhwTemperatureTask);
|
openthermTaskManager.addTask(readDhwTemperatureTask);
|
||||||
@@ -2059,9 +2051,9 @@ void initOpenTherm() {
|
|||||||
// Read the second DHW temperature.
|
// Read the second DHW temperature.
|
||||||
readDhwTemperature2Task.setInterval(5000)
|
readDhwTemperature2Task.setInterval(5000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& settings.opentherm.options.dhwSupport
|
settings.opentherm.options.dhwSupport &&
|
||||||
&& Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP2, true);
|
Sensors::getAmountByType(Sensors::Type::OT_DHW_TEMP2, true);
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(readDhwTemperature2Task);
|
openthermTaskManager.addTask(readDhwTemperature2Task);
|
||||||
@@ -2069,9 +2061,9 @@ void initOpenTherm() {
|
|||||||
// Read the DHW flow rate.
|
// Read the DHW flow rate.
|
||||||
readDhwFlowTask.setInterval(5000)
|
readDhwFlowTask.setInterval(5000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& settings.opentherm.options.dhwSupport
|
settings.opentherm.options.dhwSupport &&
|
||||||
&& Sensors::getAmountByType(Sensors::Type::OT_DHW_FLOW_RATE, true);
|
Sensors::getAmountByType(Sensors::Type::OT_DHW_FLOW_RATE, true);
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(readDhwFlowTask);
|
openthermTaskManager.addTask(readDhwFlowTask);
|
||||||
@@ -2095,9 +2087,9 @@ void initOpenTherm() {
|
|||||||
// Read the CH2 water temperature.
|
// Read the CH2 water temperature.
|
||||||
readCh2TemperatureTask.setInterval(5000)
|
readCh2TemperatureTask.setInterval(5000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady()
|
return isSlaveReady() &&
|
||||||
&& Sensors::getAmountByType(Sensors::Type::OT_CH2_TEMP, true)
|
Sensors::getAmountByType(Sensors::Type::OT_CH2_TEMP, true) &&
|
||||||
&& vars.master.ch2.enabled && !settings.opentherm.options.nativeOTC;
|
vars.master.ch2.enabled && !settings.opentherm.options.nativeOTC;
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(readCh2TemperatureTask);
|
openthermTaskManager.addTask(readCh2TemperatureTask);
|
||||||
@@ -2145,10 +2137,9 @@ void initOpenTherm() {
|
|||||||
// Read the requested and actual relative fan speeds.
|
// Read the requested and actual relative fan speeds.
|
||||||
readFanSpeedTask.setInterval(5000)
|
readFanSpeedTask.setInterval(5000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady() && (
|
return isSlaveReady() &&
|
||||||
Sensors::getAmountByType(Sensors::Type::OT_FAN_SPEED_SETPOINT, true) ||
|
(Sensors::getAmountByType(Sensors::Type::OT_FAN_SPEED_SETPOINT, true) ||
|
||||||
Sensors::getAmountByType(Sensors::Type::OT_FAN_SPEED_CURRENT, true)
|
Sensors::getAmountByType(Sensors::Type::OT_FAN_SPEED_CURRENT, true));
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(readFanSpeedTask);
|
openthermTaskManager.addTask(readFanSpeedTask);
|
||||||
@@ -2238,9 +2229,7 @@ void initOpenTherm() {
|
|||||||
// Read or clear the diagnostic code.
|
// Read or clear the diagnostic code.
|
||||||
readDiagnosticTask.setInterval(60000)
|
readDiagnosticTask.setInterval(60000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return isSlaveReady() && (
|
return isSlaveReady() && (vars.slave.diag.active || vars.slave.fault.active);
|
||||||
vars.slave.diag.active || vars.slave.fault.active
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.onDone(onOperationDone);
|
.onDone(onOperationDone);
|
||||||
openthermTaskManager.addTask(readDiagnosticTask);
|
openthermTaskManager.addTask(readDiagnosticTask);
|
||||||
|
|||||||
+8
-8
@@ -560,14 +560,14 @@ static void restApi() {
|
|||||||
} else if (section == S_MQTT) {
|
} else if (section == S_MQTT) {
|
||||||
const auto previousMqtt = settings.mqtt;
|
const auto previousMqtt = settings.mqtt;
|
||||||
result = fromJson(requestDoc, settings.mqtt);
|
result = fromJson(requestDoc, settings.mqtt);
|
||||||
mqttChanged = previousMqtt.enabled != settings.mqtt.enabled
|
mqttChanged = previousMqtt.enabled != settings.mqtt.enabled ||
|
||||||
|| previousMqtt.port != settings.mqtt.port
|
previousMqtt.port != settings.mqtt.port ||
|
||||||
|| previousMqtt.interval != settings.mqtt.interval
|
previousMqtt.interval != settings.mqtt.interval ||
|
||||||
|| strcmp(previousMqtt.server, settings.mqtt.server) != 0
|
strcmp(previousMqtt.server, settings.mqtt.server) != 0 ||
|
||||||
|| strcmp(previousMqtt.user, settings.mqtt.user) != 0
|
strcmp(previousMqtt.user, settings.mqtt.user) != 0 ||
|
||||||
|| strcmp(previousMqtt.password, settings.mqtt.password) != 0
|
strcmp(previousMqtt.password, settings.mqtt.password) != 0 ||
|
||||||
|| strcmp(previousMqtt.prefix, settings.mqtt.prefix) != 0
|
strcmp(previousMqtt.prefix, settings.mqtt.prefix) != 0 ||
|
||||||
|| strcmp(previousMqtt.homeAssistantDiscoveryPrefix, settings.mqtt.homeAssistantDiscoveryPrefix) != 0;
|
strcmp(previousMqtt.homeAssistantDiscoveryPrefix, settings.mqtt.homeAssistantDiscoveryPrefix) != 0;
|
||||||
|
|
||||||
} else if (section == S_EMERGENCY) {
|
} else if (section == S_EMERGENCY) {
|
||||||
result = fromJson(requestDoc, settings.emergency);
|
result = fromJson(requestDoc, settings.emergency);
|
||||||
|
|||||||
+9
-8
@@ -64,9 +64,9 @@ static Task pidTask("PID", Task::Type::FOREVER, [](void*) {
|
|||||||
pidRegulator.setpoint = settings.heating.target;
|
pidRegulator.setpoint = settings.heating.target;
|
||||||
|
|
||||||
float error = pidRegulator.setpoint - pidRegulator.input;
|
float error = pidRegulator.setpoint - pidRegulator.input;
|
||||||
bool hasDeadband = settings.pid.deadband.enabled
|
bool hasDeadband = settings.pid.deadband.enabled &&
|
||||||
&& (error > -(settings.pid.deadband.thresholdHigh))
|
(error > -(settings.pid.deadband.thresholdHigh)) &&
|
||||||
&& (error < settings.pid.deadband.thresholdLow);
|
(error < settings.pid.deadband.thresholdLow);
|
||||||
|
|
||||||
if (hasDeadband) {
|
if (hasDeadband) {
|
||||||
pidRegulator.Kp *= settings.pid.deadband.p_multiplier;
|
pidRegulator.Kp *= settings.pid.deadband.p_multiplier;
|
||||||
@@ -102,8 +102,9 @@ static void turbo() {
|
|||||||
|
|
||||||
static void hysteresis() {
|
static void hysteresis() {
|
||||||
// Hysteresis also clears blocking when it is no longer applicable.
|
// Hysteresis also clears blocking when it is no longer applicable.
|
||||||
const bool useHysteresis = settings.heating.hysteresis.enabled && indoorSensorsConnected
|
const bool useHysteresis =
|
||||||
&& (settings.equitherm.enabled || settings.pid.enabled || settings.opentherm.options.nativeOTC);
|
settings.heating.hysteresis.enabled && indoorSensorsConnected &&
|
||||||
|
(settings.equitherm.enabled || settings.pid.enabled || settings.opentherm.options.nativeOTC);
|
||||||
|
|
||||||
if (useHysteresis) {
|
if (useHysteresis) {
|
||||||
if (!vars.master.heating.blocking && vars.master.heating.indoorTemp - settings.heating.target + 0.0001f >= settings.heating.hysteresis.value) {
|
if (!vars.master.heating.blocking && vars.master.heating.indoorTemp - settings.heating.target + 0.0001f >= settings.heating.hysteresis.value) {
|
||||||
@@ -228,9 +229,9 @@ void initRegulator() {
|
|||||||
|
|
||||||
// Sensor availability is refreshed by the regulator before checking PID eligibility.
|
// Sensor availability is refreshed by the regulator before checking PID eligibility.
|
||||||
pidTask.setEnabledWhen([] {
|
pidTask.setEnabledWhen([] {
|
||||||
return settings.pid.enabled && settings.heating.enabled
|
return settings.pid.enabled && settings.heating.enabled &&
|
||||||
&& !vars.emergency.state && !settings.opentherm.options.nativeOTC
|
!vars.emergency.state && !settings.opentherm.options.nativeOTC &&
|
||||||
&& indoorSensorsConnected;
|
indoorSensorsConnected;
|
||||||
});
|
});
|
||||||
pidTask.setInterval(10000);
|
pidTask.setInterval(10000);
|
||||||
pidTask.resume(pidTask.interval());
|
pidTask.resume(pidTask.interval());
|
||||||
|
|||||||
+9
-12
@@ -954,18 +954,16 @@ void initSensors() {
|
|||||||
|
|
||||||
pollDhtSensorsTask.setInterval(1000)
|
pollDhtSensorsTask.setInterval(1000)
|
||||||
.setEnabledWhen([] {
|
.setEnabledWhen([] {
|
||||||
return canRunSensors() && (
|
return canRunSensors() &&
|
||||||
Sensors::getAmountByType(Sensors::Type::DHT11, true) ||
|
(Sensors::getAmountByType(Sensors::Type::DHT11, true) ||
|
||||||
Sensors::getAmountByType(Sensors::Type::DHT22, true)
|
Sensors::getAmountByType(Sensors::Type::DHT22, true));
|
||||||
);
|
|
||||||
});
|
});
|
||||||
sensorsTaskManager.addTask(pollDhtSensorsTask);
|
sensorsTaskManager.addTask(pollDhtSensorsTask);
|
||||||
|
|
||||||
maintainDallasSensorsTask.setEnabledWhen([] {
|
maintainDallasSensorsTask.setEnabledWhen([] {
|
||||||
return canRunSensors() && (
|
return canRunSensors() &&
|
||||||
!dallasInstances.empty() ||
|
(!dallasInstances.empty() ||
|
||||||
Sensors::getAmountByType(Sensors::Type::DALLAS_TEMP, true)
|
Sensors::getAmountByType(Sensors::Type::DALLAS_TEMP, true));
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.resume(15000);
|
.resume(15000);
|
||||||
sensorsTaskManager.addTask(maintainDallasSensorsTask);
|
sensorsTaskManager.addTask(maintainDallasSensorsTask);
|
||||||
@@ -978,10 +976,9 @@ void initSensors() {
|
|||||||
|
|
||||||
#if USE_BLE
|
#if USE_BLE
|
||||||
scanBleSensorsTask.setEnabledWhen([] {
|
scanBleSensorsTask.setEnabledWhen([] {
|
||||||
return canRunSensors() && (
|
return canRunSensors() &&
|
||||||
NimBLEDevice::isInitialized() ||
|
(NimBLEDevice::isInitialized() ||
|
||||||
Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true)
|
Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true));
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.onDone([](const Task&, uint32_t) {
|
.onDone([](const Task&, uint32_t) {
|
||||||
if (scanBleSensorsTask.interval() != 1000) {
|
if (scanBleSensorsTask.interval() != 1000) {
|
||||||
|
|||||||
Reference in new issue
Block a user