diff --git a/src/extras/RFControl.cpp b/src/extras/RFControl.cpp index bfb195d..5938089 100644 --- a/src/extras/RFControl.cpp +++ b/src/extras/RFControl.cpp @@ -32,7 +32,12 @@ RFControl::RFControl(int pin){ /////////////////// void RFControl::start(uint8_t _numCycles, uint8_t tickTime){ - pRMT[pCount]=0; // load end-marker (zero bytes) into RMT memory + + if(pCount%2==0) // if next entry is lower 16 bits of 32-bit memory + pRMT[pCount/2]=0; // set memory to zero (end-marker) + else + pRMT[pCount/2]&=0xFFFF; // else preserve lower 16 bits and zero our upper 16 bits + REG_WRITE(GPIO_ENABLE_W1TS_REG,1<32767 || offTime<1 || onTime>32767 || onTime<1){ - Serial.print("\n*** ERROR: Request to add RF Control pulse with onTime="); - Serial.print(onTime); - Serial.print(" and offTime="); - Serial.print(offTime); + if(numTicks>32767 || numTicks<1){ + Serial.print("\n*** ERROR: Request to add RF Control entry with numTicks="); + Serial.print(numTicks); Serial.print(" is out of allowable range: 1-32767\n\n"); } else { + + int index=pCount/2; - pRMT[pCount++]=(offTime<<16)+onTime+(1<<15); // load pulse information into RMT memory and increment pointer + if(pCount%2==0) + pRMT[index]=numTicks | (int)phase; // load entry into lower 16 bits of 32-bit memory + else + pRMT[index]=pRMT[index] & 0xFFFF | (numTicks<<16) | ((int)phase<<16); // load entry into upper 16 bits of 32-bit memory, preserving lower 16 bits + + pCount++; } + } /////////////////// @@ -82,3 +101,5 @@ boolean RFControl::configured=false; volatile int RFControl::numCycles; uint32_t *RFControl::pRMT=(uint32_t *)RMT_CHANNEL_MEM(0); int RFControl::pCount=0; +RFControl::PHASE RF_LOW=RFControl::PHASE::Low; +RFControl::PHASE RF_HIGH=RFControl::PHASE::High; diff --git a/src/extras/RFControl.h b/src/extras/RFControl.h index 9f35d15..99a3433 100644 --- a/src/extras/RFControl.h +++ b/src/extras/RFControl.h @@ -12,11 +12,20 @@ class RFControl { static int pCount; static void eot_int(void *arg); - public: + public: + + enum class PHASE { + Low=0, + High=0x8000 + }; + RFControl(int pin); // creates transmitter on pin static void clear(); // clears transmitter memory static void add(uint16_t onTime, uint16_t offTime); // adds pulse of onTime ticks HIGH followed by offTime ticks LOW + static void phase(uint16_t numTicks, PHASE phase); // adds either a HIGH phase or LOW phase lasting numTicks ticks void start(uint8_t _numCycles, uint8_t tickTime=1); // starts transmission of pulses, repeated for numCycles, where each tick in pulse is tickTime microseconds long }; +extern RFControl::PHASE RF_LOW; +extern RFControl::PHASE RF_HIGH; diff --git a/src/extras/extras.ino b/src/extras/extras.ino index 8d8b76d..1f85782 100644 --- a/src/extras/extras.ino +++ b/src/extras/extras.ino @@ -1,5 +1,30 @@ -#error THIS IS NOT COMPILABLE CODE +// This is a placeholder .ino file that allows you to easily edit the contents of this library using the Arduino IDE, +// as well as compile and test from this point. This file is ignored when the library is included in other sketches. -This is a dummy .ino file that allows you to easily edit the contents of this library using the Arduino IDE. -The code is NOT designed to be compiled from this point. Compile and test the library using one of the examples. +#include "RFControl.h" + +void setup(){ + + Serial.begin(115200); + delay(1000); + + Serial.print("\n\nTest sketch for HomeSpan Extras Library\n\n"); + + RFControl rf(4); + + Serial.println("Starting..."); + + rf.clear(); + for(int i=0;i<3;i++) + rf.add(2000,2000); + rf.phase(10000,RF_LOW); + rf.start(5,100); + + Serial.println("Done!"); + +} + +void loop(){ + +}