calc_dew to helpers

This commit is contained in:
MichaelDvP
2026-07-09 19:41:54 +02:00
parent f6cb695635
commit 5c2205cf65
5 changed files with 19 additions and 18 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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<int8_t>((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<uint8_t>(dew8);
data[7] = remotehum_[hc];
data[8] = static_cast<uint8_t>(static_cast<uint16_t>(dew) >> 8);
data[9] = static_cast<uint8_t>(static_cast<uint16_t>(dew) & 0xFF);
data[8] = static_cast<uint8_t>(dew >> 8);
data[9] = static_cast<uint8_t>(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

View File

@@ -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