|
@@ -6,6 +6,24 @@
|
|
#include <string.h>
|
|
#include <string.h>
|
|
#include "esp_log.h"
|
|
#include "esp_log.h"
|
|
|
|
|
|
|
|
+typedef struct {
|
|
|
|
+ uint32_t max;
|
|
|
|
+ uint32_t min;
|
|
|
|
+ uint32_t cnt;
|
|
|
|
+ uint32_t total;
|
|
|
|
+} debug_data_t;
|
|
|
|
+
|
|
|
|
+debug_data_t debug_data = { 0,99999,0,0 };
|
|
|
|
+debug_data_t debug_data_tot = { 0,99999,0,0 };
|
|
|
|
+
|
|
|
|
+#define DEBUG_WIDTH_FUNC() { \
|
|
|
|
+ if( width > debug_data.max ) debug_data.max = width; \
|
|
|
|
+ if( width < debug_data.min ) debug_data.min = width; \
|
|
|
|
+ debug_data.total += width; \
|
|
|
|
+ debug_data.cnt++; \
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
enum { UNKNOWN, T0, T1, T2, T3, OK_Sensor, DONE };
|
|
enum { UNKNOWN, T0, T1, T2, T3, OK_Sensor, DONE };
|
|
|
|
|
|
static unsigned char rx_state = T0;
|
|
static unsigned char rx_state = T0;
|
|
@@ -32,8 +50,6 @@ static void addBit (uint8_t value) {
|
|
rx_state = OK_Sensor;
|
|
rx_state = OK_Sensor;
|
|
}
|
|
}
|
|
|
|
|
|
-#define MARG 55
|
|
|
|
-
|
|
|
|
static int rx_decode (uint32_t width) {
|
|
static int rx_decode (uint32_t width) {
|
|
|
|
|
|
switch (rx_state) {
|
|
switch (rx_state) {
|
|
@@ -42,26 +58,27 @@ static int rx_decode (uint32_t width) {
|
|
|
|
|
|
case T0: // First ON-half of pulse : HIGH around 910
|
|
case T0: // First ON-half of pulse : HIGH around 910
|
|
|
|
|
|
- if ( (1010-MARG) <= width && width <= (1080) ) {
|
|
|
|
|
|
+ if ( (960-100) <= width && width <= (1080+100) ) {
|
|
rx_state = T1;
|
|
rx_state = T1;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- if( isTrigged ) {
|
|
|
|
- //ESP_LOGE("PROOVE", "T0 Un-Trig B:%u W:%u",rx_numBits,width);
|
|
|
|
- }
|
|
|
|
return -1; // error, reset
|
|
return -1; // error, reset
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
|
|
|
|
case T1:
|
|
case T1:
|
|
- if ( (445-MARG) <= width && width <= (445+MARG)) {
|
|
|
|
- bitData = 1;
|
|
|
|
- } else if ( (1420-MARG) <= width && width <= (1420+MARG) ) {
|
|
|
|
- bitData = 0;
|
|
|
|
- } else {
|
|
|
|
- if( isTrigged ) {
|
|
|
|
- //ESP_LOGE("PROOVE", "T1 Un-Trig B:%u W:%u",rx_numBits,width);
|
|
|
|
|
|
+
|
|
|
|
+ if ( 200 <= width && width <= 2000 ) {
|
|
|
|
+
|
|
|
|
+ if( width > 1000 ) {
|
|
|
|
+ bitData = 0;
|
|
}
|
|
}
|
|
|
|
+ else {
|
|
|
|
+ //DEBUG_WIDTH_FUNC();
|
|
|
|
+ bitData = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } else {
|
|
return -1; // error, reset
|
|
return -1; // error, reset
|
|
}
|
|
}
|
|
|
|
|
|
@@ -123,11 +140,17 @@ int64_t nextPulseProovesmartSensor(uint32_t width)
|
|
if (rx_state == DONE) {
|
|
if (rx_state == DONE) {
|
|
now = millis();
|
|
now = millis();
|
|
sensor_data <<= 8;
|
|
sensor_data <<= 8;
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ if( debug_data.max > debug_data_tot.max ) debug_data_tot.max = debug_data.max;
|
|
|
|
+ if( debug_data.min < debug_data_tot.min ) debug_data_tot.min = debug_data.min;
|
|
|
|
+ printf("OREGON DEbug min,max:%u %u\n",debug_data_tot.min,debug_data_tot.max);
|
|
|
|
+ */
|
|
|
|
+
|
|
if( sensor_data != previous_data || (now > (old_time+1000)) ) {
|
|
if( sensor_data != previous_data || (now > (old_time+1000)) ) {
|
|
previous_data = sensor_data;
|
|
previous_data = sensor_data;
|
|
retVal = sensor_data;
|
|
retVal = sensor_data;
|
|
blinkTheLED();
|
|
blinkTheLED();
|
|
- //printf("%d\n",debug_width);
|
|
|
|
}
|
|
}
|
|
old_time = now;
|
|
old_time = now;
|
|
ProovesmartSensor_ResetDecoder();
|
|
ProovesmartSensor_ResetDecoder();
|