Added oregon v2.1 support to ArduinoTellstick along with some code cleanup
Former-commit-id: d05ee71fa4f2f91afd6452e894385bbcd7020917
This commit is contained in:
parent
c2d03347ca
commit
1c23a7c360
11 changed files with 391 additions and 116 deletions
|
|
@ -2,6 +2,9 @@
|
|||
#include "buffer.h"
|
||||
#include "archtech.h"
|
||||
#include "config.h"
|
||||
#include "oregonV2.1.h"
|
||||
|
||||
#define SILENCE_LENGTH 100 //the number of samples with "low" that represents a silent period between two signals
|
||||
|
||||
volatile bool RFRX = false;
|
||||
|
||||
|
|
@ -13,19 +16,29 @@ void parseRadioRXBuffer() {
|
|||
|
||||
bool parse = false;
|
||||
while (bufferReadP != bufferWriteP) { //stop if the read pointer is pointing to where the writing is currently performed
|
||||
|
||||
if ( (((int)bufferReadP) & 0x1) == 1 ) { //buffer pointer is odd (stores highs)
|
||||
uint8_t sampleCount = *bufferReadP;
|
||||
|
||||
if ( (((uintptr_t)bufferReadP) & 0x1) == 1 ) { //buffer pointer is odd (stores highs)
|
||||
if (prevValue >= SILENCE_LENGTH) {
|
||||
startDataP = bufferReadP; //some new data must starrt here since this is the first "high" after a silent period
|
||||
startDataP = bufferReadP; //some new data must start here since this is the first "high" after a silent period
|
||||
}
|
||||
|
||||
//stream data to stream parsers
|
||||
parseOregonStream(HIGH, sampleCount);
|
||||
|
||||
} else { //buffer pointer is even (stores lows)
|
||||
if (*bufferReadP >= SILENCE_LENGTH) { //evaluate if it is time to parse the curernt data
|
||||
if (sampleCount >= SILENCE_LENGTH) { //evaluate if it is time to parse the curernt data
|
||||
endDataP = bufferReadP; //this is a silient period and must be the end of a data
|
||||
parse = true;
|
||||
break;
|
||||
}
|
||||
|
||||
//stream data to stream parsers
|
||||
parseOregonStream(LOW, sampleCount);
|
||||
|
||||
}
|
||||
|
||||
//step the read pointer one step
|
||||
uint8_t* nextBufferReadP = getNextBufferPointer(bufferReadP);
|
||||
if (nextBufferReadP == startDataP) { //next pointer will point to startDataP. Data will overflow. Reset the data pointers.
|
||||
startDataP = 0;
|
||||
|
|
@ -35,7 +48,7 @@ void parseRadioRXBuffer() {
|
|||
//advance buffer pointer one step
|
||||
bufferReadP = nextBufferReadP;
|
||||
|
||||
prevValue = *bufferReadP; //update previous value
|
||||
prevValue = sampleCount; //update previous value
|
||||
}
|
||||
|
||||
if (!parse) {
|
||||
|
|
@ -51,50 +64,57 @@ void parseRadioRXBuffer() {
|
|||
* and the endDataP will point at the first (low) silent period after the data data start.
|
||||
*/
|
||||
|
||||
//make sure that the data set size is big enought to parse.
|
||||
uint16_t dataSetSize = calculateBufferPointerDistance(startDataP, endDataP);
|
||||
if (dataSetSize < 32) { //at least 32 low/high
|
||||
return;
|
||||
}
|
||||
|
||||
//Let all available parsers parse the data set now.
|
||||
parseArctechSelfLearning(startDataP, endDataP);
|
||||
//TODO: add more parsers here
|
||||
|
||||
//reset the data pointers since the data have been parsed at this point
|
||||
startDataP = 0;
|
||||
endDataP = 0;
|
||||
|
||||
}; //end radioTask
|
||||
|
||||
void sendTCodedData(uint8_t* data, uint8_t T_long, uint8_t* timings, uint8_t repeat, uint8_t pause) {
|
||||
RFRX = false; //turn off the RF reciever
|
||||
ACTIVATE_RADIO_TRANSMITTER();
|
||||
for (uint8_t rep = 0; rep < repeat; ++rep) {
|
||||
bool nextPinState = HIGH;
|
||||
for (int i = 0; i < T_long; ++i) {
|
||||
uint8_t timeIndex = (data[i / 4] >> (6 - (2 * (i % 4)))) & 0x03;
|
||||
if (timings[timeIndex] > 0 || i == T_long - 1) {
|
||||
digitalWrite(TX_PIN, nextPinState);
|
||||
if(nextPinState){
|
||||
TX_PIN_HIGH();
|
||||
}else{
|
||||
TX_PIN_LOW();
|
||||
}
|
||||
delayMicroseconds(10 * timings[timeIndex]);
|
||||
}
|
||||
nextPinState = !nextPinState;
|
||||
}
|
||||
digitalWrite(TX_PIN, LOW);
|
||||
TX_PIN_LOW();
|
||||
if (rep < repeat - 1) {
|
||||
delay(pause);
|
||||
}
|
||||
}
|
||||
RFRX = true; //turn on the RF reciever
|
||||
ACTIVATE_RADIO_RECEIVER();
|
||||
};
|
||||
|
||||
void sendSCodedData(uint8_t* data, uint8_t pulseCount, uint8_t repeat, uint8_t pause) {
|
||||
RFRX = false; //turn off the RF reciever
|
||||
ACTIVATE_RADIO_TRANSMITTER();
|
||||
for (uint8_t rep = 0; rep < repeat; ++rep) {
|
||||
bool nextPinState = HIGH;
|
||||
for (int i = 0; i < pulseCount; ++i) {
|
||||
if (data[i] > 0 || i == pulseCount - 1) {
|
||||
digitalWrite(TX_PIN, nextPinState);
|
||||
if(nextPinState){
|
||||
TX_PIN_HIGH();
|
||||
}else{
|
||||
TX_PIN_LOW();
|
||||
}
|
||||
delayMicroseconds(data[i] * 10);
|
||||
}
|
||||
nextPinState = !nextPinState;
|
||||
}
|
||||
delay(pause);
|
||||
}
|
||||
RFRX = false; //turn on the RF reciever
|
||||
TX_PIN_LOW();
|
||||
ACTIVATE_RADIO_RECEIVER();
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue