1
0
Quellcode durchsuchen

Data union works for Mode,Fan and Temp

Thomas Chef vor 2 Jahren
Ursprung
Commit
036df8e3b7
3 geänderte Dateien mit 79 neuen und 58 gelöschten Zeilen
  1. 7 13
      main/receiver.c
  2. 36 13
      main/toshiba_ir.c
  3. 36 32
      main/toshiba_ir.h

+ 7 - 13
main/receiver.c

@@ -23,13 +23,6 @@
 uint32_t dataArr[1000];
 uint32_t dataArrIdx = 0;
 
-static int convertToSignedTemp(unsigned int value)
-{
-
-	//int signValue;
-
-	return ( (value >> 11) == 0 )? value : ((-1 ^ 0xFFF) | value);
-}
 
 void receiverTask(void *pvParameter)
 {
@@ -47,15 +40,16 @@ void receiverTask(void *pvParameter)
             //if( dataArrIdx == 1000 ) dataArrIdx=0;
 
             // Receive the Toshiba IR
-            int64_t data = nextPulseToshiba_ir(width);
-            if( data != -1 ) {
+            union ToshibaProtocolU* data = (union ToshibaProtocolU*)nextPulseToshiba_ir(width);
+            if( data != NULL ) {
+
+                ESP_LOGI("TOSHIBA", "Data: %02X %02X %02X %02X %02X %02X %02X %02X %02X",data->raw[8],data->raw[7],data->raw[6],data->raw[5],data->raw[4],data->raw[3],data->raw[2],data->raw[1],data->raw[0]);
 
-                int value      = convertToSignedTemp( data & 0xFFF );
-                unsigned char id         = (data>>12) & 0x007;
+                const uint8_t fan = (data->data.Fan > 0) ? data->data.Fan-1 : data->data.Fan;
+                const uint8_t power = (data->data.Mode == 3) ? 1 : 0;
+                ESP_LOGI("TOSHIBA","Mode:%u Temp:%u Fan:%u",power,data->data.Temp+17u,fan);
 
-                ESP_LOGI("RX", "ClasO:  <TR%08llX> %u               %4.1f",data,id, (float)value/10);
 
-                //sprintf(dataStr,"<TR%08llX>",data);
 #ifdef WIFI_ENABLED
                 sendUDPMessage(dataStr, true);
 #endif

+ 36 - 13
main/toshiba_ir.c

@@ -5,6 +5,29 @@
 #include "rxTimer.h"
 #include <string.h>
 
+/**
+ * @Analys of Toshiba IR Rx:
+ *  0  1  2  3  4  5  6  7  8
+ * F2 0D 03 FC 01 D0 A3 00 72       30 Grader
+ * F2 0D 03 FC 01 90 A3 00 32       26 Grader
+ * F2 0D 03 FC 01 40 A3 00 E2       21 Grader
+ * F2 0D 03 FC 01 30 A3 00 92       20 Grader
+ * F2 0D 03 FC 01 20 A3 00 82       19 Grader
+ * F2 0D 03 FC 01 10 A3 00 B2       18
+ * F2 0D 03 FC 01 00 A3 00 A2       17
+ * 
+ * F2 0D 03 FC 01 D0 03 00 D2       Auto Fan  0000  0 (0 is Auto, 2-6 is the speed, 6 is Max)
+ * F2 0D 03 FC 01 D0 43 00 92       1         0100  2
+ *                                  2         0110  3
+ * F2 0D 03 FC 01 D0 83 00 52       3         1000  4
+ *                                  4         1010  5
+ * F2 0D 03 FC 01 D0 C3 00 12       5         1100  6
+ * 
+ * F2 0D 03 FC 01 60 83 00 E2       ON        1000 0011 (3 is ON, 7 is OFF)
+ * F2 0D 03 FC 01 60 87 00 E6       OFF       1000 0111
+ * 
+ */
+
 // Toshiba A/C
 const uint16_t kToshibaAcHdrMark = 4400;
 const uint16_t kToshibaAcHdrSpace = 4480;
@@ -16,10 +39,9 @@ const uint16_t kToshibaAcZeroSpace = 530;
 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];
+uint8_t data[kToshibaNumberOfBytes];            // Temp data during rx
+uint8_t dataTransfer[kToshibaNumberOfBytes];    // Send as pointer to receiver
 
 enum
 {
@@ -37,7 +59,7 @@ static uint32_t rx_numBits;
 
 void Toshiba_ir_ResetDecoder()
 {
-    ESP_LOGI("T", "Reset decoder");
+    //ESP_LOGI("T", "Reset decoder");
     rx_numBits = kToshibaNumberOfBits;
     rx_state = UNKNOWN;
     memset(data,0,kToshibaNumberOfBytes);
@@ -105,12 +127,12 @@ static int32_t rx_decode(uint32_t width)
 
             if(rx_numBits == 0)
             { // end of frame
-                ESP_LOGI("T", "END OF FRAME");
+                //ESP_LOGI("T", "END OF FRAME");
                 rx_state = DONE;
 
-                for(uint8_t i=9; i>0 ;i--) {
+                /*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 )
@@ -145,9 +167,11 @@ static int32_t rx_decode(uint32_t width)
     return 0;
 }
 
-int64_t nextPulseToshiba_ir(uint32_t width)
+
+
+uint8_t* nextPulseToshiba_ir(uint32_t width)
 {
-    int64_t retVal = -1;
+    uint8_t* retVal = NULL;
 
     if (width > 0)
     {
@@ -160,14 +184,13 @@ int64_t nextPulseToshiba_ir(uint32_t width)
                 break;
             case 1:
                 rx_state = DONE;
+                memcpy(dataTransfer,data,kToshibaNumberOfBytes);
+                Toshiba_ir_ResetDecoder();
+                retVal = dataTransfer;
                 break;
             }
         }
     }
-    if (rx_state == DONE) {
-
-        Toshiba_ir_ResetDecoder();
-    }
     
     return retVal;
 }

+ 36 - 32
main/toshiba_ir.h

@@ -6,48 +6,52 @@
 
 void Toshiba_ir_ResetDecoder ();
 
-int64_t nextPulseToshiba_ir(uint32_t width);
+uint8_t* nextPulseToshiba_ir(uint32_t width);
 
-#define  kToshibaACStateLengthLong  10
+#define kToshibaNumberOfBits 72
+#define kToshibaNumberOfBytes (kToshibaNumberOfBits/8)
 
-union ToshibaProtocol{
-  uint8_t raw[kToshibaACStateLengthLong];  ///< The state in code form.
-  struct {
-    // Byte[0] - 0xF2
-    uint8_t :8;
-    // Byte[1] - 0x0D (inverted previous byte's value)
-    uint8_t :8;
-    // Byte[2] - The expected payload length (in bytes) past the Byte[4].
-    ///< Known lengths are:
-    ///<   1 (56 bit message)
-    ///<   3 (72 bit message)
-    ///<   4 (80 bit message)
-    uint8_t Length   :8;
-    // Byte[3] - The bit-inverted value of the "length" byte.
-    uint8_t          :8;
-    // Byte[4]
+struct toshibaDataBits {
+    // Byte[8]
+    // (Checksum for 72 bit messages, Eco/Turbo for long 80 bit messages)
+    uint8_t EcoTurbo :8;
+    // Byte[7]
+    uint8_t          :4;
+    uint8_t Filter   :1;
     uint8_t          :3;
-    uint8_t LongMsg  :1;
-    uint8_t          :1;
-    uint8_t ShortMsg :1;
+    // Byte[6]
+    uint8_t Mode     :3;
     uint8_t          :2;
+    uint8_t Fan      :3;
     // Byte[5]
     uint8_t Swing    :3;
     uint8_t          :1;
     uint8_t Temp     :4;
-    // Byte[6]
-    uint8_t Mode     :3;
-    uint8_t          :2;
-    uint8_t Fan      :3;
-    // Byte[7]
-    uint8_t          :4;
-    uint8_t Filter   :1;
+    // Byte[4]
     uint8_t          :3;
+    uint8_t LongMsg  :1;
+    uint8_t          :1;
+    uint8_t ShortMsg :1;
+    uint8_t          :2;
+    // Byte[3] - The bit-inverted value of the "length" byte.
+    uint8_t          :8;
+    // Byte[2] - The expected payload length (in bytes) past the Byte[4].
+    ///< Known lengths are:
+    ///<   1 (56 bit message)
+    ///<   3 (72 bit message)
+    ///<   4 (80 bit message)
+    uint8_t Length   :8;
+    // Byte[1] - 0x0D (inverted previous byte's value)
+    uint8_t :8;
+    // Byte[0] - 0xF2
+    uint8_t StartByte :8;
+    
+};
 
-    // Byte[8]
-    // (Checksum for 72 bit messages, Eco/Turbo for long 80 bit messages)
-    uint8_t EcoTurbo :8;
-  };
+
+union ToshibaProtocolU {
+  uint8_t raw[kToshibaNumberOfBytes];  ///< The state in code form.
+  struct toshibaDataBits data;
 };
 
 #endif