|
@@ -3,60 +3,96 @@
|
|
|
#include <stdio.h>
|
|
|
#include "esp_log.h"
|
|
|
#include "rxTimer.h"
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+// Toshiba A/C
|
|
|
+const uint16_t kToshibaAcHdrMark = 4400;
|
|
|
+const uint16_t kToshibaAcHdrSpace = 4480;
|
|
|
+const uint16_t kToshibaAcBitMark = 530;
|
|
|
+const uint16_t kToshibaAcOneSpace = 1600;
|
|
|
+const uint16_t kToshibaAcZeroSpace = 530;
|
|
|
+// Some models have a different inter-message gap.
|
|
|
+// See: https://github.com/crankyoldgit/IRremoteESP8266/issues/1420
|
|
|
+const uint16_t kToshibaAcMinGap = 4600; // WH-UB03NJ remote
|
|
|
+const uint16_t kToshibaAcUsualGap = 7400; // Others
|
|
|
+
|
|
|
+#define kToshibaNumberOfBits 72
|
|
|
+#define kToshibaNumberOfBytes (kToshibaNumberOfBits/8)
|
|
|
+
|
|
|
+uint8_t data[kToshibaNumberOfBytes];
|
|
|
|
|
|
enum
|
|
|
{
|
|
|
UNKNOWN,
|
|
|
+ STARTER,
|
|
|
T0,
|
|
|
T1,
|
|
|
- T2,
|
|
|
- T3,
|
|
|
- TEMP1_OK,
|
|
|
DONE
|
|
|
};
|
|
|
|
|
|
static uint8_t rx_state = UNKNOWN;
|
|
|
|
|
|
-static uint64_t sensor_data;
|
|
|
static uint32_t rx_numBits;
|
|
|
|
|
|
|
|
|
void Toshiba_ir_ResetDecoder()
|
|
|
{
|
|
|
- sensor_data = 0;
|
|
|
- rx_numBits = 0;
|
|
|
+ ESP_LOGI("T", "Reset decoder");
|
|
|
+ rx_numBits = kToshibaNumberOfBits;
|
|
|
rx_state = UNKNOWN;
|
|
|
+ memset(data,0,kToshibaNumberOfBytes);
|
|
|
}
|
|
|
|
|
|
static void addBit(uint8_t value)
|
|
|
{
|
|
|
+ if( value == 1 ) {
|
|
|
+
|
|
|
+
|
|
|
+ const uint8_t byteNo = (rx_numBits+7) / 8;
|
|
|
+ const uint8_t shiftBits = (int)rx_numBits - (byteNo*8) + 7;
|
|
|
+
|
|
|
+ //ESP_LOGI("BIT RX:","%u %u", byteNo, shiftBits);
|
|
|
|
|
|
- rx_numBits++;
|
|
|
- sensor_data = (sensor_data << 1) + (value & 0x01);
|
|
|
|
|
|
- rx_state = TEMP1_OK;
|
|
|
+ data[byteNo-1] |= ((uint8_t)1u) << shiftBits;
|
|
|
+ }
|
|
|
+
|
|
|
+ rx_numBits--;
|
|
|
}
|
|
|
|
|
|
-#define START_PULSE_MIN (3880-200)
|
|
|
-#define START_PULSE_MAX (4010+200)
|
|
|
+#define START_PULSE_MIN (kToshibaAcHdrMark-200)
|
|
|
+#define START_PULSE_MAX (kToshibaAcHdrMark+200)
|
|
|
|
|
|
-#define T0_PULSE_MIN (380-100)
|
|
|
-#define T0_PULSE_MAX (520+100)
|
|
|
+#define T0_PULSE_MIN (kToshibaAcBitMark-100)
|
|
|
+#define T0_PULSE_MAX (kToshibaAcBitMark+100)
|
|
|
|
|
|
-#define SHORT_PULSE_MIN (890-100)
|
|
|
-#define SHORT_PULSE_MAX (990+100)
|
|
|
+#define SHORT_PULSE_MIN (kToshibaAcZeroSpace-100)
|
|
|
+#define SHORT_PULSE_MAX (kToshibaAcZeroSpace+100)
|
|
|
|
|
|
-#define LONG_PULSE_MIN (1880-150)
|
|
|
-#define LONG_PULSE_MAX (1980+150)
|
|
|
+#define LONG_PULSE_MIN (kToshibaAcOneSpace-100)
|
|
|
+#define LONG_PULSE_MAX (kToshibaAcOneSpace+100)
|
|
|
|
|
|
|
|
|
static int32_t rx_decode(uint32_t width)
|
|
|
{
|
|
|
switch (rx_state) {
|
|
|
- case UNKNOWN: // Start of frame
|
|
|
+ case UNKNOWN: // Start of frame A
|
|
|
+ if ( START_PULSE_MIN <= width && width <= START_PULSE_MAX )
|
|
|
+ {
|
|
|
+ rx_state = STARTER;
|
|
|
+ //ESP_LOGI("T", "->STARTER");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return -1; // error, reset
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case STARTER: // Start of frame B
|
|
|
if ( START_PULSE_MIN <= width && width <= START_PULSE_MAX )
|
|
|
{
|
|
|
rx_state = T0;
|
|
|
+ //ESP_LOGI("T", "STARTER");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -64,28 +100,27 @@ static int32_t rx_decode(uint32_t width)
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
+
|
|
|
case T0: // First half of pulse : HIGH around 230us
|
|
|
|
|
|
- if (rx_numBits == 32)
|
|
|
+ if(rx_numBits == 0)
|
|
|
{ // end of frame
|
|
|
+ ESP_LOGI("T", "END OF FRAME");
|
|
|
rx_state = DONE;
|
|
|
- sensor_data = (sensor_data >> 8); // Mask away some bits at the end
|
|
|
+
|
|
|
+ for(uint8_t i=9; i>0 ;i--) {
|
|
|
+ ESP_LOGI("DATA","Byte %u : %02x", i-1, data[i-1]);
|
|
|
+ }
|
|
|
return 1;
|
|
|
}
|
|
|
else if( T0_PULSE_MIN <= width && width <= T0_PULSE_MAX )
|
|
|
{
|
|
|
rx_state = T1;
|
|
|
+ //ESP_LOGI("T", "T0");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (rx_numBits == 0 && START_PULSE_MIN <= width && width <= START_PULSE_MAX )
|
|
|
- {
|
|
|
- rx_state = T0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return -1; // error, reset
|
|
|
- }
|
|
|
+ return -1; // error, reset
|
|
|
}
|
|
|
break;
|
|
|
|
|
@@ -93,10 +128,12 @@ static int32_t rx_decode(uint32_t width)
|
|
|
if( SHORT_PULSE_MIN <= width && width <= SHORT_PULSE_MAX )
|
|
|
{
|
|
|
addBit(0);
|
|
|
+ //ESP_LOGI("T", "Short %u",rx_numBits);
|
|
|
}
|
|
|
else if( LONG_PULSE_MIN <= width && width <= LONG_PULSE_MAX )
|
|
|
{
|
|
|
addBit(1);
|
|
|
+ //ESP_LOGI("T", "Long %u", rx_numBits);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -110,9 +147,6 @@ static int32_t rx_decode(uint32_t width)
|
|
|
|
|
|
int64_t nextPulseToshiba_ir(uint32_t width)
|
|
|
{
|
|
|
- static int64_t previous_data = 0;
|
|
|
- static uint32_t old_time=0;
|
|
|
- static uint32_t now;
|
|
|
int64_t retVal = -1;
|
|
|
|
|
|
if (width > 0)
|
|
@@ -131,14 +165,7 @@ int64_t nextPulseToshiba_ir(uint32_t width)
|
|
|
}
|
|
|
}
|
|
|
if (rx_state == DONE) {
|
|
|
- now = millis();
|
|
|
|
|
|
- if( sensor_data != previous_data || (now > (old_time+1000)) ) {
|
|
|
- previous_data = sensor_data;
|
|
|
- retVal = sensor_data;
|
|
|
-
|
|
|
- }
|
|
|
- old_time = now;
|
|
|
Toshiba_ir_ResetDecoder();
|
|
|
}
|
|
|
|