TC 7 lat temu
rodzic
commit
a7006a2c18
3 zmienionych plików z 37 dodań i 80 usunięć
  1. 9 0
      Src/app.c
  2. 15 80
      Src/oregon.c
  3. 13 0
      Src/oregon.h

+ 9 - 0
Src/app.c

@@ -37,10 +37,13 @@
 #include "nexa.h"
 #include "temp1.h"
 #include "temp2.h"
+#include "oregon.h"
 #include "transmit.h"
 #include "stm32l1xx_hal.h"
 #include "stm32l1xx_hal_gpio.h"
 
+
+
 volatile unsigned long width;
 
 
@@ -114,6 +117,9 @@ void loop() {
 
   static unsigned int width;
   
+  //static OregonDecoderV2 orscV2;
+  //static OregonDecoderV3 orscV3;
+  
   static unsigned long previous_now = 0; // Get the current time
   unsigned long now = millis(); // Get the current time
   
@@ -130,6 +136,9 @@ void loop() {
   
   if( rcvDeQueue(&width) ) {
     
+    // Oregon V3
+    
+    
     // ********** TEMP1 ***********
     if( nextPulseTemp1(width) ) {
         

+ 15 - 80
Src/oregon.c

@@ -1,16 +1,15 @@
-class DecodeOOK {
-protected:
-    byte total_bits, bits, flip, state, pos, data[25];
+#include "app.h"
+#include "nexa.h"
+#include "oregon.h"
 
-    virtual char decode (word width) =0;
-    
-public:
+// Constructor must run resetDecoder()
+
+unsigned char total_bits, bits, flip, state, pos, data[25];
 
-    enum { UNKNOWN, T0, T1, T2, T3, OK, DONE };
+enum { UNKNOWN, T0, T1, T2, T3, OK, DONE };
 
-    DecodeOOK () { resetDecoder(); }
 
-    bool nextPulse (word width) {
+    boolean nextPulse (unsigned short width) {
         if (state != DONE)
         
             switch (decode(width)) {
@@ -20,9 +19,11 @@ public:
         return isDone();
     }
     
-    bool isDone () const { return state == DONE; }
+    boolean isDone() {
+      return state == DONE;
+    }
 
-    const byte* getData (byte& count) const {
+    const unsigned char* getData (unsigned char& count) {
         count = pos;
         return data; 
     }
@@ -34,7 +35,7 @@ public:
     
     // add one bit to the packet data buffer
     
-    virtual void gotBit (char value) {
+    virtual void gotBit (unsigned char value) {
         total_bits++;
         byte *ptr = data + pos;
         *ptr = (*ptr >> 1) | (value << 7);
@@ -93,77 +94,11 @@ public:
             gotBit(0); // padding
         state = DONE;
     }
-};
 
 
-class OregonDecoderV2 : public DecodeOOK {
-public:
-    OregonDecoderV2() {}
-    
-    // add one bit to the packet data buffer
-    virtual void gotBit (char value) {
-        if(!(total_bits & 0x01))
-        {
-            data[pos] = (data[pos] >> 1) | (value ? 0x80 : 00);
-        }
-        total_bits++;
-        pos = total_bits >> 4;
-        if (pos >= sizeof data) {
-            resetDecoder();
-            return;
-        }
-        state = OK;
-    }
-    
-    virtual char decode (word width) {
-        if (200 <= width && width < 1200) {
-            byte w = width >= 700;
-            switch (state) {
-                case UNKNOWN:
-                    if (w != 0) {
-                        // Long pulse
-                        ++flip;
-                    } else if (32 <= flip) {
-                        // Short pulse, start bit
-                        flip = 0;
-                        state = T0;
-                    } else {
-                      // Reset decoder
-                        return -1;
-                    }
-                    break;
-                case OK:
-                    if (w == 0) {
-                        // Short pulse
-                        state = T0;
-                    } else {
-                        // Long pulse
-                        manchester(1);
-                    }
-                    break;
-                case T0:
-                    if (w == 0) {
-                      // Second short pulse
-                        manchester(0);
-                    } else {
-                        // Reset decoder
-                        return -1;
-                    }
-                    break;
-            }
-        } else {
-            return -1;
-        }
-        return total_bits == 160 ? 1: 0;
-    }
-};
-
-class OregonDecoderV3 : public DecodeOOK {
-public:
-    OregonDecoderV3() {}
     
     // add one bit to the packet data buffer
-    virtual void gotBit (char value) {
+    void gotBit (char value) {
         data[pos] = (data[pos] >> 1) | (value ? 0x80 : 00);
         total_bits++;
         pos = total_bits >> 3;
@@ -205,5 +140,5 @@ public:
         }
         return  total_bits == 80 ? 1: 0;
     }
-};
+
 

+ 13 - 0
Src/oregon.h

@@ -3,6 +3,19 @@
 
 #include "app.h"
 
+void oregonV3ResetDecoder ();
+
+extern unsigned long long oregonV3_x_data;
+
+boolean nextPulseoregonV3(unsigned int width);
+
+typedef struct {
+unsigned int remote_id;
+unsigned char group;
+unsigned char onOff;
+unsigned char channel;
+unsigned char button;
+} OREGONV3_QUEUE_DATA;