From 2dc4f28dd92fdb353b58c2528d27213c3d2a1515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 13 Feb 2018 19:42:37 +0100 Subject: [PATCH] Prevent resending messages from rfin in RF Bridge (#561) --- code/espurna/rfbridge.ino | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/code/espurna/rfbridge.ino b/code/espurna/rfbridge.ino index 08431ee2..47436c06 100644 --- a/code/espurna/rfbridge.ino +++ b/code/espurna/rfbridge.ino @@ -443,37 +443,47 @@ String rfbRetrieve(unsigned char id, bool status) { } void rfbStatus(unsigned char id, bool status) { + String value = rfbRetrieve(id, status); if (value.length() > 0) { + bool same = _rfbSameOnOff(id); #if RF_RAW_SUPPORT byte message[RF_MAX_MESSAGE_SIZE]; int len = _rfbToArray(value.c_str(), message, 0); + if (len == RF_MESSAGE_SIZE && // probably a standard msg (message[0] != RF_CODE_START || // raw would start with 0xAA message[1] != RF_CODE_RFOUT_BUCKET || // followed by 0xB0, message[2] + 4 != len || // needs a valid length, message[len-1] != RF_CODE_STOP)) { // and finish with 0x55 - unsigned char times = RF_SEND_TIMES; - if (same) times = _rfbin ? 0 : 1; - _rfbSend(message, times); + + if (!_rfbin) { + unsigned char times = same ? 1 : RF_SEND_TIMES; + _rfbSend(message, times); + } + } else { _rfbSendRawOnce(message, len); // send a raw message } #else // RF_RAW_SUPPORT - byte message[RF_MESSAGE_SIZE]; - _rfbToArray(value.c_str(), message); - unsigned char times = RF_SEND_TIMES; - if (same) times = _rfbin ? 0 : 1; - _rfbSend(message, times); + if (!_rfbin) { + byte message[RF_MESSAGE_SIZE]; + _rfbToArray(value.c_str(), message); + unsigned char times = same ? 1 : RF_SEND_TIMES; + _rfbSend(message, times); + } #endif // RF_RAW_SUPPORT } + + _rfbin = false; + } void rfbLearn(unsigned char id, bool status) {