Skip to content

Commit

Permalink
RFBridge: toggle when RF codes for ON and OFF are the same (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed Nov 9, 2017
1 parent 442c96e commit 907b469
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions code/espurna/config/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 19 additions & 8 deletions code/espurna/rfbridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -134,20 +138,27 @@ void _rfbDecode() {
unsigned char id, status;
bool found = false;
for (id=0; id<relayCount(); id++) {
for (status=0; status<2; status++) {
String code = rfbRetrieve(id, status == 1);
if (code.length()) {
if (code.endsWith(&buffer[12])) {
found = true;
break;
}
String code_on = rfbRetrieve(id, true);
String code_off = rfbRetrieve(id, false);
if (code_on.length() && code_off.length()) {
if (code_on.endsWith(&buffer[12])) {
found = true;
status = 1;
}
if (code_off.endsWith(&buffer[12])) {
found = true;
if (status == 1) status = 2;
}
}
if (found) break;
}
if (found) {
_rfbin = true;
relayStatus(id, status == 1);
if (status == 2) {
relayToggle(id);
} else {
relayStatus(id, status == 1);
}
}

}
Expand Down

0 comments on commit 907b469

Please sign in to comment.