ArduinoTellstick bug fixes. now the nexa part is working

Former-commit-id: 3e462e990cc25d1b54c38ca729922392aca97c05
This commit is contained in:
Daniel Collin 2016-01-31 09:47:59 +01:00
parent 41ebf9ac30
commit efadc097ce
3 changed files with 28 additions and 8 deletions

View file

@ -43,7 +43,7 @@ send low for 10,000 microseconds
#define ARCHTECH_SHORT_MIN 2 #define ARCHTECH_SHORT_MIN 2
#define ARCHTECH_SHORT_MAX 7 #define ARCHTECH_SHORT_MAX 7
#define ARCHTECH_LONG_MIN 17 #define ARCHTECH_LONG_MIN 17
#define ARCHTECH_LONG_MAX 23 #define ARCHTECH_LONG_MAX 27
#define IS_SHORT(b) ( ARCHTECH_SHORT_MIN <= b && b <= ARCHTECH_SHORT_MAX ) #define IS_SHORT(b) ( ARCHTECH_SHORT_MIN <= b && b <= ARCHTECH_SHORT_MAX )
#define IS_LONG(b) ( ARCHTECH_LONG_MIN <= b && b <= ARCHTECH_LONG_MAX ) #define IS_LONG(b) ( ARCHTECH_LONG_MIN <= b && b <= ARCHTECH_LONG_MAX )
@ -56,13 +56,21 @@ bool parseArctechSelfLearning(uint8_t* bufStartP, uint8_t* bufEndP) { //start
bool dimValuePresent; bool dimValuePresent;
uint16_t bitsInBuffer = calculateBufferPointerDistance(bufStartP, bufEndP) / 4; //each bit is representd by 4 high/low uint16_t bitsInBuffer = calculateBufferPointerDistance(bufStartP, bufEndP) / 4; //each bit is representd by 4 high/low
if (bitsInBuffer == 32) { //Serial.print("bits in buffer: "); Serial.print(bitsInBuffer); Serial.print(" - ");
if (bitsInBuffer == 33) {
//Serial.println("default");
dimValuePresent = false; dimValuePresent = false;
}else if(bitsInBuffer == 36){ }else if(bitsInBuffer == 37){
//Serial.println("with dim");
dimValuePresent = true; dimValuePresent = true;
} else { } else {
//Serial.println("ignore");
return false; return false;
} }
//stkip two buffers entries.
stepBufferPointer(&bufStartP);
stepBufferPointer(&bufStartP);
for (uint8_t i = 0; i < bitsInBuffer-1; ++i) { for (uint8_t i = 0; i < bitsInBuffer-1; ++i) {
@ -75,12 +83,17 @@ bool parseArctechSelfLearning(uint8_t* bufStartP, uint8_t* bufEndP) { //start
uint8_t b4 = *bufStartP; //no of low uint8_t b4 = *bufStartP; //no of low
stepBufferPointer(&bufStartP); stepBufferPointer(&bufStartP);
//Serial.print(b1); Serial.print(", ");Serial.print(b2); Serial.print(", ");Serial.print(b3); Serial.print(", ");Serial.print(b4);
if (IS_ONE(b1,b2,b3,b4)) { //"one" is sent over air if (IS_ONE(b1,b2,b3,b4)) { //"one" is sent over air
//Serial.println(" --> 1");
data <<= 1; //shift in a zero data <<= 1; //shift in a zero
data |= 0x1; //add one data |= 0x1; //add one
} else if (IS_ZERO(b1,b2,b3,b4)) { //"zero" is sent over air } else if (IS_ZERO(b1,b2,b3,b4)) { //"zero" is sent over air
//Serial.println(" --> 0");
data <<= 1; //shift in a zero data <<= 1; //shift in a zero
} else { } else {
//Serial.println(" --> CORRUPT");
return false; return false;
} }

View file

@ -14,7 +14,7 @@ inline void setupPins(){
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
//pin7 = PD7 = port D, bit 8 //pin7 = PD7 = port D, bit 8
#define RX_PIN_READ() ( PIND & 0b00000001 ) // optimized "digitalRead(7)" #define RX_PIN_READ() ( digitalRead(7) ) // optimized "digitalRead(7)"
//pin8 = PB0 = port B, bit 1 //pin8 = PB0 = port B, bit 1
#define TX_PIN_LOW() ( PORTB &= 0b01111111 ) // optimized "digitalWrite(8, LOW)" #define TX_PIN_LOW() ( PORTB &= 0b01111111 ) // optimized "digitalWrite(8, LOW)"
#define TX_PIN_HIGH() ( PORTB |= 0b10000000 ) // optimized "digitalWrite(8, HIGH)" #define TX_PIN_HIGH() ( PORTB |= 0b10000000 ) // optimized "digitalWrite(8, HIGH)"
@ -22,4 +22,4 @@ inline void setupPins(){
#unsupported architecture #unsupported architecture
#endif #endif
#endif //CONFIG_H #endif //CONFIG_H

View file

@ -17,8 +17,9 @@ void parseRadioRXBuffer() {
bool parse = false; bool parse = false;
while (bufferReadP != bufferWriteP) { //stop if the read pointer is pointing to where the writing is currently performed while (bufferReadP != bufferWriteP) { //stop if the read pointer is pointing to where the writing is currently performed
uint8_t sampleCount = *bufferReadP; uint8_t sampleCount = *bufferReadP;
if ( (((uintptr_t)bufferReadP) & 0x1) == 1 ) { //buffer pointer is odd (stores highs) if ( (((uintptr_t)bufferReadP) & 0x1) == 1 ) { //buffer pointer is odd (stores highs)
//Serial.print("high:"); Serial.println(sampleCount);
if (prevValue >= SILENCE_LENGTH) { if (prevValue >= SILENCE_LENGTH) {
startDataP = bufferReadP; //some new data must start 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
} }
@ -27,10 +28,13 @@ void parseRadioRXBuffer() {
parseOregonStream(HIGH, sampleCount); parseOregonStream(HIGH, sampleCount);
} else { //buffer pointer is even (stores lows) } else { //buffer pointer is even (stores lows)
//Serial.print("low:"); Serial.println(sampleCount);
if (sampleCount >= 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 endDataP = bufferReadP; //this is a silient period and must be the end of a data
parse = true; if(startDataP != 0){
break; parse = true;
break;
}
} }
//stream data to stream parsers //stream data to stream parsers
@ -43,6 +47,7 @@ void parseRadioRXBuffer() {
if (nextBufferReadP == startDataP) { //next pointer will point to startDataP. Data will overflow. Reset the data pointers. if (nextBufferReadP == startDataP) { //next pointer will point to startDataP. Data will overflow. Reset the data pointers.
startDataP = 0; startDataP = 0;
endDataP = 0; endDataP = 0;
prevValue = 0;
} }
//advance buffer pointer one step //advance buffer pointer one step
@ -64,6 +69,8 @@ void parseRadioRXBuffer() {
* and the endDataP will point at the first (low) silent period after the data data start. * and the endDataP will point at the first (low) silent period after the data data start.
*/ */
//Serial.print((uintptr_t)startDataP); Serial.print(" - "); Serial.println((uintptr_t)endDataP);
//Let all available parsers parse the data set now. //Let all available parsers parse the data set now.
parseArctechSelfLearning(startDataP, endDataP); parseArctechSelfLearning(startDataP, endDataP);
//TODO: add more parsers here //TODO: add more parsers here