|
@@ -0,0 +1,107 @@
|
|
|
+#include "oregon.h"
|
|
|
+#include <stdint.h>
|
|
|
+#include <stdio.h>
|
|
|
+#include "../rxTimer.h"
|
|
|
+#include "../led.h"
|
|
|
+#include <string.h>
|
|
|
+#include "esp_log.h"
|
|
|
+
|
|
|
+static void done ();
|
|
|
+
|
|
|
+static unsigned char total_bits, bits, flip, state, pos, data[25];
|
|
|
+char result_str[25];
|
|
|
+
|
|
|
+enum { UNKNOWN, T0, T1, T2, T3, SENSOR_OK, DONE };
|
|
|
+
|
|
|
+void Oregon_ResetDecoder () {
|
|
|
+ total_bits = bits = pos = flip = 0;
|
|
|
+ state = UNKNOWN;
|
|
|
+ memset(result_str,'\0',sizeof(result_str));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// V3-Version of the gitBit-function
|
|
|
+static void gotBit (char value) {
|
|
|
+ data[pos] = (data[pos] >> 1) | (value ? 0x80 : 00);
|
|
|
+ total_bits++;
|
|
|
+ pos = total_bits >> 3;
|
|
|
+ if (pos >= sizeof data) {
|
|
|
+ Oregon_ResetDecoder();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ state = SENSOR_OK;
|
|
|
+}
|
|
|
+
|
|
|
+// store a bit using Manchester encoding
|
|
|
+static void manchester (char value) {
|
|
|
+ flip ^= value; // manchester code, long pulse flips the bit
|
|
|
+ gotBit(flip);
|
|
|
+}
|
|
|
+
|
|
|
+static void done () {
|
|
|
+ while (bits)
|
|
|
+ gotBit(0); // padding
|
|
|
+ state = DONE;
|
|
|
+}
|
|
|
+
|
|
|
+static int rx_decode( int width ) {
|
|
|
+ if( (480-200) < width && width < (980+200) ) {
|
|
|
+ char w = width >= 730;
|
|
|
+ switch (state) {
|
|
|
+ case UNKNOWN:
|
|
|
+ if (w == 0)
|
|
|
+ ++flip;
|
|
|
+ else if (32 <= flip) {
|
|
|
+ flip = 1;
|
|
|
+ manchester(1); // Width 950
|
|
|
+ } else
|
|
|
+ return -1;
|
|
|
+ break;
|
|
|
+ case SENSOR_OK:
|
|
|
+ if (w == 0)
|
|
|
+ state = T0;
|
|
|
+ else
|
|
|
+ manchester(1); // Width 980
|
|
|
+ break;
|
|
|
+ case T0:
|
|
|
+ if (w == 0)
|
|
|
+ manchester(0); // Width 480
|
|
|
+ else
|
|
|
+ return -1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ return total_bits == 80 ? 1: 0;
|
|
|
+}
|
|
|
+
|
|
|
+ //10 bytes data: 2A 19 04 CE 00 00 60 12 00 30
|
|
|
+
|
|
|
+char * nextPulseOregonSensor(uint32_t width) {
|
|
|
+ if( state != DONE ) {
|
|
|
+
|
|
|
+ switch (rx_decode(width)) {
|
|
|
+ case -1:
|
|
|
+ Oregon_ResetDecoder();
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ done();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if( state == DONE ) {
|
|
|
+ if( pos == 10 ) {
|
|
|
+ for( int i=0; i<pos; i++ ) {
|
|
|
+ sprintf(result_str+(i*2),"%02X",data[i] );
|
|
|
+ }
|
|
|
+ return result_str;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Oregon_ResetDecoder();
|
|
|
+ return (char *)NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return (char *)NULL;
|
|
|
+}
|