Added 'phase' method to RFControl
RFControl::phase() allows you to add either a HIGH or LOW entry (i.e. a single phase of a pulse. RFControl::add() continues to add a full HIGH/LOW pulse so these changes are fully backwards compatible.
This commit is contained in:
parent
417587facf
commit
e7e6d4de61
|
|
@ -32,7 +32,12 @@ RFControl::RFControl(int pin){
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
void RFControl::start(uint8_t _numCycles, uint8_t tickTime){
|
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<<pin); // enable output on pin
|
REG_WRITE(GPIO_ENABLE_W1TS_REG,1<<pin); // enable output on pin
|
||||||
numCycles=_numCycles; // set number of cycles to repeat transmission
|
numCycles=_numCycles; // set number of cycles to repeat transmission
|
||||||
REG_SET_FIELD(RMT_CH0CONF0_REG,RMT_DIV_CNT_CH0,tickTime); // set one tick = 1 microsecond * tickTime (RMT will be set to use 1 MHz REF_TICK, not 80 MHz APB_CLK)
|
REG_SET_FIELD(RMT_CH0CONF0_REG,RMT_DIV_CNT_CH0,tickTime); // set one tick = 1 microsecond * tickTime (RMT will be set to use 1 MHz REF_TICK, not 80 MHz APB_CLK)
|
||||||
|
|
@ -50,21 +55,35 @@ void RFControl::clear(){
|
||||||
///////////////////
|
///////////////////
|
||||||
|
|
||||||
void RFControl::add(uint16_t onTime, uint16_t offTime){
|
void RFControl::add(uint16_t onTime, uint16_t offTime){
|
||||||
|
|
||||||
if(pCount==511){ // maximum number of pulses reached (saving one space for end-marker)
|
phase(onTime,RF_HIGH);
|
||||||
Serial.print("\n*** ERROR: Can't add more than 511 pulses to RF Control Module\n\n");
|
phase(offTime,RF_LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
|
||||||
|
void RFControl::phase(uint16_t numTicks, PHASE phase){
|
||||||
|
|
||||||
|
if(pCount==1023){ // maximum number of entries reached (saving one space for end-marker)
|
||||||
|
Serial.print("\n*** ERROR: Can't add more than 1023 entries to RF Control Module\n\n");
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if(offTime>32767 || offTime<1 || onTime>32767 || onTime<1){
|
if(numTicks>32767 || numTicks<1){
|
||||||
Serial.print("\n*** ERROR: Request to add RF Control pulse with onTime=");
|
Serial.print("\n*** ERROR: Request to add RF Control entry with numTicks=");
|
||||||
Serial.print(onTime);
|
Serial.print(numTicks);
|
||||||
Serial.print(" and offTime=");
|
|
||||||
Serial.print(offTime);
|
|
||||||
Serial.print(" is out of allowable range: 1-32767\n\n");
|
Serial.print(" is out of allowable range: 1-32767\n\n");
|
||||||
} else {
|
} 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;
|
volatile int RFControl::numCycles;
|
||||||
uint32_t *RFControl::pRMT=(uint32_t *)RMT_CHANNEL_MEM(0);
|
uint32_t *RFControl::pRMT=(uint32_t *)RMT_CHANNEL_MEM(0);
|
||||||
int RFControl::pCount=0;
|
int RFControl::pCount=0;
|
||||||
|
RFControl::PHASE RF_LOW=RFControl::PHASE::Low;
|
||||||
|
RFControl::PHASE RF_HIGH=RFControl::PHASE::High;
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,20 @@ class RFControl {
|
||||||
static int pCount;
|
static int pCount;
|
||||||
static void eot_int(void *arg);
|
static void eot_int(void *arg);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
enum class PHASE {
|
||||||
|
Low=0,
|
||||||
|
High=0x8000
|
||||||
|
};
|
||||||
|
|
||||||
RFControl(int pin); // creates transmitter on pin
|
RFControl(int pin); // creates transmitter on pin
|
||||||
static void clear(); // clears transmitter memory
|
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 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
|
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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
|
#include "RFControl.h"
|
||||||
The code is NOT designed to be compiled from this point. Compile and test the library using one of the examples.
|
|
||||||
|
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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue