Jelajahi Sumber

IR Tx Checksum works

Thomas Chef 1 tahun lalu
induk
melakukan
11f93f1918
1 mengubah file dengan 26 tambahan dan 8 penghapusan
  1. 26 8
      main/ir_transmit.c

+ 26 - 8
main/ir_transmit.c

@@ -19,8 +19,13 @@ extern uint8_t bitReverse(uint8_t b);
 #define RMT_CLK_DIV    80
 
 // Variable that holds the IR protocol transmission. 1 start bit, 8*8+19*8 data bits and one stop bit
-#define RMT_BITS (1+64+1+1+152+1+1) // 221 bits in total
+#define STATIC_PRE_BYTES 8
+#define DYN_DATA_BYTES 19
+#define TOT_DATA_BYTES (STATIC_PRE_BYTES+DYN_DATA_BYTES)
+#define RMT_BITS (1+(STATIC_PRE_BYTES*8)+1+1+(DYN_DATA_BYTES*8)+1+1) // 221 bits in total
+
 rmt_item32_t toshiba_rmt[RMT_BITS];
+uint8_t irTxData[TOT_DATA_BYTES];
 
 QueueHandle_t toshibaTxQueue = NULL;
 
@@ -35,6 +40,14 @@ void copyDataToRmtArray( const uint8_t rmtStartBit, const uint8_t* data, const u
     }
 }
 
+void correctIrTxDataChecksum() {
+
+	irTxData[TOT_DATA_BYTES-1] = 0xFA;
+	for( uint8_t b=0+STATIC_PRE_BYTES ; b<(TOT_DATA_BYTES-1) ; b++ ) {
+		irTxData[TOT_DATA_BYTES-1] += irTxData[b];
+	}
+}
+
 void toshibaTxTask(void *pvParameter)
 {
 	ESP_LOGI("IR_TRANSMIT", "toshibaTxTask() starting.");
@@ -117,15 +130,20 @@ void initIrTransmit() {
     toshiba_rmt[220].val = (1 << 16);    // RMT End marker
 
 	// Setup the fixed 64 bits: 0x4004072000000060 (Sent like this)
-	const uint8_t fixedData[8]={0x40,0x04,0x07,0x20,0x0,0x00,0x0,0x60};
-	//memcpy(data,(void *)&fixedData[0],8);	// Copy the fixed data
-	copyDataToRmtArray(1,fixedData,8,false);
+	//const uint8_t fixedData[STATIC_PRE_BYTES]={0x40,0x04,0x07,0x20,0x0,0x00,0x0,0x60}; // Non-reversed
+	const uint8_t fixedData[STATIC_PRE_BYTES]={0x02,0x20,0xE0,0x04,0x00,0x00,0x00,0x06}; // Reversed
+	memcpy(&irTxData[0],(void *)&fixedData[0],STATIC_PRE_BYTES);	// Copy the fixed data
 
 	// Setup the the real 152 data bits
-	const uint8_t confData[19]={0x02,0x20,0xE0,0x04,0x00,0x49,0x31,0x86,	// 0x86 is correct
-	                            0xA3,0x06,0x00,0x0E,0xE0,0x00,0x00,0x89,
-								0x00,0x00,0x20 };
-	copyDataToRmtArray(67,confData,19,true);
+	const uint8_t confData[DYN_DATA_BYTES]={0x02,0x20,0xE0,0x04,0x00,0x49,0x31,0x86,	// 0x86 is correct
+	                            			0xA3,0x06,0x00,0x0E,0xE0,0x00,0x00,0x89,
+											0x00,0x00,0x20 };
+	memcpy(&irTxData[0+STATIC_PRE_BYTES],(void *)&confData[0],DYN_DATA_BYTES);
+
+	correctIrTxDataChecksum();
+	
+	copyDataToRmtArray(1,&irTxData[0],STATIC_PRE_BYTES,true);
+	copyDataToRmtArray(67,&irTxData[8],DYN_DATA_BYTES,true);
 
     toshibaTxQueue = xQueueCreate( 5, kPanasonicNumberOfBytes );
 	//xTaskCreatePinnedToCore(toshibaTxTask, "toshibaTxTask", 1024*10, NULL, 2, NULL,0);