//For SWTL

#include "RTE.h"

#include <stddef.h>                     // Defines NULL
#include <stdbool.h>                    // Defines true
#include <stdlib.h>                     // Defines EXIT_FAILURE
#include "../OsekCom/OsekCom.h"
#include "../Speaker/Speaker.h"
#include "TouchPanel/TouchPanel.h"
#include   "forceSnsr.h"
#include   "forceSnsr_Cfg.h"
#include   "forcedetect.h"
#include "TouchPanel.h"
//#include "TouchPanel_Cfg.h"
#include "Std_Types.h"
#include "device.h" 
#include "touch/touch.h"
#include "math.h"
#include "stdlib.h"


#include <stddef.h>                     // Defines NULL
#include <stdbool.h>                    // Defines true
#include <stdlib.h>                     // Defines EXIT_FAILURE
#include "definitions.h"                // SYS function prototypes
#include "OsekCom/OsekCom.h"
#include "Speaker/Speaker.h"
#include "P417_SWTL_App_ert_rtw/P417_SWTL_App.h"
#include "TouchPanel/TouchPanel.h"
#include "forceSnsr/forcedetect.h"
#include "TLE9263/TLE926x_Main.h"
#include "DiagnosticL/UDS/UDS_Services_Common.h"
#include "plib_systick.h"
//For SWTL

//#include "Global.h"
#ifndef uint8_t
#define uint8_t unsigned char
#endif

#ifndef uint16_t
#define uint16_t unsigned short
#endif

#ifndef uint32_t
#define uint32_t unsigned int
#endif



#define Cncl_Btn_E2EID    ((uint16_t)(0x2136)) // in CAN ID 0x305
uint8_t g_speeker_event = 0x00;

#if 0
static uint8_t autoCrc_Table[256] =

         {

                  0x00u, 0x1du, 0x3au, 0x27u, 0x74u, 0x69u, 0x4eu, 0x53u,

                  0xe8u, 0xf5u, 0xd2u, 0xcfu, 0x9cu, 0x81u, 0xa6u, 0xbbu,

                  0xcdu, 0xd0u, 0xf7u, 0xeau, 0xb9u, 0xa4u, 0x83u, 0x9eu,

                  0x25u, 0x38u, 0x1fu, 0x02u, 0x51u, 0x4cu, 0x6bu, 0x76u,

                  0x87u, 0x9au, 0xbdu, 0xa0u, 0xf3u, 0xeeu, 0xc9u, 0xd4u,

                  0x6fu, 0x72u, 0x55u, 0x48u, 0x1bu, 0x06u, 0x21u, 0x3cu,

                  0x4au, 0x57u, 0x70u, 0x6du, 0x3eu, 0x23u, 0x04u, 0x19u,

                  0xa2u, 0xbfu, 0x98u, 0x85u, 0xd6u, 0xcbu, 0xecu, 0xf1u,

                  0x13u, 0x0eu, 0x29u, 0x34u, 0x67u, 0x7au, 0x5du, 0x40u,

                  0xfbu, 0xe6u, 0xc1u, 0xdcu, 0x8fu, 0x92u, 0xb5u, 0xa8u,

                  0xdeu, 0xc3u, 0xe4u, 0xf9u, 0xaau, 0xb7u, 0x90u, 0x8du,

                  0x36u, 0x2bu, 0x0cu, 0x11u, 0x42u, 0x5fu, 0x78u, 0x65u,

                  0x94u, 0x89u, 0xaeu, 0xb3u, 0xe0u, 0xfdu, 0xdau, 0xc7u,

                  0x7cu, 0x61u, 0x46u, 0x5bu, 0x08u, 0x15u, 0x32u, 0x2fu,

                  0x59u, 0x44u, 0x63u, 0x7eu, 0x2du, 0x30u, 0x17u, 0x0au,

                  0xb1u, 0xacu, 0x8bu, 0x96u, 0xc5u, 0xd8u, 0xffu, 0xe2u,

                  0x26u, 0x3bu, 0x1cu, 0x01u, 0x52u, 0x4fu, 0x68u, 0x75u,

                  0xceu, 0xd3u, 0xf4u, 0xe9u, 0xbau, 0xa7u, 0x80u, 0x9du,

                  0xebu, 0xf6u, 0xd1u, 0xccu, 0x9fu, 0x82u, 0xa5u, 0xb8u,

                  0x03u, 0x1eu, 0x39u, 0x24u, 0x77u, 0x6au, 0x4du, 0x50u,

                  0xa1u, 0xbcu, 0x9bu, 0x86u, 0xd5u, 0xc8u, 0xefu, 0xf2u,

                  0x49u, 0x54u, 0x73u, 0x6eu, 0x3du, 0x20u, 0x07u, 0x1au,

                  0x6cu, 0x71u, 0x56u, 0x4bu, 0x18u, 0x05u, 0x22u, 0x3fu,

                  0x84u, 0x99u, 0xbeu, 0xa3u, 0xf0u, 0xedu, 0xcau, 0xd7u,

                  0x35u, 0x28u, 0x0fu, 0x12u, 0x41u, 0x5cu, 0x7bu, 0x66u,

                  0xddu, 0xc0u, 0xe7u, 0xfau, 0xa9u, 0xb4u, 0x93u, 0x8eu,

                  0xf8u, 0xe5u, 0xc2u, 0xdfu, 0x8cu, 0x91u, 0xb6u, 0xabu,

                  0x10u, 0x0du, 0x2au, 0x37u, 0x64u, 0x79u, 0x5eu, 0x43u,

                  0xb2u, 0xafu, 0x88u, 0x95u, 0xc6u, 0xdbu, 0xfcu, 0xe1u,

                  0x5au, 0x47u, 0x60u, 0x7du, 0x2eu, 0x33u, 0x14u, 0x09u,

                  0x7fu, 0x62u, 0x45u, 0x58u, 0x0bu, 0x16u, 0x31u, 0x2cu,

                  0x97u, 0x8au, 0xadu, 0xb0u, 0xe3u, 0xfeu, 0xd9u, 0xc4u

         };
#endif


//volatile uint8_t TouchBoard_RC;

//volatile uint8_t TouchBoard_Sts;
//volatile uint8_t TouchBoard_X;
//volatile uint8_t TouchBoard_Y;
uint8_t RTE_Get_TouchBoard_CRC(void)
{
         return 0;
}

volatile uint8_t Cancel_RC;

volatile uint8_t Cancel_Sts;
volatile uint8_t Cancel_Qf1;

uint8_t RTE_Get_RC(void)
{
    return Cancel_RC;
}

//#define Cncl_Btn_E2EID    ((uint16_t)(0x2136)) // in CAN ID 0x305
uint8_t RTE_Get_Cancel_CRC(void)
{
#if 0
    uint8_t Crc_Value;
   uint8_t Crc_LoopCounter;
   uint8_t Data[5];
   Data[0]=(uint8_t)( Cncl_Btn_E2EID & 0x00FF ); // E2E ID low byte
   Data[1]=(uint8_t)((Cncl_Btn_E2EID & 0xFF00) >> 8); // E2E ID high byte
   Data[2]=Cancel_RC;
   Data[3]=Cancel_Qf1;
   Data[4]=Cancel_Sts;
   Crc_Value = 0;
    for (Crc_LoopCounter = 0; Crc_LoopCounter < 5; Crc_LoopCounter++)

         {

                  Crc_Value = autoCrc_Table[Crc_Value ^ Data[Crc_LoopCounter]];

         }
   return Crc_Value ^ 0u;
#endif
   uint8_t Crc_Value =0x00;
   uint8_t i,j;
   uint8_t Data[5];
   Data[0]=(uint8_t)( Cncl_Btn_E2EID & 0x00FF ); // E2E ID low byte
   Data[1]=(uint8_t)((Cncl_Btn_E2EID & 0xFF00) >> 8); // E2E ID high byte
   Data[2]=Cancel_RC;
   Data[3]=Cancel_Qf1;
   Data[4]=Cancel_Sts;
   
   for(i=0; i<5; i++)
   {
       Crc_Value ^= Data[i];
       for(j=0; j<8; j++)
       {
           if(Crc_Value & 0x80u)
           {
               Crc_Value <<= 1;
               Crc_Value ^= 0x1du;      
           }
           else
           {
               Crc_Value <<= 1;
           }
       }
   }
   Crc_Value ^= 0x00u;
   
   return Crc_Value&0xffu;
}




//Input Sensor
//uint16_t RTE_Get_Power_AD_SNS(void);

//uint8_t RTE_Get_Pressure_Sensor_xxxx(void);//IIC DATA?

//Not active,Touch,Touch and Press,invalid from sensor
uint8_t RTE_Get_TouchBoard_Up_Sts(void)
{
    /* y:a7, x: e6 */
    /* y:8d, x: eb */
    /* y:75, x: ed */
    /* y:6a, x: eb */
    /* y:75, x: eb */
	Buttons_SignalType Signal;

	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		Signal = BUTTON_RELEASE;
	}else{
	 	Signal = TouchPanel_BtnSignalRead(BTN_UP);
	}

	return Signal;
}

uint8_t RTE_Get_TouchBoard_Down_Sts(void)
{
    /* x:26, y: 96 */
    /* x:20, y: 80 */
    /* x:20, y: 80 */
	Buttons_SignalType Signal;

	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		Signal = BUTTON_RELEASE;
	}else{
	 	Signal = TouchPanel_BtnSignalRead(BTN_DOWN);
	}

	return Signal;
}

uint8_t RTE_Get_TouchBoard_Left_Sts(void)
{
    /* x:95, y: ec */
    /* x:97, y: e9 */
	Buttons_SignalType Signal;

 	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		Signal = BUTTON_RELEASE;
	}else{
	 	Signal = TouchPanel_BtnSignalRead(BTN_LEFT);
	}   
	return Signal;
}

uint8_t RTE_Get_TouchBoard_Right_Sts(void)
{
    /* x:98, y: 22 */
    /* x:9d, y: 27 */
    /* x:94, y: 25 */
	Buttons_SignalType Signal;
  	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		Signal = BUTTON_RELEASE;
	}else{
	 	Signal = TouchPanel_BtnSignalRead(BTN_RIGHT);
	}    
	
	return Signal;
}

uint8_t RTE_Get_TouchBoard_Center_Sts(void)
{
	Buttons_SignalType Signal;

  	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		Signal = BUTTON_RELEASE;
	}else{
	 	Signal = TouchPanel_BtnSignalRead(BTN_CONFIRM);
	}   
	
	return Signal;
}



uint8_t RTE_Get_TouchBoard_ADAS1_Sts(void)//TJP1
{
	Buttons_SignalType Signal;
	Signal = TouchPanel_BtnSignalRead(BTN_ADAS1);	    
    return Signal;
}
uint8_t RTE_Get_TouchBoard_ADAS2_Sts(void)//TJP2
{
	Buttons_SignalType Signal = BUTTON_RELEASE;
	//Signal = TouchPanel_BtnSignalRead(BTN_TJP2);	
    
    return Signal;
}


uint8_t RTE_Get_TouchBoard_Resu1_Sts(void)//Resume1
{
	Buttons_SignalType Signal;
	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		Signal = BUTTON_RELEASE;
	}
	else if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) && BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1))
	{
		Signal = BUTTON_RELEASE;
	}
	else
	{
		Signal = TouchPanel_BtnSignalRead(BTN_RESUME1); 
	}
	
    return Signal;	
}
uint8_t RTE_Get_TouchBoard_Resu2_Sts(void)//Resume2
{
	 Buttons_SignalType Signal = BUTTON_RELEASE;
	 //Signal = TouchPanel_BtnSignalRead(BTN_RES2);	 
	 
	 return Signal;  
}

uint8_t RTE_Get_TouchBoard_Cncl1_Sts(void)//Cancel1
{
	Buttons_SignalType Signal;

	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		Signal = BUTTON_RELEASE;
	}
	else if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) && BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1))
	{
		Signal = BUTTON_RELEASE;
	}
	else
	{
		Signal = TouchPanel_BtnSignalRead(BTN_CANCEL1); 
	}
	return Signal;	
}
uint8_t RTE_Get_TouchBoard_Cncl2_Sts(void)//Cancel2
{
	Buttons_SignalType Signal = BUTTON_RELEASE;
	//Signal = TouchPanel_BtnSignalRead(BTN_CANCEL2);	
	
	return Signal;	
}


//touch borad left/right slide: 0:idle, 1:short slide left 2:short slide right 3:long slide left 4:long slide right
uint8_t RTE_Get_TouchBoard_Left_Right_Slide_Sts(void)
{
    uint8_t retval = SIG_SWPLERISTSLE_SWPLERIREQSTS_IDLE;
#if 1
	TP_SlideDirection_Enum SlideDir;
	SlideDir = TouchPanel_SlideEventRead();
	switch(SlideDir)
	{
		case TP_SlideDirection_ShortLEFT:
			retval = SIG_SWPLERISTSLE_SWPLERIREQSTS_SHORTSLIDELEFT;
		break;
		case TP_SlideDirection_LongLEFT:
			retval = SIG_SWPLERISTSLE_SWPLERIREQSTS_LONGSLIDELEFT;
		break;
		case TP_SlideDirection_ShortRIGHT:
			retval = SIG_SWPLERISTSLE_SWPLERIREQSTS_SHORTSLIDERIGHT;
		break;
		case TP_SlideDirection_LongRIGHT:
			retval = SIG_SWPLERISTSLE_SWPLERIREQSTS_LONGSLIDERIGHT;
		break;
		default: break;
	}
#endif
     return retval;
}

//touch borad Up/Down slide: 0:idle, 1:short slide up 2:short slide down 3:long slide up 4:long slide down
uint8_t RTE_Get_TouchBoard_Up_Down_Slide_Sts(void)
{
    uint8_t retval = SIG_SWPUPDWNSTSLE_SWPUPDWNREQSTS_IDLE;
#if 1
	TP_SlideDirection_Enum SlideDir;
	SlideDir = TouchPanel_SlideEventRead();
	switch(SlideDir)
	{
		case TP_SlideDirection_ShortUP:
			retval = SIG_SWPUPDWNSTSLE_SWPUPDWNREQSTS_SHORTSLIDEUP;
		break;
		case TP_SlideDirection_LongUP:
			retval = SIG_SWPUPDWNSTSLE_SWPUPDWNREQSTS_LONGSLIDEUP;
		break;
		case TP_SlideDirection_ShortDOWN:
			retval = SIG_SWPUPDWNSTSLE_SWPUPDWNREQSTS_SHORTSLIDEDOWN;
		break;
		case TP_SlideDirection_LongDOWN:
			retval = SIG_SWPUPDWNSTSLE_SWPUPDWNREQSTS_LONGSLIDEDOWN;
		break;
		default: break;
	}

#endif
        return retval;
}


//uint8_t RTE_Get_INTB_PRSS_SNS(void);



//uint8_t RTE_Get_X1_SNS(void);
//uint8_t RTE_Get_X2_SNS(void);
//uint8_t RTE_Get_X3_SNS(void);
//uint8_t RTE_Get_X4_SNS(void);
//uint8_t RTE_Get_X5_SNS(void);
#define Initial_Movement_Hysteresis 10
#define Next_Movement_Hysteresis 5
#define X_Length 6
#define Y_Length 6

uint8_t X_Buf[X_Length];
uint8_t Y_Buf[Y_Length];
uint8_t X_CNT;
uint8_t Y_CNT;
uint8_t Stable_CNT_X;
uint8_t Stable_CNT_Y;
uint8_t X_Update_Flg;
uint8_t Y_Update_Flg;
uint8_t X_Update;
uint8_t Y_Update;
uint8_t rtn_X;
uint8_t rtn_Y;

uint8_t RTE_Get_X_SNS(void)
{
#if 0
    uint8_t count;
    uint16_t sum_x=0;
    uint8 x_pos;
	GetSurface_Position(&x_pos, NULL_PTR);
    X_Buf[X_CNT++]=x_pos;
    if(X_CNT==X_Length)
    {
        X_CNT=0;
    }
    for(count=0;count<X_Length;count++)
    {
        sum_x+=(uint16_t)X_Buf[count];
    }
   if(x_pos==0)
    {
       sum_x=0;
    }
    return (uint8_t)(sum_x/X_Length);
#endif
    
#if 1
     uint8_t i;
    uint8_t j;
    uint8 x_pos;
    uint8 temp;
    
    //uint8 rtn=0;
	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		x_pos = 0x00;
	}else{
		GetSurface_Position(&x_pos, NULL_PTR);
	}

    X_Buf[X_CNT++]=x_pos;
    if(X_CNT==X_Length)
    {
        X_CNT=0;
    }
    for(j=0;j<X_Length-1;j++)
    {
        for(i=0;i<X_Length-1-j;i++)
        {
            if(X_Buf[i]>X_Buf[i+1])
            {
                temp=X_Buf[i];
                X_Buf[i]=X_Buf[i+1];
                X_Buf[i+1]=temp;
            }
        }
    }
   if(X_Buf[X_Length-1]-X_Buf[0]<Initial_Movement_Hysteresis)  
    {
       Stable_CNT_X++; 
       if(X_Update_Flg==1)
       {
         X_Update=(X_Buf[0]+X_Buf[X_Length-1])/2;
       }
       if(Stable_CNT_X>10)
       {
           Stable_CNT_X=10;
           X_Update_Flg=0;
           rtn_X= X_Update; 
           if( (X_Buf[0]+X_Buf[X_Length-1])/2-X_Update>0)
           {
               if((X_Buf[0]+X_Buf[X_Length-1])/2-X_Update>Next_Movement_Hysteresis)
               {
                   Stable_CNT_X=0; 
                   X_Update_Flg=1; 
               }
           }
           else
           {
               if(X_Update-(X_Buf[0]+X_Buf[X_Length-1])/2>Next_Movement_Hysteresis)
               {
                   Stable_CNT_X=0; 
                   X_Update_Flg=1; 
               }
           }
       }
    }
    else
    {
        Stable_CNT_X=0; 
        X_Update_Flg=1;  
        rtn_X= (X_Buf[X_Length/2]+X_Buf[X_Length/2-1])/2;
    }
      if(x_pos==0)
    {
       rtn_X=0;
    }
   return rtn_X; 
    
#endif
    
}


//uint8_t RTE_Get_Y1_SNS(void);
//uint8_t RTE_Get_Y2_SNS(void);
//uint8_t RTE_Get_Y3_SNS(void);
//uint8_t RTE_Get_Y4_SNS(void);
//uint8_t RTE_Get_Y5_SNS(void);
uint8_t RTE_Get_Y_SNS(void)
{
#if 0
    uint8_t count;
    uint16_t sum_y=0;
    uint8 y_pos;
	GetSurface_Position(NULL_PTR, &y_pos);
    Y_Buf[Y_CNT++]=y_pos;
    if(Y_CNT==Y_Length)
    {
        Y_CNT=0;
    }
    for(count=0;count<Y_Length;count++)
    {
        sum_y+=(uint16_t)Y_Buf[count];
    }
     if(y_pos==0)
    {
       sum_y=0;
    }
    return (uint8_t)(sum_y/Y_Length);
#endif
 
#if 1
    uint8_t i;
    uint8_t j;
    uint8 y_pos;
    uint8 temp;

	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
		BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
		y_pos = 0x00;
	}else{
		GetSurface_Position(NULL_PTR, &y_pos);
	}
	
    Y_Buf[Y_CNT++]=y_pos;
    if(Y_CNT==Y_Length)
    {
        Y_CNT=0;
    }
    for(j=0;j<Y_Length-1;j++)
    {
        for(i=0;i<Y_Length-1-j;i++)
        {
            if(Y_Buf[i]>Y_Buf[i+1])
            {
                temp=Y_Buf[i];
                Y_Buf[i]=Y_Buf[i+1];
                Y_Buf[i+1]=temp;
            }
        }
    }
    
    if(Y_Buf[Y_Length-1]-Y_Buf[0]<Initial_Movement_Hysteresis)  
    {
       Stable_CNT_Y++; 
       if(Y_Update_Flg==1)
       {
         Y_Update=(Y_Buf[0]+Y_Buf[Y_Length-1])/2;
       }
       if(Stable_CNT_Y>10)
       {
           Stable_CNT_Y=10;
           Y_Update_Flg=0;
           rtn_Y= Y_Update; 
           if( (Y_Buf[0]+Y_Buf[Y_Length-1])/2-Y_Update>0)
           {
               if((Y_Buf[0]+Y_Buf[Y_Length-1])/2-Y_Update>Next_Movement_Hysteresis)
               {
                   Stable_CNT_Y=0; 
                   Y_Update_Flg=1; 
               }
           }
           else
           {
               if(Y_Update-(Y_Buf[0]+Y_Buf[Y_Length-1])/2>Next_Movement_Hysteresis)
               {
                   Stable_CNT_Y=0; 
                   Y_Update_Flg=1; 
               }
           }
       }
    }
    else
    {
        Stable_CNT_Y=0; 
        Y_Update_Flg=1;
        
      rtn_Y=(Y_Buf[Y_Length/2]+Y_Buf[Y_Length/2-1])/2;
        
    }
     if(y_pos==0)
    {
       rtn_Y=0;
    }
    return rtn_Y;
#endif
    
}
uint8_t g_XY_Touch_And_Below_1N = 0;

uint8_t RTE_Get_TouchBoard_XY_Sts(void)//Not active,Touch,Touch and Press,invalid from sensor
{
	//PanelPress_LevelType Press_Level;
    Buttons_SignalType XY_Sts = BUTTON_RELEASE;
#if 0
	if(BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_RESUME1) ||
	   BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_CANCEL1) ||
	   BUTTON_RELEASE != TouchPanel_BtnSignalRead(BTN_ADAS1))
	{
	    g_XY_Touch_And_Below_1N = 0x00;
	 	XY_Sts = BUTTON_RELEASE;
	}
	else
	{
		XY_Sts =  TouchSurface_XY_StsRead();
		//Press_Level = TouchPanel_PressLevelRead();
		if(TouchSurface_is_TouchActive() == TRUE)//PANEL_PRESS_LEVEL0 == Press_Level &&
		{
			g_XY_Touch_And_Below_1N = 0x01;
		}else{
			g_XY_Touch_And_Below_1N = 0x00;
		}
	}
#else
	XY_Sts =  TouchSurface_XY_StsRead();
	//Press_Level = TouchPanel_PressLevelRead();
	if(TouchSurface_is_TouchActive() == TRUE)//PANEL_PRESS_LEVEL0 == Press_Level &&
	{
		g_XY_Touch_And_Below_1N = 0x01;
	}else{
		g_XY_Touch_And_Below_1N = 0x00;
	}
#endif
    return XY_Sts;
}


uint8_t RTE_Get_ACT_FAULT_OUT_SNS(void)
{
    return 0;
}
uint8_t RTE_Get_ACT_LD_OUT_SNS(void)
{
    return 0;
}

uint8_t RTE_Get_TouchBoard_XY_Touch_And_Below_1N(void)   // 0 false   1 true
{
#if 0
    uint8_t ret_val = 0;
	if(g_XY_Touch_And_Below_1N == TRUE)
	{
		ret_val = 0x01;
	}
    return ret_val;
#endif
  
  #if 1  
    uint8_t ret_val = 0;  
  Buttons_SignalType XY_Sts = BUTTON_RELEASE;
  XY_Sts =  TouchSurface_XY_StsRead();
  if(XY_Sts>0)  
  {
   ret_val=1;
  }
  else
  {
   ret_val=0;
  }   
   return ret_val;  
   #endif
}

//Input CANimage.png
uint8_t rtn_data = 0;

//LED on off control
uint8_t RTE_Get_CAN_ActvnOfSteerWhlIllmn(void)
{
    //uint8_t temp = 0;
    rtn_data = 0;

	(void)ReceiveMessage(SIG_ACTVNOFSTEERWHLILLMN, &rtn_data);

	return rtn_data;
}
//LED Day/Night Mode switch
uint8_t RTE_Get_CAN_TwliBriSts(void)
{
    //uint8_t temp = 0;
    rtn_data = 0;

	(void)ReceiveMessage(SIG_TWLIBRISTS, &rtn_data);

	return rtn_data;
}


uint8_t RTE_Get_CAN_IntrBriSts(void)
{
    //uint8_t temp = 0;
    rtn_data = 0;

	(void)ReceiveMessage(SIG_INTRBRISTS, &rtn_data);

	return rtn_data;
}

uint8_t RTE_Get_CAN_SteerWhlTouchBdLeFaildFb(void)
{
    //uint8_t temp = 0;
    rtn_data = 0;

	//(void)ReceiveMessage(SIG_INTRBRISTS, &rtn_data);

	return rtn_data;
}

uint8_t RTE_Get_CAN_SwtOfKeyTone(void)
{
    //uint8_t temp = 0;
    rtn_data = 0;

	(void)ReceiveMessage(SIG_SWTOFKEYTONE, &rtn_data);

	return rtn_data;
}

//Vibration control
uint8_t RTE_Get_CAN_VibrationFbToSwtp(void)
{
    //uint8_t temp = 0;
    rtn_data = 0;

	//(void)ReceiveMessage(SIG_SWTOFKEYTONE, &rtn_data);

	return rtn_data;
}

uint8_t RTE_Get_CAN_IhuPrivateDHUCanFr01_Frame_Timeout(void)//0x030 frame
{
   bool result = false;
	//if (ReadFlagRxErrorSig(SIG_) == COM_TRUE)
	//{
	//	result = true;
	//}
	return result;
}

//Output Control

void RTE_Set_illumination_BL_PWM(uint32_t Percent)
{
    // 100000 means 100%
    /* to set PWM for LED ,PWM from 0 to 100*/
	uint32_t temp = 0;
	static uint32_t local_percent = 0xffffffff;

    //uint8_t LED_Delay = 0;
   // LED_Delay = SYSTICK_Get1_5_S_Flag();
   // if(LED_Delay==1)
   // {
	if(local_percent != Percent)
	{
		local_percent = Percent;
		// temp = Percent * 0xff / 100;
		temp = (7999/100) * Percent/1000;
		//IoHw_PWM3_Setter(PWM_CHANNEL_CHANNEL0, temp);
        (void)TCC0_PWM24bitDutySet(TCC0_CHANNEL0, (uint16_t)temp);
        temp = 250 * Percent/100000;
		TC0_Compare8bitMatch1Set((uint8_t)temp);
		TC1_Compare8bitMatch0Set((uint8_t)temp);
	}
   // }
}


//void RTE_Set_Power_AD_Ctrl(uint8_t Value);




//ACT control??
uint8_t trigger_ACT = 0;
void RTE_Set_ACT_Vibration(uint8_t Sts)
{
 if (Sts==1)
    {
        if (trigger_ACT == 0)
        {
            trigger_ACT = 1;
    //    speeker_Tig_Once(50, SA51024_STRENGTH_LEVEL3);
        }

    }
else
    {
        trigger_ACT = 0;
    }

}
//void RTE_Set_Gain0(uint8_t Value);
//void RTE_Set_Gain1(uint8_t Value);
//void RTE_Set_SDZ(uint8_t Value);
//void RTE_Set_INP(uint8_t Value);

//Output CAN
void RTE_Set_CAN_LeMFctActSgCe(uint8_t Value)
{
    InitMessage(SIG_LEMFCTACTSGCE, &Value);
}

void RTE_Set_CAN_LeMFctActSgDn(uint8_t Value)
{
    InitMessage(SIG_LEMFCTACTSGDN, &Value);
}

void RTE_Set_CAN_LeMFctActSgLe(uint8_t Value)
{
    InitMessage(SIG_LEMFCTACTSGLE, &Value);
}

void RTE_Set_CAN_LeMFctActSgRi(uint8_t Value)
{
    InitMessage(SIG_LEMFCTACTSGRI, &Value);
}

void RTE_Set_CAN_LeMFctActSgUp(uint8_t Value)
{
    InitMessage(SIG_LEMFCTACTSGUP, &Value);
}


uint8_t g_TouchBoard_ADAS1_Sts = BUTTON_RELEASE;
void RTE_Set_CAN_SteerWhlTouchBdADAS(uint8_t Value)
{
     
    
    if((Value == BUTTON_TOUCH_AND_PRESS && g_TouchBoard_ADAS1_Sts != BUTTON_TOUCH_AND_PRESS) ||
      (Value != BUTTON_TOUCH_AND_PRESS && g_TouchBoard_ADAS1_Sts == BUTTON_TOUCH_AND_PRESS))
    {
        //speeker_Tig_Once(60, SA51024_STRENGTH_LEVEL3);
		g_speeker_event |= 0x01;
    }
    g_TouchBoard_ADAS1_Sts = Value;  
    InitMessage(SIG_STEERWHLTOUCHBDADAS, &Value);
}

void RTE_Set_CAN_SwpLeRiStsLe(uint8_t Value)
{
    InitMessage(SIG_SWPLERISTSLE, &Value);
}

void RTE_Set_CAN_SwpUpDwnStsLe(uint8_t Value)
{
    InitMessage(SIG_SWPUPDWNSTSLE, &Value);
}

void RTE_Set_CAN_DiagcFailrTouchPanSWTLCmnFltSts(uint8_t Value)
{
    InitMessage(SIG_DIAGCFAILRTOUCHPANSWTLCMNFLTSTS, &Value);
}

void RTE_Set_CAN_DiagcFailrTouchPanSWTLTouchdFltSts(uint8_t Value)
{
    InitMessage(SIG_DIAGCFAILRTOUCHPANSWTLTOUCHDFLTSTS, &Value);
}

void RTE_Set_CAN_DiagcFailrTouchPanSWTLVibrationFltSts(uint8_t Value)
{
    InitMessage(SIG_DIAGCFAILRTOUCHPANSWTLVIBRATIONFLTSTS, &Value);
}

void RTE_Set_CAN_DiagcFailrTouchPanSWTLSnsrFltSts(uint8_t Value)
{
    InitMessage(SIG_DIAGCFAILRTOUCHPANSWTLSNSRFLTSTS, &Value);
}

void RTE_Set_CAN_SteerWhlTouchBdCnclChks(uint8_t Value)
{
    Value = RTE_Get_Cancel_CRC();
    InitMessage(SIG_STEERWHLTOUCHBDCNCLCHKS, &Value);
}

void RTE_Set_CAN_SteerWhlTouchBdCnclCntr(uint8_t Value)
{
   
    
}

void RTE_Set_CAN_SteerWhlTouchBdCnclQf1(uint8_t Value)
{
    InitMessage(SIG_STEERWHLTOUCHBDCNCLQF1, &Value);
    Cancel_Qf1=Value;
    
}

uint8_t g_TouchBoard_Cncl1_Sts = BUTTON_RELEASE;
void RTE_Set_CAN_SteerWhlTouchBdCnclSteerWhlTouchBdSts(uint8_t Value)
{
    
    
    if((Value == BUTTON_TOUCH_AND_PRESS && g_TouchBoard_Cncl1_Sts != BUTTON_TOUCH_AND_PRESS) ||
      (Value != BUTTON_TOUCH_AND_PRESS && g_TouchBoard_Cncl1_Sts == BUTTON_TOUCH_AND_PRESS))
    {
    	g_speeker_event |= 0x02;
        //speeker_Tig_Once(60, SA51024_STRENGTH_LEVEL3);
    }
    g_TouchBoard_Cncl1_Sts = Value;   
    InitMessage(SIG_STEERWHLTOUCHBDCNCLSTEERWHLTOUCHBDSTS, &Value);
    Cancel_Sts=Value;
}

void RTE_Set_CAN_SteerWhlTouchBdCrsResuQf1(uint8_t Value)
{
    InitMessage(SIG_STEERWHLTOUCHBDCRSRESUQF1, &Value);
}

uint8_t g_TouchBoard_Resu1_Sts = BUTTON_RELEASE;
void RTE_Set_CAN_SteerWhlTouchBdCrsResuSteerWhlTouchBdSts(uint8_t Value)
{    
    
    
    if((Value == BUTTON_TOUCH_AND_PRESS && g_TouchBoard_Resu1_Sts != BUTTON_TOUCH_AND_PRESS) ||
      (Value != BUTTON_TOUCH_AND_PRESS && g_TouchBoard_Resu1_Sts == BUTTON_TOUCH_AND_PRESS))
    {
    	g_speeker_event |= 0x04;
        //speeker_Tig_Once(60, SA51024_STRENGTH_LEVEL3);
    }
    g_TouchBoard_Resu1_Sts = Value;  
    InitMessage(SIG_STEERWHLTOUCHBDCRSRESUSTEERWHLTOUCHBDSTS, &Value); 
}

void RTE_Set_CAN_SteerWhlTouchBdLeChks(uint8_t Value)
{
    //InitMessage(SIG_STEERWHLTOUCHBDLECHKS, &Value);
    
}

void RTE_Set_CAN_SteerWhlTouchBdLeCntr(uint8_t Value)
{
    //InitMessage(SIG_STEERWHLTOUCHBDLECNTR, &Value);//fcb
   // TouchBoard_RC=Value;
}
uint8_t g_last_SteerWhlTouchBdSts = BUTTON_RELEASE;
uint8_t speeker_Tig_gap_cnt = 0;//kailong remove

void RTE_Set_CAN_SteerWhlTouchBdLeSteerWhlTouchBdSts(uint8_t Value)
{
   //kailong 
    
         
 
    
    
    
#if 1
    if((Value == BUTTON_TOUCH_AND_PRESS && g_last_SteerWhlTouchBdSts != BUTTON_TOUCH_AND_PRESS) ||
    (Value != BUTTON_TOUCH_AND_PRESS && g_last_SteerWhlTouchBdSts == BUTTON_TOUCH_AND_PRESS))
    {
    	g_speeker_event |= 0x08;
    }
    
     if(speeker_Tig_gap_cnt != 0x00){
            speeker_Tig_gap_cnt--;
        }
    
	if(g_speeker_event != 0x00)
	{
       
        
        if(speeker_Tig_gap_cnt == 0x00)
        {
            if((g_speeker_event&0x07) != 0x00)// ADAS1 Resu1 Cncl1
            {
               // speeker_Tig_Once(49, SA51024_STRENGTH_LEVEL2);
                speeker_Tig_gap_cnt = 25;//25ms
            }
            else if(g_speeker_event&0x08)
            {
                if(g_TouchBoard_ADAS1_Sts == BUTTON_RELEASE &&
                    g_TouchBoard_Resu1_Sts  == BUTTON_RELEASE &&	
                    g_TouchBoard_Cncl1_Sts  == BUTTON_RELEASE)
                {
                   // speeker_Tig_Once(49, SA51024_STRENGTH_LEVEL2);
                    speeker_Tig_gap_cnt = 25;//25ms
                }		
            }
        }
		g_speeker_event = 0x00;
	}


    g_last_SteerWhlTouchBdSts = Value;   
#endif
    
    
    InitMessage(SIG_STEERWHLTOUCHBDLESTEERWHLTOUCHBDSTS, &Value);
    //TouchBoard_Sts=Value;
}


void RTE_Set_CAN_SteerWhlTouchBdLeTouchPosnX(uint8_t Value)
{
    InitMessage(SIG_STEERWHLTOUCHBDLETOUCHPOSNX, &Value);
    //TouchBoard_X=Value;
}
void RTE_Set_CAN_SteerWhlTouchBdLeTouchPosnY(uint8_t Value)
{
    InitMessage(SIG_STEERWHLTOUCHBDLETOUCHPOSNY, &Value);
    //TouchBoard_Y=Value;
}


uint8_t Pre_300_req;
uint8_t Remain_frame;
uint8_t Remain_cnt;
uint8_t Remain_X = 0;
uint8_t Remain_Y = 0;
uint8_t Frame_0x300_RC = 15;
void RTE_Set_SEND_CAN_0x300_immediately(uint8_t Value) //called immediately in 10ms task when touch,or touch and press in XY area
{
    uint8_t Current_300_req;
    Current_300_req=Value;
    
    if(Value==1)
     {
       if(Frame_0x300_RC > 14){
         Frame_0x300_RC = 0;
      }else{
         Frame_0x300_RC++;
      }
       //InitMessage(SIG_STEERWHLTOUCHBDLECNTR, &Frame_0x300_RC);//fcb
        //Send a 0x300 frame

        OsekComTxReqFrmSwtlPrivateDHUCanFr01();
     }
     if(Value==0&&Pre_300_req==1)
    {
        Remain_frame=1;
    }
    Pre_300_req=Current_300_req;
    
    if(Remain_frame==1)
    {
        InitMessage(SIG_STEERWHLTOUCHBDLETOUCHPOSNX, &Remain_X);
        InitMessage(SIG_STEERWHLTOUCHBDLETOUCHPOSNY, &Remain_Y);
       InitMessage(SIG_STEERWHLTOUCHBDLESTEERWHLTOUCHBDSTS, &Remain_Y);
        if(Remain_cnt<2)
        {
           if(Frame_0x300_RC > 14){
                Frame_0x300_RC = 0;
         }else{
              Frame_0x300_RC++;
         }
           //InitMessage(SIG_STEERWHLTOUCHBDLECNTR, &Frame_0x300_RC);//fcb
            OsekComTxReqFrmSwtlPrivateDHUCanFr01();
          Remain_cnt++;
        }
        else
        {
          Remain_frame=0;
          Remain_cnt=0;
        }
    }
}

uint8_t Cancel_0x305_RC = 15;
void RTE_Set_SEND_CAN_0x305_25ms(uint8_t Value) // when touch,or touch and press in 3 button area,0x305 is sent every 25ms
{
     uint8_t temp;
  if(Value==1)
     {
      
      if(Cancel_0x305_RC > 14){
         Cancel_0x305_RC = 0;
      }else{
         Cancel_0x305_RC++;
      }
       InitMessage(SIG_STEERWHLTOUCHBDCNCLCNTR, &Cancel_0x305_RC);
       Cancel_RC=Cancel_0x305_RC;
       temp = RTE_Get_Cancel_CRC();
    InitMessage(SIG_STEERWHLTOUCHBDCNCLCHKS, &temp);
        //Send a 0x305 frame

        OsekComTxReqFrmSwtlPrivateDHUCanFr02();
     }
}

void RTE_Set_SEND_CAN_0x305_1000ms(uint8_t Value) // when  3 button area is not active,0x305 is Sent every 1000ms
{
    uint8_t temp;
  if(Value==1)
     {
        if(Cancel_0x305_RC > 14){
            Cancel_0x305_RC = 0;
        }else{
             Cancel_0x305_RC++;
        }
       InitMessage(SIG_STEERWHLTOUCHBDCNCLCNTR, &Cancel_0x305_RC);
       Cancel_RC=Cancel_0x305_RC;
       temp = RTE_Get_Cancel_CRC();
    InitMessage(SIG_STEERWHLTOUCHBDCNCLCHKS, &temp);
        //Send a 0x305 frame

        OsekComTxReqFrmSwtlPrivateDHUCanFr02();
     }
}

uint8_t UbInitValue = 1;
void RTE_Set_All_UB(void)
{
  InitMessage(SIG_DIAGCFAILRTOUCHPANSWTL_UB, &UbInitValue);
  InitMessage(SIG_LEMFCTACTSGCE_UB, &UbInitValue);
  InitMessage(SIG_LEMFCTACTSGDN_UB, &UbInitValue);
  InitMessage(SIG_LEMFCTACTSGLE_UB, &UbInitValue);
  InitMessage(SIG_LEMFCTACTSGRI_UB, &UbInitValue);
  InitMessage(SIG_LEMFCTACTSGUP_UB, &UbInitValue);
  InitMessage(SIG_STEERWHLTOUCHBDADAS_UB, &UbInitValue);
  InitMessage(SIG_STEERWHLTOUCHBDCNCL_UB, &UbInitValue);
  InitMessage(SIG_STEERWHLTOUCHBDCRSRESU_UB, &UbInitValue);
  InitMessage(SIG_STEERWHLTOUCHBDLE_UB, &UbInitValue);
  InitMessage(SIG_SWPLERISTSLE_UB, &UbInitValue);
  InitMessage(SIG_SWPUPDWNSTSLE_UB, &UbInitValue);
  InitMessage(SIG_SWTLPARTNOCMPL_UB, &UbInitValue);
  InitMessage(SIG_SWTLSERNO_UB, &UbInitValue);
}

#if 1
void RTE_Set_All_Test_Value(void)
{
  uint16_t Press_baseline;
  uint16_t Press_signal;
  Press_baseline=Get_forcedetect_basline_value();
  Press_signal=Get_forcedetect_force_value();
  InitMessage(SIG_SWTLPRESSBASELINE, &Press_baseline);//Press_baseline
  InitMessage(SIG_SWTLPRESSSIGNAL, &Press_signal);//Press_signal-Convert to N: TouchPanel_PressNValue = ((float32)Press_signal / (float32)0xF2);
  
  uint16_t Touch_Sensor_Sts00;
  uint16_t Touch_Sensor_Sts01;
  uint16_t Touch_Sensor_Sts02;
  uint16_t Touch_Sensor_Sts03;
  uint16_t Touch_Sensor_Sts04;
  uint16_t Touch_Sensor_Sts05;
  uint16_t Touch_Sensor_Sts06;
  uint16_t Touch_Sensor_Sts07;
  uint16_t Touch_Sensor_Sts08;
  uint16_t Touch_Sensor_Sts09;
  uint16_t Touch_Sensor_Sts10;
  uint16_t Touch_Sensor_Sts11;
  uint16_t Touch_Sensor_Sts12;
  
  
  uint16_t Touch_Sensor_Ref00;
  uint16_t Touch_Sensor_Ref01;
  uint16_t Touch_Sensor_Ref02;
  uint16_t Touch_Sensor_Ref03;
  uint16_t Touch_Sensor_Ref04;
  uint16_t Touch_Sensor_Ref05;
  uint16_t Touch_Sensor_Ref06;
  uint16_t Touch_Sensor_Ref07;
  uint16_t Touch_Sensor_Ref08;
  uint16_t Touch_Sensor_Ref09;
  uint16_t Touch_Sensor_Ref10;
  uint16_t Touch_Sensor_Ref11;
  uint16_t Touch_Sensor_Ref12;
 
  
  //uint8_t Touch_Sensor_Sts13;
  
  Touch_Sensor_Sts00 = abs(get_sensor_node_signal(0U)-get_sensor_node_reference(0U));
  Touch_Sensor_Sts01 = abs(get_sensor_node_signal(1U)-get_sensor_node_reference(1U));
  Touch_Sensor_Sts02= abs(get_sensor_node_signal(2U)-get_sensor_node_reference(2U));
  Touch_Sensor_Sts03= abs(get_sensor_node_signal(3U)-get_sensor_node_reference(3U));
  Touch_Sensor_Sts04= abs(get_sensor_node_signal(4U)-get_sensor_node_reference(4U));
  Touch_Sensor_Sts05= abs(get_sensor_node_signal(5U)-get_sensor_node_reference(5U));
  Touch_Sensor_Sts06= abs(get_sensor_node_signal(6U)-get_sensor_node_reference(6U));
  Touch_Sensor_Sts07= abs(get_sensor_node_signal(7U)-get_sensor_node_reference(7U));
  Touch_Sensor_Sts08= abs(get_sensor_node_signal(8U)-get_sensor_node_reference(8U));
  Touch_Sensor_Sts09=abs(get_sensor_node_signal(9U)-get_sensor_node_reference(9U));
  Touch_Sensor_Sts10= abs(get_sensor_node_signal(10U)-get_sensor_node_reference(10U));
  Touch_Sensor_Sts11= abs(get_sensor_node_signal(11U)-get_sensor_node_reference(11U));
  Touch_Sensor_Sts12= abs(get_sensor_node_signal(12U)-get_sensor_node_reference(12U));
  
  
  Touch_Sensor_Ref00=get_sensor_node_reference(0U);
  Touch_Sensor_Ref01=get_sensor_node_reference(1U);
  Touch_Sensor_Ref02=get_sensor_node_reference(2U);
  Touch_Sensor_Ref03=get_sensor_node_reference(3U);
  Touch_Sensor_Ref04=get_sensor_node_reference(4U);
  Touch_Sensor_Ref05=get_sensor_node_reference(5U);
  Touch_Sensor_Ref06=get_sensor_node_reference(6U);
  Touch_Sensor_Ref07=get_sensor_node_reference(7U);
  Touch_Sensor_Ref08=get_sensor_node_reference(8U);
  Touch_Sensor_Ref09=get_sensor_node_reference(9U);
  Touch_Sensor_Ref10=get_sensor_node_reference(10U);
  Touch_Sensor_Ref11=get_sensor_node_reference(11U);
  Touch_Sensor_Ref12=get_sensor_node_reference(12U);
  
  //Touch_Sensor_Sts13=g_XY_Touch_And_Below_1N;
  
   InitMessage(SIG_SWTLSENSOR1_SIGNAL, &Touch_Sensor_Sts00);
   InitMessage(SIG_SWTLSENSOR2_SINGAL, &Touch_Sensor_Sts01);
   InitMessage(SIG_SWTLSENSOR3_SIGNAL, &Touch_Sensor_Sts02);
   InitMessage(SIG_SWTLSENSOR4_SIGNAL, &Touch_Sensor_Sts03);
   InitMessage(SIG_SWTLSENSOR5_SIGNAL, &Touch_Sensor_Sts04);
   InitMessage(SIG_SWTLSENSOR6_SIGNAL, &Touch_Sensor_Sts05);
   InitMessage(SIG_SWTLSENSOR7_SIGNAL, &Touch_Sensor_Sts06);
   InitMessage(SIG_SWTLSENSOR8_SIGNAL, &Touch_Sensor_Sts07);
   InitMessage(SIG_SWTLSENSOR9_SIGNAL, &Touch_Sensor_Sts08);
   InitMessage(SIG_SWTLSENSOR10_SIGNAL, &Touch_Sensor_Sts09);
   InitMessage(SIG_SWTLSENSOR11_SIGNAL, &Touch_Sensor_Sts10);
   InitMessage(SIG_SWTLSENSOR12_SIGNAL, &Touch_Sensor_Sts11);
   InitMessage(SIG_SWTLSENSOR13_SIGNAL, &Touch_Sensor_Sts12);
   
   InitMessage(SIG_SWTLSENSOR1_BASELINE, &Touch_Sensor_Ref00);
   InitMessage(SIG_SWTLSENSOR2_BASELINE, &Touch_Sensor_Ref01);
   InitMessage(SIG_SWTLSENSOR3_BASELINE, &Touch_Sensor_Ref02);
   InitMessage(SIG_SWTLSENSOR4_BASELINE, &Touch_Sensor_Ref03);
   InitMessage(SIG_SWTLSENSOR5_BASELINE, &Touch_Sensor_Ref04);
   InitMessage(SIG_SWTLSENSOR6_BASELINE, &Touch_Sensor_Ref05);
   InitMessage(SIG_SWTLSENSOR7_BASELINE, &Touch_Sensor_Ref06);
   InitMessage(SIG_SWTLSENSOR8_BASELINE, &Touch_Sensor_Ref07);
   InitMessage(SIG_SWTLSENSOR9_BASELINE, &Touch_Sensor_Ref08);
   InitMessage(SIG_SWTLSENSOR10_BASELINE, &Touch_Sensor_Ref09);
   InitMessage(SIG_SWTLSENSOR11_BASELINE, &Touch_Sensor_Ref10);
   InitMessage(SIG_SWTLSENSOR12_BASELINE, &Touch_Sensor_Ref11);
   InitMessage(SIG_SWTLSENSOR13_BASELINE, &Touch_Sensor_Ref12);

   g16_DiagTouchPressSenRes[0][0] = Touch_Sensor_Ref00;
   g16_DiagTouchPressSenRes[0][1] = Touch_Sensor_Ref01;
   g16_DiagTouchPressSenRes[0][2] = Touch_Sensor_Ref02;
   g16_DiagTouchPressSenRes[0][3] = Touch_Sensor_Ref03;
   g16_DiagTouchPressSenRes[0][4] = Touch_Sensor_Ref04;
   g16_DiagTouchPressSenRes[0][5] = Touch_Sensor_Ref05;
   g16_DiagTouchPressSenRes[0][6] = Touch_Sensor_Ref06;
   g16_DiagTouchPressSenRes[0][7] = Touch_Sensor_Ref07;
   g16_DiagTouchPressSenRes[0][8] = Touch_Sensor_Ref08;
   g16_DiagTouchPressSenRes[0][9] = Touch_Sensor_Ref09;
   g16_DiagTouchPressSenRes[0][10] = Touch_Sensor_Ref10;
   g16_DiagTouchPressSenRes[0][11] = Touch_Sensor_Ref11;
   g16_DiagTouchPressSenRes[0][12] = Touch_Sensor_Ref12;

   g16_DiagTouchPressSenRes[1][0] = Touch_Sensor_Sts00;
   g16_DiagTouchPressSenRes[1][1] = Touch_Sensor_Sts01;
   g16_DiagTouchPressSenRes[1][2] = Touch_Sensor_Sts02;
   g16_DiagTouchPressSenRes[1][3] = Touch_Sensor_Sts03;
   g16_DiagTouchPressSenRes[1][4] = Touch_Sensor_Sts04;
   g16_DiagTouchPressSenRes[1][5] = Touch_Sensor_Sts05;
   g16_DiagTouchPressSenRes[1][6] = Touch_Sensor_Sts06;
   g16_DiagTouchPressSenRes[1][7] = Touch_Sensor_Sts07;
   g16_DiagTouchPressSenRes[1][8] = Touch_Sensor_Sts08;
   g16_DiagTouchPressSenRes[1][9] = Touch_Sensor_Sts09;
   g16_DiagTouchPressSenRes[1][10] = Touch_Sensor_Sts10;
   g16_DiagTouchPressSenRes[1][11] = Touch_Sensor_Sts11;
   g16_DiagTouchPressSenRes[1][12] = Touch_Sensor_Sts12;

   g16_DiagTouchPressSenRes[2][0] = Press_baseline;
   g16_DiagTouchPressSenRes[2][1] = Press_signal;
   g16_DiagTouchPressSenRes[2][2] = Press_baseline;
   
   InitMessage(SIG_SWTLSENSOR14_SIGNAL, &g_XY_Touch_And_Below_1N);


}

#endif