diff --git a/src/extras/RFControl.cpp b/src/extras/RFControl.cpp index ed89819..0f4d467 100644 --- a/src/extras/RFControl.cpp +++ b/src/extras/RFControl.cpp @@ -69,11 +69,12 @@ void RFControl::start(uint32_t *data, int nData, uint8_t nCycles, uint8_t tickTi void RFControl::clear(){ data.clear(); + lowWord=true; } /////////////////// -void RFControl::add(uint16_t onTime, uint16_t offTime){ +void RFControl::add(uint32_t onTime, uint32_t offTime){ phase(onTime,HIGH); phase(offTime,LOW); @@ -81,16 +82,19 @@ void RFControl::add(uint16_t onTime, uint16_t offTime){ /////////////////// -void RFControl::phase(uint16_t nTicks, uint8_t phase){ +void RFControl::phase(uint32_t nTicks, uint8_t phase){ - uint32_t ticks=nTicks&0x7FFF; + while(nTicks>0){ // create as many repeated phases as needed to accomodate duration of nTicks + uint32_t ticks=nTicks>0x7FFF?0x7FFF:nTicks; + nTicks-=ticks; - if(lowWord) - data.push_back(ticks | (phase?(1<<15):0)); - else - data.back()|=ticks<<16 | (phase?(1<<31):0); - - lowWord=!lowWord; + if(lowWord) + data.push_back(ticks | (phase?(1<<15):0)); + else + data.back()|=ticks<<16 | (phase?(1<<31):0); + + lowWord=!lowWord; + } } /////////////////// diff --git a/src/extras/RFControl.h b/src/extras/RFControl.h index b840f37..95c23be 100644 --- a/src/extras/RFControl.h +++ b/src/extras/RFControl.h @@ -22,8 +22,8 @@ class RFControl { void start(uint8_t nCycles=1, uint8_t tickTime=1); // starts transmission of pulses from internal data structure, repeated for numCycles, where each tick in pulse is tickTime microseconds long void clear(); // clears transmitter memory - void add(uint16_t onTime, uint16_t offTime); // adds pulse of onTime ticks HIGH followed by offTime ticks LOW - void phase(uint16_t nTicks, uint8_t phase); // adds either a HIGH phase or LOW phase lasting numTicks ticks + void add(uint32_t onTime, uint32_t offTime); // adds pulse of onTime ticks HIGH followed by offTime ticks LOW + void phase(uint32_t nTicks, uint8_t phase); // adds either a HIGH phase or LOW phase lasting numTicks ticks }; // Helper macro for creating your own storage of uint32_t data array elements - used with first variation of start() above diff --git a/src/extras/extras.ino b/src/extras/extras.ino index c709135..795c6ad 100644 --- a/src/extras/extras.ino +++ b/src/extras/extras.ino @@ -10,23 +10,33 @@ void setup() { Serial.println("\n\nHomeSpan RF Transmitter Example"); - RFControl rf(18); // create an instance of RFControl with signal output to pin 6 + RFControl rf(17); // create an instance of RFControl with signal output to pin 17 -#define NPOINTS 3 - - uint32_t data[NPOINTS]; + rf.clear(); - for(int i=0;i