|
@ -1,17 +1,17 @@ |
|
|
/*
|
|
|
/*
|
|
|
|
|
|
|
|
|
ITEAD RF BRIDGE MODULE |
|
|
|
|
|
|
|
|
RF MODULE |
|
|
|
|
|
|
|
|
Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
|
|
|
|
|
|
Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com> |
|
|
|
|
|
|
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#ifdef ITEAD_SONOFF_RFBRIDGE
|
|
|
|
|
|
|
|
|
#if defined(ITEAD_SONOFF_RFBRIDGE) || RF_SUPPORT
|
|
|
|
|
|
|
|
|
#include <queue>
|
|
|
#include <queue>
|
|
|
#include <Ticker.h>
|
|
|
#include <Ticker.h>
|
|
|
|
|
|
|
|
|
#if RFB_DIRECT
|
|
|
|
|
|
|
|
|
#if RFB_DIRECT || RF_SUPPORT
|
|
|
#include <RCSwitch.h>
|
|
|
#include <RCSwitch.h>
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
@ -53,6 +53,7 @@ unsigned char _learnId = 0; |
|
|
bool _learnStatus = true; |
|
|
bool _learnStatus = true; |
|
|
bool _rfbin = false; |
|
|
bool _rfbin = false; |
|
|
|
|
|
|
|
|
|
|
|
#if not RF_SUPPORT
|
|
|
typedef struct { |
|
|
typedef struct { |
|
|
byte code[RF_MESSAGE_SIZE]; |
|
|
byte code[RF_MESSAGE_SIZE]; |
|
|
byte times; |
|
|
byte times; |
|
@ -60,8 +61,9 @@ typedef struct { |
|
|
static std::queue<rfb_message_t> _rfb_message_queue; |
|
|
static std::queue<rfb_message_t> _rfb_message_queue; |
|
|
Ticker _rfb_ticker; |
|
|
Ticker _rfb_ticker; |
|
|
bool _rfb_ticker_active = false; |
|
|
bool _rfb_ticker_active = false; |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#if RFB_DIRECT
|
|
|
|
|
|
|
|
|
#if RFB_DIRECT || RF_SUPPORT
|
|
|
RCSwitch * _rfModem; |
|
|
RCSwitch * _rfModem; |
|
|
bool _learning = false; |
|
|
bool _learning = false; |
|
|
#endif
|
|
|
#endif
|
|
@ -74,21 +76,6 @@ bool _rfb_ticker_active = false; |
|
|
// PRIVATES
|
|
|
// PRIVATES
|
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
From an hexa char array ("A220EE...") to a byte array (half the size) |
|
|
|
|
|
*/ |
|
|
|
|
|
static int _rfbToArray(const char * in, byte * out, int length = RF_MESSAGE_SIZE * 2) { |
|
|
|
|
|
int n = strlen(in); |
|
|
|
|
|
if (n > RF_MAX_MESSAGE_SIZE*2 || (length > 0 && n != length)) return 0; |
|
|
|
|
|
char tmp[3] = {0,0,0}; |
|
|
|
|
|
n /= 2; |
|
|
|
|
|
for (unsigned char p = 0; p<n; p++) { |
|
|
|
|
|
memcpy(tmp, &in[p*2], 2); |
|
|
|
|
|
out[p] = strtol(tmp, NULL, 16); |
|
|
|
|
|
} |
|
|
|
|
|
return n; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
/*
|
|
|
From a byte array to an hexa char array ("A220EE...", double the size) |
|
|
From a byte array to an hexa char array ("A220EE...", double the size) |
|
|
*/ |
|
|
*/ |
|
@ -132,8 +119,8 @@ void _rfbWebSocketOnAction(uint32_t client_id, const char * action, JsonObject& |
|
|
#endif // WEB_SUPPORT
|
|
|
#endif // WEB_SUPPORT
|
|
|
|
|
|
|
|
|
void _rfbAck() { |
|
|
void _rfbAck() { |
|
|
#if not RFB_DIRECT
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending ACK\n")); |
|
|
|
|
|
|
|
|
#if (not RFB_DIRECT) && (not RF_SUPPORT)
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Sending ACK\n")); |
|
|
Serial.println(); |
|
|
Serial.println(); |
|
|
Serial.write(RF_CODE_START); |
|
|
Serial.write(RF_CODE_START); |
|
|
Serial.write(RF_CODE_ACK); |
|
|
Serial.write(RF_CODE_ACK); |
|
@ -144,11 +131,11 @@ void _rfbAck() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void _rfbLearn() { |
|
|
void _rfbLearn() { |
|
|
#if RFB_DIRECT
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Entering LEARN mode\n")); |
|
|
|
|
|
|
|
|
#if RFB_DIRECT || RF_SUPPORT
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Entering LEARN mode\n")); |
|
|
_learning = true; |
|
|
_learning = true; |
|
|
#else
|
|
|
#else
|
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending LEARN\n")); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Sending LEARN\n")); |
|
|
Serial.println(); |
|
|
Serial.println(); |
|
|
Serial.write(RF_CODE_START); |
|
|
Serial.write(RF_CODE_START); |
|
|
Serial.write(RF_CODE_LEARN); |
|
|
Serial.write(RF_CODE_LEARN); |
|
@ -165,6 +152,24 @@ void _rfbLearn() { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if not RF_SUPPORT
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
From an hexa char array ("A220EE...") to a byte array (half the size) |
|
|
|
|
|
*/ |
|
|
|
|
|
static int _rfbToArray(const char * in, byte * out, int length = RF_MESSAGE_SIZE * 2) { |
|
|
|
|
|
int n = strlen(in); |
|
|
|
|
|
if (n > RF_MAX_MESSAGE_SIZE*2 || (length > 0 && n != length)) return 0; |
|
|
|
|
|
char tmp[3] = {0,0,0}; |
|
|
|
|
|
n /= 2; |
|
|
|
|
|
for (unsigned char p = 0; p<n; p++) { |
|
|
|
|
|
memcpy(tmp, &in[p*2], 2); |
|
|
|
|
|
out[p] = strtol(tmp, NULL, 16); |
|
|
|
|
|
} |
|
|
|
|
|
return n; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void _rfbSendRaw(const byte *message, const unsigned char n = RF_MESSAGE_SIZE) { |
|
|
void _rfbSendRaw(const byte *message, const unsigned char n = RF_MESSAGE_SIZE) { |
|
|
for (unsigned char j=0; j<n; j++) { |
|
|
for (unsigned char j=0; j<n; j++) { |
|
|
Serial.write(message[j]); |
|
|
Serial.write(message[j]); |
|
@ -233,7 +238,7 @@ void _rfbSend(byte * code, unsigned char times) { |
|
|
|
|
|
|
|
|
char buffer[RF_MESSAGE_SIZE]; |
|
|
char buffer[RF_MESSAGE_SIZE]; |
|
|
_rfbToChar(code, buffer); |
|
|
_rfbToChar(code, buffer); |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Enqueuing MESSAGE '%s' %d time(s)\n"), buffer, times); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Enqueuing MESSAGE '%s' %d time(s)\n"), buffer, times); |
|
|
|
|
|
|
|
|
rfb_message_t message; |
|
|
rfb_message_t message; |
|
|
memcpy(message.code, code, RF_MESSAGE_SIZE); |
|
|
memcpy(message.code, code, RF_MESSAGE_SIZE); |
|
@ -248,12 +253,14 @@ void _rfbSend(byte * code, unsigned char times) { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // not RF_SUPPORT
|
|
|
|
|
|
|
|
|
#if RF_RAW_SUPPORT
|
|
|
#if RF_RAW_SUPPORT
|
|
|
|
|
|
|
|
|
void _rfbSendRawOnce(byte *code, unsigned char length) { |
|
|
void _rfbSendRawOnce(byte *code, unsigned char length) { |
|
|
char buffer[length*2]; |
|
|
char buffer[length*2]; |
|
|
_rfbToChar(code, buffer, length); |
|
|
_rfbToChar(code, buffer, length); |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending RAW MESSAGE '%s'\n"), buffer); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Sending RAW MESSAGE '%s'\n"), buffer); |
|
|
_rfbSendRaw(code, length); |
|
|
_rfbSendRaw(code, length); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -266,13 +273,13 @@ bool _rfbMatch(char* code, unsigned char& relayID, unsigned char& value, char* b |
|
|
bool found = false; |
|
|
bool found = false; |
|
|
String compareto = String(&code[12]); |
|
|
String compareto = String(&code[12]); |
|
|
compareto.toUpperCase(); |
|
|
compareto.toUpperCase(); |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Trying to match code %s\n"), compareto.c_str()); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Trying to match code %s\n"), compareto.c_str()); |
|
|
|
|
|
|
|
|
for (unsigned char i=0; i<relayCount(); i++) { |
|
|
for (unsigned char i=0; i<relayCount(); i++) { |
|
|
|
|
|
|
|
|
String code_on = rfbRetrieve(i, true); |
|
|
String code_on = rfbRetrieve(i, true); |
|
|
if (code_on.length() && code_on.endsWith(compareto)) { |
|
|
if (code_on.length() && code_on.endsWith(compareto)) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Match ON code for relay %d\n"), i); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Match ON code for relay %d\n"), i); |
|
|
value = 1; |
|
|
value = 1; |
|
|
found = true; |
|
|
found = true; |
|
|
if (buffer) strcpy(buffer, code_on.c_str()); |
|
|
if (buffer) strcpy(buffer, code_on.c_str()); |
|
@ -280,7 +287,7 @@ bool _rfbMatch(char* code, unsigned char& relayID, unsigned char& value, char* b |
|
|
|
|
|
|
|
|
String code_off = rfbRetrieve(i, false); |
|
|
String code_off = rfbRetrieve(i, false); |
|
|
if (code_off.length() && code_off.endsWith(compareto)) { |
|
|
if (code_off.length() && code_off.endsWith(compareto)) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Match OFF code for relay %d\n"), i); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Match OFF code for relay %d\n"), i); |
|
|
if (found) value = 2; |
|
|
if (found) value = 2; |
|
|
found = true; |
|
|
found = true; |
|
|
if (buffer) strcpy(buffer, code_off.c_str()); |
|
|
if (buffer) strcpy(buffer, code_off.c_str()); |
|
@ -305,11 +312,11 @@ void _rfbDecode() { |
|
|
|
|
|
|
|
|
byte action = _uartbuf[0]; |
|
|
byte action = _uartbuf[0]; |
|
|
char buffer[RF_MESSAGE_SIZE * 2 + 1] = {0}; |
|
|
char buffer[RF_MESSAGE_SIZE * 2 + 1] = {0}; |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Action 0x%02X\n"), action); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Action 0x%02X\n"), action); |
|
|
|
|
|
|
|
|
if (action == RF_CODE_LEARN_KO) { |
|
|
if (action == RF_CODE_LEARN_KO) { |
|
|
_rfbAck(); |
|
|
_rfbAck(); |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Learn timeout\n")); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Learn timeout\n")); |
|
|
#if WEB_SUPPORT
|
|
|
#if WEB_SUPPORT
|
|
|
wsSend_P(PSTR("{\"action\": \"rfbTimeout\"}")); |
|
|
wsSend_P(PSTR("{\"action\": \"rfbTimeout\"}")); |
|
|
#endif
|
|
|
#endif
|
|
@ -320,13 +327,13 @@ void _rfbDecode() { |
|
|
_rfbAck(); |
|
|
_rfbAck(); |
|
|
_rfbToChar(&_uartbuf[1], buffer); |
|
|
_rfbToChar(&_uartbuf[1], buffer); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Received message '%s'\n"), buffer); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Received message '%s'\n"), buffer); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (action == RF_CODE_LEARN_OK) { |
|
|
if (action == RF_CODE_LEARN_OK) { |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Learn success\n")); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Learn success\n")); |
|
|
rfbStore(_learnId, _learnStatus, buffer); |
|
|
rfbStore(_learnId, _learnStatus, buffer); |
|
|
|
|
|
|
|
|
// Websocket update
|
|
|
// Websocket update
|
|
@ -347,7 +354,7 @@ void _rfbDecode() { |
|
|
bool matched = _rfbMatch(buffer, id, status, buffer); |
|
|
bool matched = _rfbMatch(buffer, id, status, buffer); |
|
|
|
|
|
|
|
|
if (matched) { |
|
|
if (matched) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Matched message '%s'\n"), buffer); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Matched message '%s'\n"), buffer); |
|
|
_rfbin = true; |
|
|
_rfbin = true; |
|
|
if (status == 2) { |
|
|
if (status == 2) { |
|
|
relayToggle(id); |
|
|
relayToggle(id); |
|
@ -365,18 +372,18 @@ void _rfbDecode() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void _rfbReceive() { |
|
|
void _rfbReceive() { |
|
|
#if RFB_DIRECT
|
|
|
|
|
|
|
|
|
#if RFB_DIRECT || RF_SUPPORT
|
|
|
static long learn_start = 0; |
|
|
static long learn_start = 0; |
|
|
if (!_learning && learn_start) { |
|
|
if (!_learning && learn_start) { |
|
|
learn_start = 0; |
|
|
learn_start = 0; |
|
|
} |
|
|
} |
|
|
if (_learning) { |
|
|
if (_learning) { |
|
|
if (!learn_start) { |
|
|
if (!learn_start) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] arming learn timeout\n")); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Arming learn timeout\n")); |
|
|
learn_start = millis(); |
|
|
learn_start = millis(); |
|
|
} |
|
|
} |
|
|
if (learn_start > 0 && millis() - learn_start > RF_LEARN_TIMEOUT) { |
|
|
if (learn_start > 0 && millis() - learn_start > RF_LEARN_TIMEOUT) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] learn timeout triggered\n")); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Learn timeout triggered\n")); |
|
|
memset(_uartbuf, 0, sizeof(_uartbuf)); |
|
|
memset(_uartbuf, 0, sizeof(_uartbuf)); |
|
|
_uartbuf[0] = RF_CODE_LEARN_KO; |
|
|
_uartbuf[0] = RF_CODE_LEARN_KO; |
|
|
_rfbDecode(); |
|
|
_rfbDecode(); |
|
@ -390,7 +397,7 @@ void _rfbReceive() { |
|
|
last = millis(); |
|
|
last = millis(); |
|
|
unsigned long rf_code = _rfModem->getReceivedValue(); |
|
|
unsigned long rf_code = _rfModem->getReceivedValue(); |
|
|
if ( rf_code > 0) { |
|
|
if ( rf_code > 0) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Received code: %08X\n"), rf_code); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Received code: %08X\n"), rf_code); |
|
|
unsigned int timing = _rfModem->getReceivedDelay(); |
|
|
unsigned int timing = _rfModem->getReceivedDelay(); |
|
|
memset(_uartbuf, 0, sizeof(_uartbuf)); |
|
|
memset(_uartbuf, 0, sizeof(_uartbuf)); |
|
|
unsigned char *msgbuf = _uartbuf + 1; |
|
|
unsigned char *msgbuf = _uartbuf + 1; |
|
@ -417,7 +424,7 @@ void _rfbReceive() { |
|
|
|
|
|
|
|
|
yield(); |
|
|
yield(); |
|
|
byte c = Serial.read(); |
|
|
byte c = Serial.read(); |
|
|
//DEBUG_MSG_P(PSTR("[RFBRIDGE] Received 0x%02X\n"), c);
|
|
|
|
|
|
|
|
|
//DEBUG_MSG_P(PSTR("[RF] Received 0x%02X\n"), c);
|
|
|
|
|
|
|
|
|
if (receiving) { |
|
|
if (receiving) { |
|
|
if (c == RF_CODE_STOP && (_uartpos == 1 || _uartpos == RF_MESSAGE_SIZE + 1)) { |
|
|
if (c == RF_CODE_STOP && (_uartpos == 1 || _uartpos == RF_MESSAGE_SIZE + 1)) { |
|
@ -453,7 +460,9 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa |
|
|
char buffer[strlen(MQTT_TOPIC_RFLEARN) + 3]; |
|
|
char buffer[strlen(MQTT_TOPIC_RFLEARN) + 3]; |
|
|
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_RFLEARN); |
|
|
snprintf_P(buffer, sizeof(buffer), PSTR("%s/+"), MQTT_TOPIC_RFLEARN); |
|
|
mqttSubscribe(buffer); |
|
|
mqttSubscribe(buffer); |
|
|
|
|
|
#if not RF_SUPPORT
|
|
|
mqttSubscribe(MQTT_TOPIC_RFOUT); |
|
|
mqttSubscribe(MQTT_TOPIC_RFOUT); |
|
|
|
|
|
#endif
|
|
|
#if RF_RAW_SUPPORT
|
|
|
#if RF_RAW_SUPPORT
|
|
|
mqttSubscribe(MQTT_TOPIC_RFRAW); |
|
|
mqttSubscribe(MQTT_TOPIC_RFRAW); |
|
|
#endif
|
|
|
#endif
|
|
@ -469,7 +478,7 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa |
|
|
|
|
|
|
|
|
_learnId = t.substring(strlen(MQTT_TOPIC_RFLEARN)+1).toInt(); |
|
|
_learnId = t.substring(strlen(MQTT_TOPIC_RFLEARN)+1).toInt(); |
|
|
if (_learnId >= relayCount()) { |
|
|
if (_learnId >= relayCount()) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Wrong learnID (%d)\n"), _learnId); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Wrong learnID (%d)\n"), _learnId); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
_learnStatus = (char)payload[0] != '0'; |
|
|
_learnStatus = (char)payload[0] != '0'; |
|
@ -478,13 +487,17 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool isRFOut = t.equals(MQTT_TOPIC_RFOUT); |
|
|
|
|
|
|
|
|
#if not RF_SUPPORT
|
|
|
|
|
|
bool isRFOut = t.equals(MQTT_TOPIC_RFOUT); |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#if RF_RAW_SUPPORT
|
|
|
#if RF_RAW_SUPPORT
|
|
|
bool isRFRaw = !isRFOut && t.equals(MQTT_TOPIC_RFRAW); |
|
|
bool isRFRaw = !isRFOut && t.equals(MQTT_TOPIC_RFRAW); |
|
|
#else
|
|
|
|
|
|
|
|
|
#elif not RF_SUPPORT
|
|
|
bool isRFRaw = false; |
|
|
bool isRFRaw = false; |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if not RF_SUPPORT
|
|
|
if (isRFOut || isRFRaw) { |
|
|
if (isRFOut || isRFRaw) { |
|
|
|
|
|
|
|
|
// The payload may be a code in HEX format ([0-9A-Z]{18}) or
|
|
|
// The payload may be a code in HEX format ([0-9A-Z]{18}) or
|
|
@ -528,6 +541,8 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif // not RF_SUPPORT
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -588,7 +603,7 @@ void _rfbInitCommands() { |
|
|
// -----------------------------------------------------------------------------
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
void rfbStore(unsigned char id, bool status, const char * code) { |
|
|
void rfbStore(unsigned char id, bool status, const char * code) { |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] Storing %d-%s => '%s'\n"), id, status ? "ON" : "OFF", code); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] Storing %d-%s => '%s'\n"), id, status ? "ON" : "OFF", code); |
|
|
char key[RF_MAX_KEY_LENGTH] = {0}; |
|
|
char key[RF_MAX_KEY_LENGTH] = {0}; |
|
|
snprintf_P(key, sizeof(key), PSTR("rfb%s%d"), status ? "ON" : "OFF", id); |
|
|
snprintf_P(key, sizeof(key), PSTR("rfb%s%d"), status ? "ON" : "OFF", id); |
|
|
setSetting(key, code); |
|
|
setSetting(key, code); |
|
@ -600,6 +615,8 @@ String rfbRetrieve(unsigned char id, bool status) { |
|
|
return getSetting(key); |
|
|
return getSetting(key); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if not RF_SUPPORT
|
|
|
|
|
|
|
|
|
void rfbStatus(unsigned char id, bool status) { |
|
|
void rfbStatus(unsigned char id, bool status) { |
|
|
|
|
|
|
|
|
String value = rfbRetrieve(id, status); |
|
|
String value = rfbRetrieve(id, status); |
|
@ -643,6 +660,7 @@ void rfbStatus(unsigned char id, bool status) { |
|
|
_rfbin = false; |
|
|
_rfbin = false; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
#endif // not RF_SUPPORT
|
|
|
|
|
|
|
|
|
void rfbLearn(unsigned char id, bool status) { |
|
|
void rfbLearn(unsigned char id, bool status) { |
|
|
_learnId = id; |
|
|
_learnId = id; |
|
@ -684,13 +702,18 @@ void rfbSetup() { |
|
|
_rfbInitCommands(); |
|
|
_rfbInitCommands(); |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#if RFB_DIRECT
|
|
|
|
|
|
|
|
|
#if RFB_DIRECT || RF_SUPPORT
|
|
|
_rfModem = new RCSwitch(); |
|
|
_rfModem = new RCSwitch(); |
|
|
|
|
|
#if RF_SUPPORT
|
|
|
|
|
|
_rfModem->enableReceive(RF_PIN); |
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] RF receiver on GPIO %u\n"), RF_PIN); |
|
|
|
|
|
#else
|
|
|
_rfModem->enableReceive(RFB_RX_PIN); |
|
|
_rfModem->enableReceive(RFB_RX_PIN); |
|
|
_rfModem->enableTransmit(RFB_TX_PIN); |
|
|
_rfModem->enableTransmit(RFB_TX_PIN); |
|
|
_rfModem->setRepeatTransmit(6); |
|
|
_rfModem->setRepeatTransmit(6); |
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] RF receiver on GPIO %u\n"), RFB_RX_PIN); |
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RFBRIDGE] RF transmitter on GPIO %u\n"), RFB_TX_PIN); |
|
|
|
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] RF receiver on GPIO %u\n"), RFB_RX_PIN); |
|
|
|
|
|
DEBUG_MSG_P(PSTR("[RF] RF transmitter on GPIO %u\n"), RFB_TX_PIN); |
|
|
|
|
|
#endif
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
// Register loop
|
|
|
// Register loop
|
|
|