diff --git a/arduino/ArduinoTellstickDuo/archtech.cpp b/arduino/ArduinoTellstickDuo/archtech.cpp index d81371a7..a6a382bf 100644 --- a/arduino/ArduinoTellstickDuo/archtech.cpp +++ b/arduino/ArduinoTellstickDuo/archtech.cpp @@ -43,7 +43,7 @@ send low for 10,000 microseconds #define ARCHTECH_SHORT_MIN 2 #define ARCHTECH_SHORT_MAX 7 #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_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; 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; - }else if(bitsInBuffer == 36){ + }else if(bitsInBuffer == 37){ + //Serial.println("with dim"); dimValuePresent = true; } else { + //Serial.println("ignore"); return false; } + + //stkip two buffers entries. + stepBufferPointer(&bufStartP); + stepBufferPointer(&bufStartP); 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 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 + //Serial.println(" --> 1"); data <<= 1; //shift in a zero data |= 0x1; //add one } else if (IS_ZERO(b1,b2,b3,b4)) { //"zero" is sent over air + //Serial.println(" --> 0"); data <<= 1; //shift in a zero } else { + //Serial.println(" --> CORRUPT"); return false; } diff --git a/arduino/ArduinoTellstickDuo/config.h b/arduino/ArduinoTellstickDuo/config.h index 43101ad5..1f0c7913 100644 --- a/arduino/ArduinoTellstickDuo/config.h +++ b/arduino/ArduinoTellstickDuo/config.h @@ -14,7 +14,7 @@ inline void setupPins(){ #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__) //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 #define TX_PIN_LOW() ( PORTB &= 0b01111111 ) // optimized "digitalWrite(8, LOW)" #define TX_PIN_HIGH() ( PORTB |= 0b10000000 ) // optimized "digitalWrite(8, HIGH)" @@ -22,4 +22,4 @@ inline void setupPins(){ #unsupported architecture #endif -#endif //CONFIG_H \ No newline at end of file +#endif //CONFIG_H diff --git a/arduino/ArduinoTellstickDuo/rf.cpp b/arduino/ArduinoTellstickDuo/rf.cpp index 980cd4a4..0d5a31a7 100644 --- a/arduino/ArduinoTellstickDuo/rf.cpp +++ b/arduino/ArduinoTellstickDuo/rf.cpp @@ -17,8 +17,9 @@ void parseRadioRXBuffer() { bool parse = false; while (bufferReadP != bufferWriteP) { //stop if the read pointer is pointing to where the writing is currently performed uint8_t sampleCount = *bufferReadP; - + if ( (((uintptr_t)bufferReadP) & 0x1) == 1 ) { //buffer pointer is odd (stores highs) + //Serial.print("high:"); Serial.println(sampleCount); if (prevValue >= SILENCE_LENGTH) { 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); } 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 endDataP = bufferReadP; //this is a silient period and must be the end of a data - parse = true; - break; + if(startDataP != 0){ + parse = true; + break; + } } //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. startDataP = 0; endDataP = 0; + prevValue = 0; } //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. */ + //Serial.print((uintptr_t)startDataP); Serial.print(" - "); Serial.println((uintptr_t)endDataP); + //Let all available parsers parse the data set now. parseArctechSelfLearning(startDataP, endDataP); //TODO: add more parsers here