Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Platformio stuff
.pio

# Mac stuff
.DS_Store

Expand Down
336 changes: 266 additions & 70 deletions RCSwitch.cpp

Large diffs are not rendered by default.

39 changes: 27 additions & 12 deletions RCSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- Frank Oltmanns / <first name>.<last name>(at)gmail(dot)com
- Max Horn / max(at)quendi(dot)de
- Robert ter Vehn / <first name>.<last name>(at)gmail(dot)com
Project home: https://github.com/sui77/rc-switch/
This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -58,13 +58,20 @@

// Number of maximum high/Low changes per packet.
// We can handle up to (unsigned long) => 32 bit * 2 H/L changes per bit + 2 for sync
#define RCSWITCH_MAX_CHANGES 67
// Для keeloq нужно увеличить RCSWITCH_MAX_CHANGES до 23+1+66*2+1=157
#define RCSWITCH_MAX_CHANGES 67 // default 67

// separationLimit: minimum microseconds between received codes, closer codes are ignored.
// according to discussion on issue #14 it might be more suitable to set the separation
// limit to the same time as the 'low' part of the sync signal for the current protocol.
// should be set to the minimum value of pulselength * the sync signal
#define RCSWITCH_SEPARATION_LIMIT 4100

class RCSwitch {

public:
RCSwitch();

void switchOn(int nGroupNumber, int nSwitchNumber);
void switchOff(int nGroupNumber, int nSwitchNumber);
void switchOn(const char* sGroup, int nSwitchNumber);
Expand All @@ -77,29 +84,31 @@ class RCSwitch {
void switchOff(char sGroup, int nDevice);

void sendTriState(const char* sCodeWord);
void send(unsigned long code, unsigned int length);
void send(unsigned long long code, unsigned int length);
void send(const char* sCodeWord);

#if not defined( RCSwitchDisableReceiving )
void enableReceive(int interrupt);
void enableReceive();
void disableReceive();
bool available();
void resetAvailable();

unsigned long getReceivedValue();
unsigned long long getReceivedValue();
unsigned int getReceivedBitlength();
unsigned int getReceivedDelay();
unsigned int getReceivedProtocol();
unsigned int* getReceivedRawdata();
uint8_t getNumProtos();
#endif

void enableTransmit(int nTransmitterPin);
void disableTransmit();
void setPulseLength(int nPulseLength);
void setRepeatTransmit(int nRepeatTransmit);
#if not defined( RCSwitchDisableReceiving )
void setReceiveTolerance(int nPercent);
void setReceiveProtocolMask(unsigned long long mask);
#endif

/**
Expand All @@ -120,8 +129,11 @@ class RCSwitch {
struct Protocol {
/** base pulse length in microseconds, e.g. 350 */
uint16_t pulseLength;
uint8_t PreambleFactor;
HighLow Preamble;
uint8_t HeaderFactor;
HighLow Header;

HighLow syncFactor;
HighLow zero;
HighLow one;

Expand All @@ -142,6 +154,7 @@ class RCSwitch {
* FOO.low*pulseLength microseconds.
*/
bool invertedSignal;
uint16_t Guard;
};

void setProtocol(Protocol protocol);
Expand All @@ -162,23 +175,25 @@ class RCSwitch {
#endif
int nTransmitterPin;
int nRepeatTransmit;

Protocol protocol;

#if not defined( RCSwitchDisableReceiving )
static int nReceiveTolerance;
volatile static unsigned long nReceivedValue;
volatile static unsigned long long nReceivedValue;
volatile static unsigned long long nReceiveProtocolMask;
volatile static unsigned int nReceivedBitlength;
volatile static unsigned int nReceivedDelay;
volatile static unsigned int nReceivedProtocol;
const static unsigned int nSeparationLimit;
/*
/*
* timings[0] contains sync timing, followed by a number of bits
*/
static unsigned int timings[RCSWITCH_MAX_CHANGES];
// буфер длительностей последних четырех пакетов, [0] - последний
static unsigned int buftimings[4];
#endif


};

#endif
1 change: 1 addition & 0 deletions examples/ReceiveDemo_Advanced/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@
RCSwitch mySwitch = RCSwitch();

void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
Serial.begin(MONITOR_SPEED);

delay(1000);
Serial.print("Listening on pin ");
Serial.println(RCSWITCH_RECIEVE_PIN);

pinMode(RCSWITCH_RECIEVE_PIN, INPUT);
mySwitch.enableReceive(RCSWITCH_RECIEVE_PIN); // see platformio_shared.ini
}

void loop() {
Expand Down
1 change: 1 addition & 0 deletions examples/ReceiveDemo_Simple/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
RCSwitch mySwitch = RCSwitch();

void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
Serial.begin(MONITOR_SPEED);
delay(1000);
Serial.print("Listening on pin ");
Serial.println(RCSWITCH_RECIEVE_PIN);

pinMode(RCSWITCH_RECIEVE_PIN, INPUT);
mySwitch.enableReceive(RCSWITCH_RECIEVE_PIN); // see platformio_shared.ini
}

void loop() {
Expand Down
1 change: 1 addition & 0 deletions examples/SendDemo/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ RCSwitch mySwitch = RCSwitch();

void setup() {

Serial.begin(9600);
Serial.begin(MONITOR_SPEED);

// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
mySwitch.enableTransmit(RCSWITCH_TRANSMIT_PIN); // see platformio_shared.ini

// Optional set protocol (default is 1, will work for most outlets)
// mySwitch.setProtocol(2);
Expand Down
1 change: 1 addition & 0 deletions examples/TypeA_WithDIPSwitches/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RCSwitch mySwitch = RCSwitch();
void setup() {

// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
mySwitch.enableTransmit(RCSWITCH_TRANSMIT_PIN); // see platformio_shared.ini

// Optional set pulse length.
// mySwitch.setPulseLength(320);
Expand Down
1 change: 1 addition & 0 deletions examples/TypeA_WithDIPSwitches_Lightweight/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
https://github.com/sui77/rc-switch/
*/

int RCLpin = 7;
int RCLpin = RCSWITCH_TRANSMIT_PIN; // see platformio_shared.ini;

void setup() {
pinMode(RCLpin, OUTPUT);
Expand Down
1 change: 1 addition & 0 deletions examples/TypeB_WithRotaryOrSlidingSwitches/platformio.ini
1 change: 1 addition & 0 deletions examples/TypeC_Intertechno/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ RCSwitch mySwitch = RCSwitch();

void setup() {

// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
mySwitch.enableTransmit(RCSWITCH_TRANSMIT_PIN); // see platformio_shared.ini

// Optional set pulse length.
// mySwitch.setPulseLength(320);
Expand All @@ -37,4 +36,4 @@ void loop() {
// Wait another second
delay(1000);

}
}
1 change: 1 addition & 0 deletions examples/TypeD_REV/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ RCSwitch mySwitch = RCSwitch();

void setup() {

// Transmitter is connected to Arduino Pin #10
mySwitch.enableTransmit(10);
mySwitch.enableTransmit(RCSWITCH_TRANSMIT_PIN); // see platformio_shared.ini

// set pulse length.
mySwitch.setPulseLength(360);
Expand Down
1 change: 1 addition & 0 deletions examples/Webserver/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ EthernetServer server(80); // Server Port 80

// RCSwitch configuration
RCSwitch mySwitch = RCSwitch();
int RCTransmissionPin = 7;
int RCTransmissionPin = RCSWITCH_TRANSMIT_PIN; // see platformio_shared.ini

// More to do...
// You should also modify the processCommand() and
Expand Down Expand Up @@ -151,4 +151,4 @@ char* httpServer() {
return sReturnCommand;
}
return '\0';
}
}
13 changes: 13 additions & 0 deletions examples/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
this_lib = ../..
extra_configs = ../../platformio_shared.ini
49 changes: 49 additions & 0 deletions platformio_shared.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[platformio]
default_envs = lolin32
;default_envs = esp32c3_cdc

[common]
framework = arduino
monitor_speed = 921600
build_flags =
-D MONITOR_SPEED=${common.monitor_speed}
lib_deps =
${platformio.this_lib}

[env:lolin32]
platform = espressif32
board = lolin32
upload_protocol = esptool
framework = ${common.framework}
lib_deps = ${common.lib_deps}
monitor_speed = ${common.monitor_speed}
build_flags =
${common.build_flags}
-D RCSWITCH_RECIEVE_PIN=16
-D RCSWITCH_TRANSMIT_PIN=17


[env:esp32c3_cdc]
platform = espressif32
board = airm2m_core_esp32c3
upload_protocol = esptool
framework = ${common.framework}
lib_deps = ${common.lib_deps}
monitor_speed = ${common.monitor_speed}
build_flags =
-D CONFIG_ESP_CONSOLE_UART=1 ; settings for esp32c3 without uart
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
${common.build_flags}
-D RCSWITCH_RECIEVE_PIN=1
-D RCSWITCH_TRANSMIT_PIN=0