mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
add mqtt base, fix mixer, fix masterthermostat, dallas fails, fix mult. roomctrl.
This commit is contained in:
@@ -20,35 +20,42 @@
|
||||
|
||||
namespace emsesp {
|
||||
|
||||
static uint32_t rc_time_ = 0;
|
||||
static int16_t remotetemp[4] = {EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET};
|
||||
// init statics
|
||||
bool Roomctrl::switch_off_[HCS] = {false, false, false, false};
|
||||
uint32_t Roomctrl::rc_time_[HCS] = {0, 0, 0, 0};
|
||||
int16_t Roomctrl::remotetemp_[HCS] = {EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET, EMS_VALUE_SHORT_NOTSET};
|
||||
|
||||
/**
|
||||
* set the temperature,
|
||||
*/
|
||||
void Roomctrl::set_remotetemp(const uint8_t hc, const int16_t temp) {
|
||||
if (hc > 3) {
|
||||
if (hc >= HCS) {
|
||||
return;
|
||||
}
|
||||
remotetemp[hc] = temp;
|
||||
if (remotetemp_[hc] != EMS_VALUE_SHORT_NOTSET && temp == EMS_VALUE_SHORT_NOTSET) {
|
||||
switch_off_[hc] = true;
|
||||
}
|
||||
remotetemp_[hc] = temp;
|
||||
}
|
||||
|
||||
/**
|
||||
* if remote control is active send the temperature every minute
|
||||
*/
|
||||
void Roomctrl::send(const uint8_t addr) {
|
||||
uint8_t hc_ = addr - ADDR;
|
||||
uint8_t hc = addr - ADDR;
|
||||
// check address, reply only on addresses 0x18..0x1B
|
||||
if (hc_ > 3) {
|
||||
if (hc >= HCS) {
|
||||
return;
|
||||
}
|
||||
// no reply if the temperature is not set
|
||||
if (remotetemp[hc_] == EMS_VALUE_SHORT_NOTSET) {
|
||||
if (remotetemp_[hc] == EMS_VALUE_SHORT_NOTSET && !switch_off_[hc]) {
|
||||
return;
|
||||
}
|
||||
if (uuid::get_uptime() - rc_time_ > SEND_INTERVAL) { // send every minute
|
||||
rc_time_ = uuid::get_uptime(); // use EMS-ESP's millis() to prevent overhead
|
||||
temperature(addr, 0x00); // send to all
|
||||
|
||||
if (uuid::get_uptime() - rc_time_[hc] > SEND_INTERVAL) { // send every minute
|
||||
rc_time_[hc] = uuid::get_uptime(); // use EMS-ESP's millis() to prevent overhead
|
||||
temperature(addr, 0x00); // send to all
|
||||
switch_off_[hc] = false;
|
||||
} else {
|
||||
// acknowledge every poll, otherwise the master shows error A22-816
|
||||
EMSuart::send_poll(addr);
|
||||
@@ -59,14 +66,14 @@ void Roomctrl::send(const uint8_t addr) {
|
||||
* check if there is a message for the remote room controller
|
||||
*/
|
||||
void Roomctrl::check(const uint8_t addr, const uint8_t * data) {
|
||||
uint8_t hc_ = (addr & 0x7F) - ADDR;
|
||||
uint8_t hc = (addr & 0x7F) - ADDR;
|
||||
|
||||
// check address, reply only on addresses 0x18..0x1B
|
||||
if (hc_ > 3) {
|
||||
if (hc >= HCS) {
|
||||
return;
|
||||
}
|
||||
// no reply if the temperature is not set
|
||||
if (remotetemp[hc_] == EMS_VALUE_SHORT_NOTSET) {
|
||||
if (remotetemp_[hc] == EMS_VALUE_SHORT_NOTSET) {
|
||||
return;
|
||||
}
|
||||
// reply to writes with write nack byte
|
||||
@@ -78,7 +85,7 @@ void Roomctrl::check(const uint8_t addr, const uint8_t * data) {
|
||||
// empty message back if temperature not set or unknown message type
|
||||
if (data[2] == 0x02) {
|
||||
version(addr, data[0]);
|
||||
} else if (remotetemp[hc_] == EMS_VALUE_SHORT_NOTSET) {
|
||||
} else if (remotetemp_[hc] == EMS_VALUE_SHORT_NOTSET) {
|
||||
unknown(addr, data[0], data[2], data[3]);
|
||||
} else if (data[2] == 0xAF && data[3] == 0) {
|
||||
temperature(addr, data[0]);
|
||||
@@ -121,15 +128,15 @@ void Roomctrl::unknown(uint8_t addr, uint8_t dst, uint8_t type, uint8_t offset)
|
||||
*/
|
||||
void Roomctrl::temperature(uint8_t addr, uint8_t dst) {
|
||||
uint8_t data[10];
|
||||
uint8_t hc_ = addr - ADDR;
|
||||
data[0] = addr;
|
||||
data[1] = dst;
|
||||
data[2] = 0xAF;
|
||||
data[3] = 0;
|
||||
data[4] = (uint8_t)(remotetemp[hc_] >> 8);
|
||||
data[5] = (uint8_t)(remotetemp[hc_] & 0xFF);
|
||||
data[6] = 0;
|
||||
data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC
|
||||
uint8_t hc = addr - ADDR;
|
||||
data[0] = addr;
|
||||
data[1] = dst;
|
||||
data[2] = 0xAF;
|
||||
data[3] = 0;
|
||||
data[4] = (uint8_t)(remotetemp_[hc] >> 8);
|
||||
data[5] = (uint8_t)(remotetemp_[hc] & 0xFF);
|
||||
data[6] = 0;
|
||||
data[7] = EMSbus::calculate_crc(data, 7); // apppend CRC
|
||||
EMSuart::transmit(data, 8);
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user