From 907b4691ab05cbd2cefe7bf616004cbd84a7f704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Thu, 9 Nov 2017 15:56:08 +0100 Subject: [PATCH] RFBridge: toggle when RF codes for ON and OFF are the same (#270) --- code/espurna/config/general.h | 1 + code/espurna/rfbridge.ino | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/code/espurna/config/general.h b/code/espurna/config/general.h index 2dda1743..fabd10e1 100644 --- a/code/espurna/config/general.h +++ b/code/espurna/config/general.h @@ -716,6 +716,7 @@ PROGMEM const char* const custom_reset_string[] = { #define RF_SEND_TIMES 4 // How many times to send the message #define RF_SEND_DELAY 250 // Interval between sendings in ms +#define RF_RECEIVE_DELAY 500 // Interval between recieving in ms (avoid debouncing) // ----------------------------------------------------------------------------- // IR diff --git a/code/espurna/rfbridge.ino b/code/espurna/rfbridge.ino index 59039915..699e651a 100644 --- a/code/espurna/rfbridge.ino +++ b/code/espurna/rfbridge.ino @@ -94,6 +94,10 @@ void _rfbSend(byte * message, int times) { void _rfbDecode() { + static unsigned long last = 0; + if (millis() - last < RF_RECEIVE_DELAY) return; + last = millis(); + byte action = _uartbuf[0]; char buffer[RF_MESSAGE_SIZE * 2 + 1] = {0}; DEBUG_MSG_P(PSTR("[RFBRIDGE] Action 0x%02X\n"), action); @@ -134,20 +138,27 @@ void _rfbDecode() { unsigned char id, status; bool found = false; for (id=0; id