Skip to content

Commit

Permalink
Merge branch 'v4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
couin3 committed May 1, 2020
2 parents ed11b21 + 99a6c06 commit 5a23684
Show file tree
Hide file tree
Showing 37 changed files with 2,004 additions and 1,177 deletions.
123 changes: 123 additions & 0 deletions RFLink/1_Radio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// ************************************* //
// * Arduino Project RFLink-esp * //
// * https://github.com/couin3/RFLink * //
// * 2018..2020 Stormteam - Marc RIVES * //
// * More details in RFLink.ino file * //
// ************************************* //

#include <Arduino.h>
#include "RFLink.h"
#include "1_Radio.h"
#ifdef AUTOCONNECT_ENABLED
#include "9_AutoConnect.h"
#else
uint8_t PIN_RF_RX_PMOS = PIN_RF_RX_PMOS_0;
uint8_t PIN_RF_RX_NMOS = PIN_RF_RX_NMOS_0;
uint8_t PIN_RF_RX_VCC = PIN_RF_RX_VCC_0;
uint8_t PIN_RF_RX_GND = PIN_RF_RX_GND_0;
uint8_t PIN_RF_RX_NA = PIN_RF_RX_NA_0;
uint8_t PIN_RF_RX_DATA = PIN_RF_RX_DATA_0;
uint8_t PIN_RF_TX_PMOS = PIN_RF_TX_PMOS_0;
uint8_t PIN_RF_TX_NMOS = PIN_RF_TX_NMOS_0;
uint8_t PIN_RF_TX_VCC = PIN_RF_TX_VCC_0;
uint8_t PIN_RF_TX_GND = PIN_RF_TX_GND_0;
uint8_t PIN_RF_TX_DATA = PIN_RF_TX_DATA_0;
boolean PULLUP_RF_RX_DATA = PULLUP_RF_RX_DATA_0;
#endif //AUTOCONNECT_ENABLED

// Prototype
void enableRX();
void disableRX();
void enableTX();
void disableTX();

Radio_State current_State = Radio_NA;

void set_Radio_mode(Radio_State new_State)
{
if (current_State != new_State)
{
switch (new_State)
{
case Radio_OFF:
disableTX();
disableRX();
break;

case Radio_RX:
disableTX();
enableRX();
break;

case Radio_TX:
disableRX();
enableTX();
break;

case Radio_NA:
break;
}
current_State = new_State;
}
}

void enableRX()
{
// RX pins
pinMode(PIN_RF_RX_NA, INPUT); // Initialise in/output ports
pinMode(PIN_RF_RX_DATA, INPUT); // Initialise in/output ports
pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output
pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output
digitalWrite(PIN_RF_RX_NMOS, HIGH); // turn GND to RF receiver ON
digitalWrite(PIN_RF_RX_PMOS, LOW); // turn VCC to RF receiver ON
pinMode(PIN_RF_RX_GND, OUTPUT); // Initialise in/output ports
pinMode(PIN_RF_RX_VCC, OUTPUT); // Initialise in/output ports
digitalWrite(PIN_RF_RX_GND, LOW); // turn GND to RF receiver ON
digitalWrite(PIN_RF_RX_VCC, HIGH); // turn VCC to RF receiver ON
if (PULLUP_RF_RX_DATA)
pinMode(PIN_RF_RX_DATA, INPUT_PULLUP); // Initialise in/output ports
delayMicroseconds(TRANSMITTER_STABLE_DELAY_US);
}

void disableRX()
{
// RX pins
pinMode(PIN_RF_RX_DATA, INPUT);
pinMode(PIN_RF_RX_NA, INPUT);
pinMode(PIN_RF_RX_PMOS, OUTPUT); // MOSFET, always output
pinMode(PIN_RF_RX_NMOS, OUTPUT); // MOSFET, always output
digitalWrite(PIN_RF_RX_PMOS, HIGH); // turn VCC to RF receiver OFF
digitalWrite(PIN_RF_RX_NMOS, LOW); // turn GND to RF receiver OFF
pinMode(PIN_RF_RX_VCC, INPUT);
pinMode(PIN_RF_RX_GND, INPUT);
}

void enableTX()
{
// TX Pins
pinMode(PIN_RF_TX_DATA, OUTPUT); // Initialise in/output ports
digitalWrite(PIN_RF_TX_DATA, LOW); // No signal yet
pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output
pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output
digitalWrite(PIN_RF_TX_NMOS, HIGH); // turn GND to TX receiver ON
digitalWrite(PIN_RF_TX_PMOS, LOW); // turn VCC to TX receiver ON
pinMode(PIN_RF_TX_GND, OUTPUT); // Initialise in/output ports
pinMode(PIN_RF_TX_VCC, OUTPUT); // Initialise in/output ports
digitalWrite(PIN_RF_TX_GND, LOW); // turn GND to TX receiver ON
digitalWrite(PIN_RF_TX_VCC, HIGH); // turn VCC to TX receiver ON
delayMicroseconds(TRANSMITTER_STABLE_DELAY_US);
}

void disableTX()
{
// TX Pins
delayMicroseconds(TRANSMITTER_STABLE_DELAY_US);
digitalWrite(PIN_RF_TX_DATA, LOW); // No more signal
pinMode(PIN_RF_TX_DATA, INPUT); //
pinMode(PIN_RF_TX_NMOS, OUTPUT); // MOSFET, always output
pinMode(PIN_RF_TX_PMOS, OUTPUT); // MOSFET, always output
digitalWrite(PIN_RF_TX_PMOS, HIGH); // turn VCC to TX receiver OFF
digitalWrite(PIN_RF_TX_NMOS, LOW); // turn GND to TX receiver OFF
pinMode(PIN_RF_TX_VCC, INPUT);
pinMode(PIN_RF_TX_GND, INPUT);
}
98 changes: 98 additions & 0 deletions RFLink/1_Radio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// ************************************* //
// * Arduino Project RFLink-esp * //
// * https://github.com/couin3/RFLink * //
// * 2018..2020 Stormteam - Marc RIVES * //
// * More details in RFLink.ino file * //
// ************************************* //

#ifndef Radio_h
#define Radio_h

#include <Arduino.h>

#define TRANSMITTER_STABLE_DELAY_US 500 // 500 // Delay to let the transmitter become stable (Note: Aurel RTX MID needs 500µS/0,5ms).
#define PULLUP_RF_RX_DATA_0 false // false // Sometimes a pullup in needed on RX data pin

// PIN Definition
//
extern uint8_t PIN_RF_RX_PMOS;
extern uint8_t PIN_RF_RX_NMOS;
extern uint8_t PIN_RF_RX_VCC;
extern uint8_t PIN_RF_RX_GND;
extern uint8_t PIN_RF_RX_NA;
extern uint8_t PIN_RF_RX_DATA;
extern uint8_t PIN_RF_TX_PMOS;
extern uint8_t PIN_RF_TX_NMOS;
extern uint8_t PIN_RF_TX_VCC;
extern uint8_t PIN_RF_TX_GND;
extern uint8_t PIN_RF_TX_DATA;
extern boolean PULLUP_RF_RX_DATA;

#ifdef ESP8266
// ESP8266 D1 Mini
#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_RX_NMOS_0 D5 // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_RX_VCC_0 NOT_A_PIN // Power to the receiver on this pin
#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin
#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input
#define PIN_RF_RX_DATA_0 D6 // On this input, the 433Mhz-RF signal is received. LOW when no signal.
#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_TX_NMOS_0 D7 // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_TX_VCC_0 NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin
#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin
#define PIN_RF_TX_DATA_0 D4 // Data to the 433Mhz transmitter on this pin
#endif

#ifdef ESP32
#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_RX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_RX_VCC_0 NOT_A_PIN // Power to the receiver on this pin
#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin
#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input
#define PIN_RF_RX_DATA_0 NOT_A_PIN // On this input, the 433Mhz-RF signal is received. LOW when no signal.
#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_TX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_TX_VCC_0 NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin
#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin
#define PIN_RF_TX_DATA_0 NOT_A_PIN // Data to the 433Mhz transmitter on this pin
#endif

#ifdef __AVR_ATmega328P__
#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_RX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_RX_VCC_0 NOT_A_PIN // Power to the receiver on this pin
#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin
#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input
#define PIN_RF_RX_DATA_0 2 // On this input, the 433Mhz-RF signal is received. LOW when no signal.
#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_TX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_TX_VCC_0 NOT_A_PIN // +5 volt / Vcc power to the transmitter on this pin
#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin
#define PIN_RF_TX_DATA_0 NOT_A_PIN // Data to the 433Mhz transmitter on this pin
#endif

#ifdef __AVR_ATmega2560__
#define PIN_RF_RX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_RX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_RX_VCC_0 16 // Power to the receiver on this pin
#define PIN_RF_RX_GND_0 NOT_A_PIN // Ground to the receiver on this pin
#define PIN_RF_RX_NA_0 NOT_A_PIN // Alt. RX_DATA. Forced as input
#define PIN_RF_RX_DATA_0 19 // On this input, the 433Mhz-RF signal is received. LOW when no signal.
#define PIN_RF_TX_PMOS_0 NOT_A_PIN // High Side P-MOSFET, active on LOW level
#define PIN_RF_TX_NMOS_0 NOT_A_PIN // Low Side N-MOSFET, active on HIGH level
#define PIN_RF_TX_VCC_0 15 // +5 volt / Vcc power to the transmitter on this pin
#define PIN_RF_TX_GND_0 NOT_A_PIN // Ground power to the transmitter on this pin
#define PIN_RF_TX_DATA_0 14 // Data to the 433Mhz transmitter on this pin
#endif

enum Radio_State
{
Radio_OFF,
Radio_RX,
Radio_TX,
Radio_NA
};

void set_Radio_mode(Radio_State new_state);

#endif // Radio_h
127 changes: 125 additions & 2 deletions RFLink/2_Signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ************************************* //

#include <Arduino.h>
#include "1_Radio.h"
#include "2_Signal.h"
#include "5_Plugin.h"

Expand Down Expand Up @@ -256,7 +257,7 @@ boolean FetchSignal()
*/
/*********************************************************************************************\
Send rawsignal buffer to RF * DEPRICATED * DO NOT USE
\*********************************************************************************************/
\*********************************************************************************************/
/*
void RawSendRF(void) { // * DEPRICATED * DO NOT USE *
int x;
Expand Down Expand Up @@ -285,4 +286,126 @@ boolean FetchSignal()
// RFLinkHW();
}
*/
/*********************************************************************************************/

/*********************************************************************************************\
Send bitstream to RF - Plugin 004 (Newkaku) special version
\*********************************************************************************************/
void AC_Send(unsigned long data, byte cmd)
{
#define AC_FPULSE 260 // Pulse width in microseconds
#define AC_FRETRANS 5 // Number of code retransmissions

// Serial.println("Send AC");
// Serial.println(data, HEX);
// Serial.println(cmd, HEX);

unsigned long bitstream = 0L;
byte command = 0;
// prepare data to send
for (unsigned short i = 0; i < 32; i++)
{ // reverse data bits
bitstream <<= 1;
bitstream |= (data & B1);
data >>= 1;
}
if (cmd != 0xff)
{ // reverse dim bits
for (unsigned short i = 0; i < 4; i++)
{
command <<= 1;
command |= (cmd & B1);
cmd >>= 1;
}
}
// send bits
for (byte nRepeat = 0; nRepeat < AC_FRETRANS; nRepeat++)
{
data = bitstream;
if (cmd != 0xff)
cmd = command;
digitalWrite(PIN_RF_TX_DATA, HIGH);
//delayMicroseconds(fpulse); //335
delayMicroseconds(335);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE * 10 + (AC_FPULSE >> 1)); //335*9=3015 //260*10=2600
for (unsigned short i = 0; i < 32; i++)
{
if (i == 27 && cmd != 0xff)
{ // DIM command, send special DIM sequence TTTT replacing on/off bit
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE);
}
else
switch (data & B1)
{
case 0:
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE * 5); // 335*3=1005 260*5=1300 260*4=1040
break;
case 1:
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE * 5);
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE);
break;
}
//Next bit
data >>= 1;
}
// send dim bits when needed
if (cmd != 0xff)
{ // need to send DIM command bits
for (unsigned short i = 0; i < 4; i++)
{ // 4 bits
switch (cmd & B1)
{
case 0:
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE * 5); // 335*3=1005 260*5=1300
break;
case 1:
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE * 5);
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE);
break;
}
//Next bit
cmd >>= 1;
}
}
//Send termination/synchronisation-signal. Total length: 32 periods
digitalWrite(PIN_RF_TX_DATA, HIGH);
delayMicroseconds(AC_FPULSE);
digitalWrite(PIN_RF_TX_DATA, LOW);
delayMicroseconds(AC_FPULSE * 40); //31*335=10385 40*260=10400
}
// End transmit
}
/*********************************************************************************************/
13 changes: 12 additions & 1 deletion RFLink/2_Signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@
#define Signal_h

#include <Arduino.h>
#include "RFLink.h"

#define RAW_BUFFER_SIZE 292 // 292 // Maximum number of pulses that is received in one go.
#define MIN_RAW_PULSES 50 // 50 // Minimal number of bits that need to have been received before we spend CPU time on decoding the signal.
#define RAWSIGNAL_SAMPLE_RATE 32 // 32 // =8 bits. Sample width / resolution in uSec for raw RF pulses.
#define SIGNAL_SEEK_TIMEOUT_MS 25 // 25 // After this time in mSec, RF signal will be considered absent.
#define SIGNAL_MIN_PREAMBLE_US 3000 // 3000 // After this time in mSec, a RF signal will be considered to have started.
#define MIN_PULSE_LENGTH_US 100 // 25! // Pulses shorter than this value in uSec. will be seen as garbage and not taken as actual pulses.
#define SIGNAL_END_TIMEOUT_US 5000 // 4500 // After this time in uSec, the RF signal will be considered to have stopped.
#define SIGNAL_REPEAT_TIME_MS 250 // 500 // Time in mSec. in which the same RF signal should not be accepted again. Filters out retransmits.
#define SCAN_HIGH_TIME_MS 50 // 50 // time interval in ms. fast processing for background tasks

struct RawSignalStruct // Raw signal variabelen places in a struct
{
Expand All @@ -34,4 +43,6 @@ boolean ScanEvent(void);
// void RFLinkHW(void);
// void RawSendRF(void);

void AC_Send(unsigned long data, byte cmd);

#endif
Loading

0 comments on commit 5a23684

Please sign in to comment.