diff --git a/src/core/helpers.cpp b/src/core/helpers.cpp index 8098f93d8..25a8ed3db 100644 --- a/src/core/helpers.cpp +++ b/src/core/helpers.cpp @@ -1033,4 +1033,17 @@ float Helpers::numericoperator2scalefactor(int8_t numeric_operator) { return -numeric_operator; } +int16_t Helpers::calc_dew(int16_t temp, uint8_t humi) { + if (humi == EMS_VALUE_UINT8_NOTSET || temp == EMS_VALUE_INT16_NOTSET) { + return EMS_VALUE_INT16_NOTSET; + } + const float k2 = 17.62; + const float k3 = 243.12; + const float t = (float)temp / 10; + const float h = (float)humi / 100; + int16_t dt = (10 * k3 * (((k2 * t) / (k3 + t)) + log(h)) / (((k2 * k3) / (k3 + t)) - log(h))); + return dt; +} + + } // namespace emsesp diff --git a/src/core/helpers.h b/src/core/helpers.h index 5758b08b8..cddc0c6a0 100644 --- a/src/core/helpers.h +++ b/src/core/helpers.h @@ -84,6 +84,7 @@ class Helpers { static uint8_t count_items(const char * const * list); static const char * translated_word(const char * const * strings, const bool force_en = false); + static int16_t calc_dew(int16_t temp, uint8_t hum); #ifdef EMSESP_STANDALONE static char * ultostr(char * ptr, uint32_t value, const uint8_t base); diff --git a/src/core/roomcontrol.cpp b/src/core/roomcontrol.cpp index b047c4755..51fcadbb3 100644 --- a/src/core/roomcontrol.cpp +++ b/src/core/roomcontrol.cpp @@ -377,7 +377,7 @@ void Roomctrl::temperature(uint8_t addr, uint8_t dst, uint8_t hc) { // send telegram 0x047B only for RC100H void Roomctrl::humidity(uint8_t addr, uint8_t dst, uint8_t hc) { - int16_t dew = calc_dew(remotetemp_[hc], remotehum_[hc]); + int16_t dew = Helpers::calc_dew(remotetemp_[hc], remotehum_[hc]); int8_t dew8 = EMS_VALUE_INT8_NOTSET; if (dew != EMS_VALUE_INT16_NOTSET) { dew8 = static_cast((dew >= 0 ? dew + 5 : dew - 5) / 10); @@ -391,8 +391,8 @@ void Roomctrl::humidity(uint8_t addr, uint8_t dst, uint8_t hc) { data[5] = 0x7B + hc; data[6] = static_cast(dew8); data[7] = remotehum_[hc]; - data[8] = static_cast(static_cast(dew) >> 8); - data[9] = static_cast(static_cast(dew) & 0xFF); + data[8] = static_cast(dew >> 8); + data[9] = static_cast(dew & 0x00FF); data[10] = EMSbus::calculate_crc(data, 10); // append CRC EMSuart::transmit(data, 11); } @@ -440,17 +440,4 @@ void Roomctrl::replyF7(uint8_t addr, uint8_t dst, uint8_t offset, uint8_t typehh EMSuart::transmit(data, 10); } -int16_t Roomctrl::calc_dew(int16_t temp, uint8_t humi) { - if (humi == EMS_VALUE_UINT8_NOTSET || temp == EMS_VALUE_INT16_NOTSET) { - return EMS_VALUE_INT16_NOTSET; - } - const float k2 = 17.62; - const float k3 = 243.12; - const float t = (float)temp / 10; - const float h = (float)humi / 100; - int16_t dt = (10 * k3 * (((k2 * t) / (k3 + t)) + log(h)) / (((k2 * k3) / (k3 + t)) - log(h))); - return dt; -} - - } // namespace emsesp diff --git a/src/core/roomcontrol.h b/src/core/roomcontrol.h index 2bc61c1e5..765982135 100644 --- a/src/core/roomcontrol.h +++ b/src/core/roomcontrol.h @@ -35,7 +35,6 @@ class Roomctrl { return (hc < 4 && remotetemp_[hc] != EMS_VALUE_INT16_NOTSET); } static void set_timeout(uint8_t t); - static int16_t calc_dew(int16_t temp, uint8_t hum); private: static constexpr uint32_t SEND_INTERVAL = 15000; // 15 sec diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 5aa0f4b84..7cc5fae20 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -818,7 +818,8 @@ void Thermostat::process_RemoteHumidity(std::shared_ptr telegram if (telegram->read_value(dew, 2)) { has_update(dewtemperature_, dew); } else if (telegram->offset == 0 && telegram->message_length < 4) { - has_update(dewtemperature_, Roomctrl::calc_dew(tempsensor1_, humidity_)); + dew = Helpers::calc_dew(tempsensor1_, humidity_); + has_update(dewtemperature_, dew); } }