Library to switch 433MHz remote controlled sockets.

Dependents:   RCswitch_example

Embed: (wiki syntax)

« Back to documentation index

RCSwitch Class Reference

RCSwitch Class. More...

#include <RCSwitch.h>

Public Member Functions

 RCSwitch (PinName tx, PinName rx)
 Class constructor.
 RCSwitch (PinName tx, PinName rx, PinName rx_en)
 Class constructor.
void setProtocol (int nProtocol)
 Set protocol to be used in transmission.
void setProtocol (int nProtocol, int nPulseLength)
 Set protocol to be used in transmission.
void switchOn (char *sGroup, char *sDevice)
 Switch a remote switch on (Type A with 10 pole DIP switches)
void switchOff (char *sGroup, char *sDevice)
 Switch a remote switch off (Type A with 10 pole DIP switches)
void switchOn (char *sGroup, int nChannelCode)
 Deprecated, use switchOn(char* sGroup, char* sDevice) instead! Switch a remote switch on (Type A with 10 pole DIP switches)
void switchOff (char *sGroup, int nChannelCode)
 Deprecated, use switchOff(char* sGroup, char* sDevice) instead! Switch a remote switch off (Type A with 10 pole DIP switches)
void switchOn (int nAddressCode, int nChannelCode)
 Switch a remote switch on (Type B with two rotary/sliding switches)
void switchOff (int nAddressCode, int nChannelCode)
 Switch a remote switch off (Type B with two rotary/sliding switches)
void switchOn (char sFamily, int nGroup, int nDevice)
 Switch a remote switch on (Type C Intertechno)
void switchOff (char sFamily, int nGroup, int nDevice)
 Switch a remote switch off (Type C Intertechno)
void switchOn (char sGroup, int nDevice)
 Switch a remote switch off (Type D REV)
void switchOff (char sGroup, int nDevice)
 Switch a remote switch on (Type D REV)
void sendTriState (char *Code)
 Sends a codeword.
void send (unsigned long Code, unsigned int length)
 Converts a CodeWord to a set Length and sends it.
void send (char *Code)
 Sends a CodeWord.
void enableReceive ()
 Enable receiving data This clear message storage and enables the interrupt, which may enable the port.
void disableReceive ()
 Disable receiving data This disables the interrupt which may disable the port.
bool available ()
 Message availiable.
void resetAvailable ()
 Clear Messages.
unsigned long getReceivedValue ()
 Get Message Value.
unsigned int getReceivedBitlength ()
 Get bit length.
unsigned int getReceivedDelay ()
 Get the delay unsigned int The delay.
unsigned int getReceivedProtocol ()
 Get Protocol.
unsigned int * getReceivedRawdata ()
 Get Raw data.
void enableTransmit ()
 Enable the transmitter.
void disableTransmit ()
 Disable the transmitter.
void setPulseLength (int nPulseLength)
 Set pulse length in micro seconds.
void setRepeatTransmit (int nRepeatTransmit)
 Set number of times to repeat transmission.
void setReceiveTolerance (int nPercent)
 Set receive tolerance.

Static Public Attributes

static int nReceiveTolerance = 60
 Tolerance of the receiver.
static unsigned long nReceivedValue = NULL
 Value Recieved.
static unsigned int nReceivedBitlength = 0
 Length in bits of value reveived.
static unsigned int nReceivedDelay = 0
 Delay in receive.
static unsigned int nReceivedProtocol = 0
 Protocol of message recieved.
static bool ReceiveEnabled = true
 Receive enabled.
static bool TransmitEnable = true
 Transmit enabled.
static bool TransmitEnablePin = false
 Pin of transmitter enable pin.
static unsigned int timings [RCSWITCH_MAX_CHANGES]
 timings[0] contains sync timing, followed by a number of bits

Detailed Description

RCSwitch Class.

Example:

 #include "mbed.h"
 #include "RCSwitch.h "

 // This Example should only do one of either transmit or receive
 //#define TRANSMIT
 #define RECEIVE

 Serial pc(USBTX, USBRX); // tx, rx
 RCSwitch mySwitch = RCSwitch( p11, p21 ); //tx, rx

 int main()
 {
     pc.printf("Setup");
     while(1) {
         #ifdef RECEIVE
         if (mySwitch.available()) {

             int value = mySwitch.getReceivedValue();

             if (value == 0) {
                 pc.printf("Unknown encoding");
             } else {
                 pc.printf("Received %d \n\r", mySwitch.getReceivedValue());
                 pc.printf(" bit %d \n\r", mySwitch.getReceivedBitlength());
                 pc.printf(" Protocol: %d \n\r", mySwitch.getReceivedProtocol());
             }
             mySwitch.resetAvailable();
         }
         #endif
         #ifdef TRANSMIT
         // Example: TypeA_WithDIPSwitches
         mySwitch.switchOn("11111", "00010");
         wait(1);
         mySwitch.switchOn("11111", "00010");
         wait(1);

         // Same switch as above, but using decimal code
         mySwitch.send(5393, 24);
         wait(1);
         mySwitch.send(5396, 24);
         wait(1);

         // Same switch as above, but using binary code
         mySwitch.send("000000000001010100010001");
         wait(1);
         mySwitch.send("000000000001010100010100");
         wait(1);

         // Same switch as above, but tri-state code
         mySwitch.sendTriState("00000FFF0F0F");
         wait(1);
         mySwitch.sendTriState("00000FFF0FF0");
         wait(1);
         #endif
     }
 }

Definition at line 113 of file RCSwitch.h.


Constructor & Destructor Documentation

RCSwitch ( PinName  tx,
PinName  rx 
)

Class constructor.

The constructor assigns the specified pinout, attatches an Interrupt to the receive pin. for the LPC1768 this must not be pins 19 and 20. For the KL25Z, the pin must be on ports A or C

Parameters:
txTransmitter pin of the RF module.
rxReceiver pin of the RF module.

Definition at line 48 of file RCSwitch.cpp.

RCSwitch ( PinName  tx,
PinName  rx,
PinName  tx_en 
)

Class constructor.

The constructor assigns the specified pinout, attatches an Interrupt to the receive pin. for the LPC1768 this must not be pins 19 and 20. For the KL25Z, the pin must be on ports A or C

Parameters:
txTransmitter pin of the RF module.
rxReceiver pin of the RF module.
tx_enEnable pin of the transmitter

Definition at line 76 of file RCSwitch.cpp.


Member Function Documentation

bool available (  )

Message availiable.

Returns:
bool Message availiability

Definition at line 652 of file RCSwitch.cpp.

void disableReceive (  )

Disable receiving data This disables the interrupt which may disable the port.

Definition at line 647 of file RCSwitch.cpp.

void disableTransmit (  )

Disable the transmitter.

Definition at line 164 of file RCSwitch.cpp.

void enableReceive (  )

Enable receiving data This clear message storage and enables the interrupt, which may enable the port.

Enable receiving data.

Definition at line 636 of file RCSwitch.cpp.

void enableTransmit (  )

Enable the transmitter.

Definition at line 153 of file RCSwitch.cpp.

unsigned int getReceivedBitlength (  )

Get bit length.

Returns:
unsigned int Number of bits received

Definition at line 664 of file RCSwitch.cpp.

unsigned int getReceivedDelay (  )

Get the delay unsigned int The delay.

Definition at line 668 of file RCSwitch.cpp.

unsigned int getReceivedProtocol (  )

Get Protocol.

Returns:
unsigned int The protocol used in the message

Definition at line 672 of file RCSwitch.cpp.

unsigned int * getReceivedRawdata (  )

Get Raw data.

Returns:
unsinged int The raw data of the message recieved

Definition at line 676 of file RCSwitch.cpp.

unsigned long getReceivedValue (  )

Get Message Value.

Returns:
unsigned long The value of the message received

Definition at line 660 of file RCSwitch.cpp.

void resetAvailable (  )

Clear Messages.

Definition at line 656 of file RCSwitch.cpp.

void send ( unsigned long  Code,
unsigned int  length 
)

Converts a CodeWord to a set Length and sends it.

Parameters:
CodeCodeWord to be sent
lengthLength of CodeWord to send

Definition at line 505 of file RCSwitch.cpp.

void send ( char *  Code )

Sends a CodeWord.

Parameters:
CodeCodeWord to send

Definition at line 509 of file RCSwitch.cpp.

void sendTriState ( char *  sCodeWord )

Sends a codeword.

Parameters:
sCodeWordCodeword to be sent

Definition at line 484 of file RCSwitch.cpp.

void setProtocol ( int  nProtocol,
int  nPulseLength 
)

Set protocol to be used in transmission.

Parameters:
nProtocolProtocol type ot transmit
nPulseLengthLength of each pulse

Definition at line 119 of file RCSwitch.cpp.

void setProtocol ( int  nProtocol )

Set protocol to be used in transmission.

Parameters:
nProtocolProtocol type ot transmit

Definition at line 101 of file RCSwitch.cpp.

void setPulseLength ( int  nPulseLength )

Set pulse length in micro seconds.

Parameters:
nPulseLengththe Length of the pulse

Definition at line 129 of file RCSwitch.cpp.

void setReceiveTolerance ( int  nPercent )

Set receive tolerance.

Parameters:
nPercentPercentage tolerance of the receiver

Definition at line 145 of file RCSwitch.cpp.

void setRepeatTransmit ( int  nRepeatTransmit )

Set number of times to repeat transmission.

Parameters:
nRepeatNumber of repeats

Definition at line 137 of file RCSwitch.cpp.

void switchOff ( char *  sGroup,
int  nChannel 
)

Deprecated, use switchOff(char* sGroup, char* sDevice) instead! Switch a remote switch off (Type A with 10 pole DIP switches)

Parameters:
sGroupCode of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
nChannelCodeNumber of the switch itself (1..5)

Definition at line 253 of file RCSwitch.cpp.

void switchOff ( int  nAddressCode,
int  nChannelCode 
)

Switch a remote switch off (Type B with two rotary/sliding switches)

Parameters:
nAddressCodeNumber of the switch group (1..4)
nChannelCodeNumber of the switch itself (1..4)

Definition at line 230 of file RCSwitch.cpp.

void switchOff ( char  sFamily,
int  nGroup,
int  nDevice 
)

Switch a remote switch off (Type C Intertechno)

Parameters:
sFamilyFamilycode (a..f)
nGroupNumber of group (1..4)
nDeviceNumber of device (1..4)

Definition at line 210 of file RCSwitch.cpp.

void switchOff ( char  sGroup,
int  nDevice 
)

Switch a remote switch on (Type D REV)

Switch a remote switch off (Type D REV)

Parameters:
sGroupCode of the switch group (A,B,C,D)
nDeviceNumber of the switch itself (1..3)

Definition at line 188 of file RCSwitch.cpp.

void switchOff ( char *  sGroup,
char *  sDevice 
)

Switch a remote switch off (Type A with 10 pole DIP switches)

Parameters:
sGroupCode of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
sDeviceCode of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")

Definition at line 274 of file RCSwitch.cpp.

void switchOn ( char  sGroup,
int  nDevice 
)

Switch a remote switch off (Type D REV)

Switch a remote switch on (Type D REV)

Parameters:
sGroupCode of the switch group (A,B,C,D)
nDeviceNumber of the switch itself (1..3)

Definition at line 178 of file RCSwitch.cpp.

void switchOn ( int  nAddressCode,
int  nChannelCode 
)

Switch a remote switch on (Type B with two rotary/sliding switches)

Parameters:
nAddressCodeNumber of the switch group (1..4)
nChannelCodeNumber of the switch itself (1..4)

Definition at line 220 of file RCSwitch.cpp.

void switchOn ( char  sFamily,
int  nGroup,
int  nDevice 
)

Switch a remote switch on (Type C Intertechno)

Parameters:
sFamilyFamilycode (a..f)
nGroupNumber of group (1..4)
nDeviceNumber of device (1..4)

Definition at line 199 of file RCSwitch.cpp.

void switchOn ( char *  sGroup,
int  nChannel 
)

Deprecated, use switchOn(char* sGroup, char* sDevice) instead! Switch a remote switch on (Type A with 10 pole DIP switches)

Parameters:
sGroupCode of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
nChannelCodeNumber of the switch itself (1..5)

Definition at line 241 of file RCSwitch.cpp.

void switchOn ( char *  sGroup,
char *  sDevice 
)

Switch a remote switch on (Type A with 10 pole DIP switches)

Parameters:
sGroupCode of the switch group (refers to DIP switches 1..5 where "1" = on and "0" = off, if all DIP switches are on it's "11111")
sDeviceCode of the switch device (refers to DIP switches 6..10 (A..E) where "1" = on and "0" = off, if all DIP switches are on it's "11111")

Definition at line 264 of file RCSwitch.cpp.


Field Documentation

unsigned int nReceivedBitlength = 0 [static]

Length in bits of value reveived.

Definition at line 305 of file RCSwitch.h.

unsigned int nReceivedDelay = 0 [static]

Delay in receive.

Definition at line 306 of file RCSwitch.h.

unsigned int nReceivedProtocol = 0 [static]

Protocol of message recieved.

Definition at line 307 of file RCSwitch.h.

unsigned long nReceivedValue = NULL [static]

Value Recieved.

Definition at line 304 of file RCSwitch.h.

int nReceiveTolerance = 60 [static]

Tolerance of the receiver.

Definition at line 303 of file RCSwitch.h.

bool ReceiveEnabled = true [static]

Receive enabled.

Definition at line 308 of file RCSwitch.h.

unsigned int timings [static]

timings[0] contains sync timing, followed by a number of bits

Definition at line 311 of file RCSwitch.h.

bool TransmitEnable = true [static]

Transmit enabled.

Definition at line 309 of file RCSwitch.h.

bool TransmitEnablePin = false [static]

Pin of transmitter enable pin.

Definition at line 310 of file RCSwitch.h.