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
20 changes: 19 additions & 1 deletion RCSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ RCSwitch::RCSwitch() {
this->nTransmitterPin = -1;
this->setRepeatTransmit(10);
this->setProtocol(1);
this->setSyncFactorFirst(false);
#if not defined( RCSwitchDisableReceiving )
this->nReceiverInterrupt = -1;
this->setReceiveTolerance(60);
Expand Down Expand Up @@ -158,6 +159,14 @@ void RCSwitch::setPulseLength(int nPulseLength) {
this->protocol.pulseLength = nPulseLength;
}

/**
* Sets sync factor to be sent first, before the code word
*/
void RCSwitch::setSyncFactorFirst(bool syncFactor) {
this->syncFactorFirst = syncFactor;
}


/**
* Sets Repeat Transmits
*/
Expand Down Expand Up @@ -508,13 +517,22 @@ void RCSwitch::send(unsigned long code, unsigned int length) {
#endif

for (int nRepeat = 0; nRepeat < nRepeatTransmit; nRepeat++) {

if (this->syncFactorFirst) {
this->transmit(protocol.syncFactor);
}

for (int i = length-1; i >= 0; i--) {
if (code & (1L << i))
this->transmit(protocol.one);
else
this->transmit(protocol.zero);
}
this->transmit(protocol.syncFactor);

if (!this->syncFactorFirst) {
this->transmit(protocol.syncFactor);
}

}

// Disable transmit after sending (i.e., for inverted protocols)
Expand Down
2 changes: 2 additions & 0 deletions RCSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class RCSwitch {
void enableTransmit(int nTransmitterPin);
void disableTransmit();
void setPulseLength(int nPulseLength);
void setSyncFactorFirst(bool syncFactorFirst);
void setRepeatTransmit(int nRepeatTransmit);
#if not defined( RCSwitchDisableReceiving )
void setReceiveTolerance(int nPercent);
Expand Down Expand Up @@ -162,6 +163,7 @@ class RCSwitch {
#endif
int nTransmitterPin;
int nRepeatTransmit;
bool syncFactorFirst = false;

Protocol protocol;

Expand Down