Browse Source

Small fixes.

Thomas Chef 5 years ago
parent
commit
7be253e7c0
2 changed files with 39 additions and 3 deletions
  1. 13 0
      main/Sensors/ClasOSensor.c
  2. 26 3
      main/receiver.c

+ 13 - 0
main/Sensors/ClasOSensor.c

@@ -1,6 +1,7 @@
 #include "ClasOSensor.h"
 #include <stdint.h>
 #include <stdio.h>
+#include "esp_log.h"
 #include "../rxTimer.h"
 #include "../led.h"
 
@@ -20,11 +21,14 @@ static uint8_t rx_state = UNKNOWN;
 static uint64_t sensor_data;
 static uint32_t rx_numBits;
 
+static uint32_t debug_width;
+
 void ClasO_ResetDecoder()
 {
     sensor_data = 0;
     rx_numBits = 0;
     rx_state = UNKNOWN;
+    debug_width = 0;
 }
 
 static void addBit(uint8_t value)
@@ -43,6 +47,7 @@ static int32_t rx_decode(uint32_t width)
             if (3700 <= width && width <= 4150)
             {
                 rx_state = T0;
+                debug_width = width;
             }
             else
             {
@@ -121,6 +126,14 @@ int64_t nextPulseClasOSensor(uint32_t width)
     }
     if (rx_state == DONE) {
         now = millis();
+
+        // For debug only
+        if( ((sensor_data>>12) & 0x007) == 1 ) {
+            ESP_LOGE("CLAS","Width:%u",debug_width);
+        }
+
+
+
         if( sensor_data != previous_data || (now > (old_time+1000)) ) {
             previous_data = sensor_data;
             retVal = sensor_data;

+ 26 - 3
main/receiver.c

@@ -37,7 +37,6 @@ static int convertToSignedTemp(unsigned int value)
 	return ( (value >> 11) == 0 )? value : ((-1 ^ 0xFFF) | value);
 }
 
-
 void receiverTask(void *pvParameter)
 {
     ESP_LOGI("RX", "Receiver task starting.");
@@ -57,8 +56,9 @@ void receiverTask(void *pvParameter)
             if( data != -1 ) {
 
                 int value      = convertToSignedTemp( data & 0xFFF );
+                unsigned char id         = (data>>12) & 0x007;
 
-                ESP_LOGI("RX", "ClasO:  <TR%08llX> %d",data,value);
+                ESP_LOGI("RX", "ClasO:  <TR%08llX> %u %d",data,id, value);
 
                 sprintf(dataStr,"<TR%08llX>\n",data);
 #ifdef WIFI_ENABLED
@@ -97,9 +97,32 @@ void receiverTask(void *pvParameter)
             char *ch_data_p = nextPulseOregonSensor(width);
             if( ch_data_p != NULL ) {
 
+                // Nibbles 17..12 = Total Rain = LSD is 0.001 inch (0,0254 mm)
+                
+                //   0 1 2 3  4 5  6 7 8  9                     Rate    Total
+                // RR2A1904CE 0000 601600 70 = 001.660          0000    001660
+                // RR2A1904CE 2001 702000 60 = 002.070 = 0,41   0120    002070
+                // RR2A1904CE 0001 902400 A0 = 002.490 = 0,42           002490
+                // Sequence:       563412  
+                // 1 cubic mm of water = 0,001 gram
+                // 7 grams of water = 7000 mm2
+                // Area of the rain sensor is 7697.69 sq.mm. It flips every ~7grams of water
+                // Every flip is therefore 0.90936402542048 mm or rain
+                // The value that is reported is in 1/1000 cubic inches of water.
+                // Multiply with 16387 / 1000 to get cm2
+
+                double total = 100 * (ch_data_p[4+12]-'0') + 
+                                10 * (ch_data_p[5+12]-'0') +
+                                     (ch_data_p[2+12]-'0') +
+                               0.1 * (ch_data_p[3+12]-'0') +
+                              0.01 * (ch_data_p[0+12]-'0') +
+                             0.001 * (ch_data_p[1+12]-'0');
+
+                total = (total * 16387) / 1000;
+
                 char ch_data[21];
                 strncpy(ch_data,ch_data_p, sizeof(ch_data));
-                ESP_LOGI("RX", "OREGON: <RR%s>", ch_data );
+                ESP_LOGI("RX", "OREGON: <RR%s> %6.4f cm2", ch_data, total );
 
                 Oregon_ResetDecoder();
             }