Browse Source

Changed RFB_DIRECT setting

rfm69
Xose Pérez 6 years ago
parent
commit
44f182c064
2 changed files with 38 additions and 27 deletions
  1. +21
    -10
      code/espurna/config/hardware.h
  2. +17
    -17
      code/espurna/rfbridge.ino

+ 21
- 10
code/espurna/config/hardware.h View File

@ -599,16 +599,13 @@
// Info // Info
#define MANUFACTURER "ITEAD" #define MANUFACTURER "ITEAD"
#define DEVICE "SONOFF_RFBRIDGE" #define DEVICE "SONOFF_RFBRIDGE"
#define SERIAL_BAUDRATE 19200
#define RELAY_PROVIDER RELAY_PROVIDER_RFBRIDGE #define RELAY_PROVIDER RELAY_PROVIDER_RFBRIDGE
// Number of virtual switches
#ifndef DUMMY_RELAY_COUNT #ifndef DUMMY_RELAY_COUNT
#define DUMMY_RELAY_COUNT 8 #define DUMMY_RELAY_COUNT 8
#endif #endif
// Remove UART noise on serial line
#define DEBUG_SERIAL_SUPPORT 0
// Buttons // Buttons
#define BUTTON1_PIN 0 #define BUTTON1_PIN 0
#define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH #define BUTTON1_MODE BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
@ -617,12 +614,26 @@
#define LED1_PIN 13 #define LED1_PIN 13
#define LED1_PIN_INVERSE 1 #define LED1_PIN_INVERSE 1
// RFB-Direct
#ifdef RFB_DIRECT
#undef DEVICE
#define DEVICE "SONOFF_RFBRIDGE_DIRECT"
#define RFB_RX_PIN 4
#define RFB_TX_PIN 5
// RFB Direct hack thanks to @wildwiz
// https://github.com/xoseperez/espurna/wiki/Hardware-Itead-Sonoff-RF-Bridge---Direct-Hack
#ifndef RFB_DIRECT
#define RFB_DIRECT 0
#endif
#ifndef RFB_RX_PIN
#define RFB_RX_PIN 4 // GPIO for RX when RFB_DIRECT
#endif
#ifndef RFB_TX_PIN
#define RFB_TX_PIN 5 // GPIO for TX when RFB_DIRECT
#endif
// When using un-modified harware, ESPurna communicates with the secondary
// MCU EFM8BB1 via UART at 19200 bps so we need to change the speed of
// the port and remove UART noise on serial line
#if not RFB_DIRECT
#define SERIAL_BAUDRATE 19200
#define DEBUG_SERIAL_SUPPORT 0
#endif #endif
#elif defined(ITEAD_SONOFF_B1) #elif defined(ITEAD_SONOFF_B1)


+ 17
- 17
code/espurna/rfbridge.ino View File

@ -11,7 +11,7 @@ Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
#include <queue> #include <queue>
#include <Ticker.h> #include <Ticker.h>
#ifdef RFB_DIRECT
#if RFB_DIRECT
#include <RCSwitch.h> #include <RCSwitch.h>
#endif #endif
@ -55,9 +55,9 @@ 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;
#ifdef RFB_DIRECT
RCSwitch * _rfModem;
bool _learning = false;
#if RFB_DIRECT
RCSwitch * _rfModem;
bool _learning = false;
#endif #endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -114,19 +114,19 @@ void _rfbWebSocketOnAction(uint32_t client_id, const char * action, JsonObject&
} }
void _rfbAck() { void _rfbAck() {
#ifndef RFB_DIRECT
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending ACK\n"));
Serial.println();
Serial.write(RF_CODE_START);
Serial.write(RF_CODE_ACK);
Serial.write(RF_CODE_STOP);
Serial.flush();
Serial.println();
#if not RFB_DIRECT
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending ACK\n"));
Serial.println();
Serial.write(RF_CODE_START);
Serial.write(RF_CODE_ACK);
Serial.write(RF_CODE_STOP);
Serial.flush();
Serial.println();
#endif #endif
} }
void _rfbLearn() { void _rfbLearn() {
#ifdef RFB_DIRECT
#if RFB_DIRECT
DEBUG_MSG_P(PSTR("[RFBRIDGE] Entering LEARN mode\n")); DEBUG_MSG_P(PSTR("[RFBRIDGE] Entering LEARN mode\n"));
_learning = true; _learning = true;
#else #else
@ -154,7 +154,7 @@ void _rfbSendRaw(const byte *message, const unsigned char n = RF_MESSAGE_SIZE) {
} }
void _rfbSend(byte * message) { void _rfbSend(byte * message) {
#ifdef RFB_DIRECT
#if RFB_DIRECT
unsigned int protocol = message[1]; unsigned int protocol = message[1];
unsigned int bitlength = message[4]; unsigned int bitlength = message[4];
unsigned long rf_code = unsigned long rf_code =
@ -328,7 +328,7 @@ void _rfbDecode() {
} }
void _rfbReceive() { void _rfbReceive() {
#ifdef RFB_DIRECT
#if RFB_DIRECT
static long learn_start = 0; static long learn_start = 0;
if (!_learning && learn_start) { if (!_learning && learn_start) {
learn_start = 0; learn_start = 0;
@ -357,7 +357,7 @@ void _rfbReceive() {
memset(_uartbuf, 0, sizeof(_uartbuf)); memset(_uartbuf, 0, sizeof(_uartbuf));
unsigned char *msgbuf = _uartbuf + 1; unsigned char *msgbuf = _uartbuf + 1;
_uartbuf[0] = _learning ? RF_CODE_LEARN_OK: RF_CODE_RFIN; _uartbuf[0] = _learning ? RF_CODE_LEARN_OK: RF_CODE_RFIN;
msgbuf[0] = 0xC0;
msgbuf[0] = 0xC0;
msgbuf[1] = _rfModem->getReceivedProtocol(); msgbuf[1] = _rfModem->getReceivedProtocol();
msgbuf[4] = _rfModem->getReceivedBitlength(); msgbuf[4] = _rfModem->getReceivedBitlength();
msgbuf[5] = rf_code >> 24; msgbuf[5] = rf_code >> 24;
@ -590,7 +590,7 @@ void rfbSetup() {
wsOnActionRegister(_rfbWebSocketOnAction); wsOnActionRegister(_rfbWebSocketOnAction);
#endif #endif
#ifdef RFB_DIRECT
#if RFB_DIRECT
_rfModem = new RCSwitch(); _rfModem = new RCSwitch();
_rfModem->enableReceive(RFB_RX_PIN); _rfModem->enableReceive(RFB_RX_PIN);
_rfModem->enableTransmit(RFB_TX_PIN); _rfModem->enableTransmit(RFB_TX_PIN);


Loading…
Cancel
Save