diff --git a/RCSwitch.cpp b/RCSwitch.cpp index 99d3cc1..4062363 100644 --- a/RCSwitch.cpp +++ b/RCSwitch.cpp @@ -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); @@ -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 */ @@ -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) diff --git a/RCSwitch.h b/RCSwitch.h index b7755e0..1e818e0 100644 --- a/RCSwitch.h +++ b/RCSwitch.h @@ -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); @@ -162,6 +163,7 @@ class RCSwitch { #endif int nTransmitterPin; int nRepeatTransmit; + bool syncFactorFirst = false; Protocol protocol;