#ifndef TOUCH_PANEL_H
#define TOUCH_PANEL_H
#include "Std_Types.h"
#include "forceSnsr/forcedetect.h"

#define PI                3.1415926f

#define TP_ERR_RANGE        15
#define TP_DEBOUNCE_CYCLE   1
#define TP_RUNNING_ERROR_CYCLE   60000

#define SLIDE_LR_MIN_DISTANCE  (30)
#define SLIDE_LR_SHORT_DISTANCE_NUM   90
#define SLIDE_UD_MIN_DISTANCE  (1.59*SLIDE_LR_MIN_DISTANCE)
#define SLIDE_UD_SHORT_DISTANCE_NUM   140


#define SLIDE_UD_LEVEL1_DISTANCE	SLIDE_UD_MIN_DISTANCE
#define SLIDE_UD_LEVEL2_DISTANCE    (SLIDE_UD_MIN_DISTANCE + 69) //((SLIDE_UD_MIN_DISTANCE+SLIDE_UD_SHORT_DISTANCE_NUM)/2)
#define SLIDE_UD_LEVEL3_DISTANCE    (SLIDE_UD_LEVEL2_DISTANCE + 69)//SLIDE_UD_SHORT_DISTANCE_NUM

#define SLIDE_CAN_EVENT_KEEP_CYCLE   30//2MS*30

#define TOUCH_SCREEN_CONTACT_AREA_INVALID_NUM   350
#define TOUCH_KET_ON                            1
#define TOUCH_KET_OFF                           0


extern uint16 Over3N_vibra_req;
extern uint16 Below1P5N_vibra_req;



typedef enum
{
    TP_SlideDirection_NONE    = 0,
    TP_SlideDirection_ShortUP,
	TP_SlideDirection_LongUP,
	TP_SlideDirection_ShortDOWN,
	TP_SlideDirection_LongDOWN,
	TP_SlideDirection_ShortLEFT,
	TP_SlideDirection_LongLEFT,
	TP_SlideDirection_ShortRIGHT,
	TP_SlideDirection_LongRIGHT
} TP_SlideDirection_Enum;


/*0 slip idle   1 decrease ,2 increase , 3 decrease double , 4 increase double ,5 decrease third, 6 increase third*/
typedef enum
{
    TP_SlideLevel_NONE  = 0,
    TP_SlideLevel1_DOWN,
	TP_SlideLevel1_UP,
	TP_SlideLevel2_DOWN,
	TP_SlideLevel2_UP,
	TP_SlideLevel3_DOWN,
	TP_SlideLevel3_UP
} TP_SlideLevel_Enum;


typedef enum{
	TOUCH_PANEL_NONE_EVENT = 0,
	TOUCH_PANEL_PRESS_EVENT,
	TOUCH_PANEL_RES_EVENT,
	TOUCH_PANEL_MOVE_EVENT,
	TOUCH_PANEL_BERR_EVENT
}TouchPanel_EventType;

typedef enum{
	PANEL_PRESS_LEVEL0 = 0,/*< 1N*/
	PANEL_PRESS_LEVEL1,/*1N <= X < 3N*/
	PANEL_PRESS_LEVEL2 /*>= 3N*/
}PanelPress_LevelType;










typedef struct{
	boolean Event;
	uint32 keep_cycle;
	TP_SlideDirection_Enum Direction;
	uint8 UpDown_SlideDistance;
	TP_SlideLevel_Enum UpDown_SlideLevel;
}TouchSlideEvent_type;

typedef struct{
	uint8 x_position;
	uint8 y_position;
	uint8 origin_x_pos;
	uint8 origin_y_pos;
	uint8 end_x_pos;
	uint8 end_y_pos;

	TouchPanel_EventType Event;
	uint32 CheckCycle;
	uint32 TouchCycle;
}TouchSurface_type;

typedef struct{
	uint8 x_position;
	uint8 y_position;
}TouchScroller_type;

typedef struct{
 uint8 convert_x;
 uint8 convert_y;
}TouchSurface_Convert_type;

typedef struct{
 float32 x;
 float32 y;
}TouchXY_type;

typedef struct{
	uint16 status;
	uint32 RunCycle;
}TouchButtons_type;

typedef enum{
	BTN_VOICE1 = 0,//MENU1	pin
	//BTN_VOICE2,//MENU2 //not used
	BTN_VOL2,//VOL1
	BTN_VOL1,//VOL2
	BTN_MENU2,//VOICE1
	BTN_MENU1,//VOICE1
	/****************/
	BTN_UP,
	BTN_DOWN,
	BTN_LEFT,
	BTN_RIGHT,
	BTN_CONFIRM,
	/****************/
	BTN_MAX_CH_NUM
}Buttons_ChType;

typedef enum{
	BUTTON_RELEASE = 0,//notcative
	BUTTON_TOUCH,
	BUTTON_TOUCH_AND_PRESS,
	//BUTTON_INVALID
}Buttons_SignalType;

#define GET_TouchPanel_is_Press    Get_forcedetect_btn_is_press_state

extern volatile uint8 measurement_done_touch;
extern volatile uint8 k_voice_touch_Sts,k_menu_touch_Sts,k_vol_touch_Sts;
extern volatile uint8 Vibra_force_level;
extern volatile uint8 last_Vibra_force_level;

extern uint8 Vibra_PressCheck(void);

void TouchPanel_init(void);
void GetSurface_Position(uint8 *x, uint8 *y);
void GetScroller_Position(uint8 *x, uint8 *y);
Buttons_SignalType TouchPanel_BtnSignalRead(Buttons_ChType ChId);
void TouchPanel_MainFunction(void);
TP_SlideDirection_Enum TouchPanel_SlideEventRead(void);
Buttons_SignalType TouchSurface_XY_StsRead(void);
TP_SlideLevel_Enum TouchPanel_SlideUpDownLevelRead(void);
PanelPress_LevelType TouchPanel_PressLevelRead(void);
boolean TouchSurface_is_TouchActive(void);
boolean TouchButton_is_TouchActive(Buttons_ChType BtId);
boolean TouchScroller_is_TouchActive(void);
#endif