|
@@ -21,14 +21,12 @@ 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)
|
|
@@ -40,14 +38,26 @@ static void addBit(uint8_t value)
|
|
|
rx_state = TEMP1_OK;
|
|
|
}
|
|
|
|
|
|
+#define START_PULSE_MIN (3880-200)
|
|
|
+#define START_PULSE_MAX (4010+200)
|
|
|
+
|
|
|
+#define T0_PULSE_MIN (380-100)
|
|
|
+#define T0_PULSE_MAX (520+100)
|
|
|
+
|
|
|
+#define SHORT_PULSE_MIN (890-100)
|
|
|
+#define SHORT_PULSE_MAX (990+100)
|
|
|
+
|
|
|
+#define LONG_PULSE_MIN (1880-150)
|
|
|
+#define LONG_PULSE_MAX (1980+150)
|
|
|
+
|
|
|
+
|
|
|
static int32_t rx_decode(uint32_t width)
|
|
|
{
|
|
|
switch (rx_state) {
|
|
|
case UNKNOWN: // Start of frame
|
|
|
- if (3700 <= width && width <= 4150)
|
|
|
+ if ( START_PULSE_MIN <= width && width <= START_PULSE_MAX )
|
|
|
{
|
|
|
rx_state = T0;
|
|
|
- debug_width = width;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -60,17 +70,16 @@ static int32_t rx_decode(uint32_t width)
|
|
|
if (rx_numBits == 32)
|
|
|
{ // end of frame
|
|
|
rx_state = DONE;
|
|
|
- //printf("c");
|
|
|
sensor_data = (sensor_data >> 8); // Mask away some bits at the end
|
|
|
return 1;
|
|
|
}
|
|
|
- else if (420 <= width && width <= 560)
|
|
|
+ else if( T0_PULSE_MIN <= width && width <= T0_PULSE_MAX )
|
|
|
{
|
|
|
rx_state = T1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (rx_numBits == 0 && 3700 <= width && width <= 4150 )
|
|
|
+ if (rx_numBits == 0 && START_PULSE_MIN <= width && width <= START_PULSE_MAX )
|
|
|
{
|
|
|
rx_state = T0;
|
|
|
}
|
|
@@ -82,13 +91,12 @@ static int32_t rx_decode(uint32_t width)
|
|
|
break;
|
|
|
|
|
|
case T1:
|
|
|
- if (880 <= width && width <= 1080)
|
|
|
+ if( SHORT_PULSE_MIN <= width && width <= SHORT_PULSE_MAX )
|
|
|
{
|
|
|
addBit(0);
|
|
|
}
|
|
|
- else if (1800 <= width && width <= 2100)
|
|
|
+ else if( LONG_PULSE_MIN <= width && width <= LONG_PULSE_MAX )
|
|
|
{
|
|
|
- //debug_width = width;
|
|
|
addBit(1);
|
|
|
}
|
|
|
else
|
|
@@ -119,7 +127,6 @@ int64_t nextPulseClasOSensor(uint32_t width)
|
|
|
break;
|
|
|
case 1:
|
|
|
rx_state = DONE;
|
|
|
- //printf("%d\n",debug_width);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -127,17 +134,12 @@ 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;
|
|
|
blinkTheLED();
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
old_time = now;
|
|
|
ClasO_ResetDecoder();
|