#ifndef __APP_TFT_H__
#define __APP_TFT_H__

#define DEFAULT_BRIGHTNESS 0
#define SAME_TIME_DISPLAY_NUM 5
#define CENTER_AREA_DISPLAY_ALIVE_TIME_DEFAULT 400
#define EACH_SURFACE_CONTAIN_PIC_NUM 230
#define CENTER_DISPLAY_PARA_STATIC 0
#define CENTER_DISPLAY_PARA_DYNC 1

#define DEFAULT_ALPHA            0

#define OFFSET_ADDRESS           0x80000000
#define Base_address      0x04000000

//_0____________________240
//|                      |
//|         W1           |
//|______________________|
//|                      |
//|                      |
//|                      |
//|                      |
//|         w2           |
//|                      |
//|                      |
//|                      |
//|                      |
//|______________________|
//|         w3           |
//|______________________|
//320
//xxhh add

#define W1_START_Y      0
#define W1_STOP_Y       102

#define W2_START_Y      103
#define W2_STOP_Y       292

#define W3_START_Y      294
#define W3_STOP_Y       320

#define MIN_START_X     0
#define MAX_STOP_X      240
#define MIN_START_Y     0
#define MAX_STOP_Y      320

#define STAGE_PreWarning            1
#define STAGE_SetEOL                2
#define STAGE_TelltaleAndSpeed      3
#define STAGE_WaterAndFuil          4
#define STAGE_TFTCheck              5
#define STAGE_Other                 6
#define STAGE_ClearODO              7



extern const uint8_t GearValue[5];


//#define  G_Stage  g_Stage
extern uint8_t  g_Stage,g_OldStage;
typedef struct
{
  uint16_t   Value;
  uint16_t   buf[50];
  uint32_t   sum;
  uint32_t   Time;
  uint8_t    Flag;
  uint8_t    enable;
  uint8_t    statu;
  uint32_t   count;
  uint8_t    Finsh;
  uint32_t   Time_one;
   uint8_t   Flag_one;
}_StaticCurrent;
typedef struct 
{
  uint16_t   Value;
  uint16_t   buf[50];
  uint32_t   sum;
  uint32_t   Time;
  uint8_t    Flag;
  uint8_t    enable;
  uint8_t    statu;
  uint32_t   count;
  uint8_t    Finsh;
  uint32_t   Time_one;
  uint8_t   Flag_one;
}_FiveVoltage;



typedef struct
{
  uint16_t   Value;
  uint32_t   Time;
  uint8_t    Flag;
  uint8_t    enable;
}_BuzzerCurrent;

extern _FiveVoltage     FiveVoltage;
extern _BuzzerCurrent   CheckCurrent;
extern _BuzzerCurrent   BuzzerAlarm;
extern _StaticCurrent   StaticCurrent;
extern _StaticCurrent   ButtomCurrent;
extern _StaticCurrent   LedCurrent;
extern _StaticCurrent   SpeedCurrent;
extern _StaticCurrent   Iol_TempCurrent;
extern _StaticCurrent   TFTCurrent;
extern _StaticCurrent   TFTCurrent1;
extern _StaticCurrent   TFTCurrent2;
extern _StaticCurrent   TFTCurrent3;
extern _StaticCurrent   TFTCurrent4;
extern _StaticCurrent   TFTCurrent5;
extern _StaticCurrent   TFTCurrent6;
extern _StaticCurrent   TFTCurrent7;
extern _StaticCurrent   ElseCurrent;
extern _StaticCurrent   EndCurrent;

extern _StaticCurrent   TripKeyCurrent;


//xxhh add end


#define UP_BOTTOM_Y              65
#define DOWN_TOP_Y               257
#define DOWN_BOTTOM_Y            319
/*
//#define UP_TOP_Y                 0
//#define MID_TOP_Y                82 //66+16
//#define MID_BOTTOM_Y             240//256-16
//#define USM_HELP_TOP_Y           88 //66+16
//#define USM_HELP_BOTTOM_Y        234//256-16
//#define MID_USM_TOP_Y            116
//#define MID_SERVICE_BOTTOM_Y     207
//#define LEFT_X_START             0
//#define RIGHT_X_END              239
//#define MID_X_RIGHT              222
//#define MINI_TOP_Y               65
//#define MINI_BOTTOM_Y            135
*/
#define SET_DRAW_INFO(x, y, pic, radius, alpha) (g_DrawInfo.x_point = x, g_DrawInfo.y_point = y, g_DrawInfo.VRAM = VRAM_BUF[ g_DrawInfo.VramSelectBuf ], g_DrawInfo.IMG = (uint8_t*)(pic), g_DrawInfo.Radius = radius, g_DrawInfo.Alpha = alpha)

#define SET_DISPLAY_STATIC_ITEM(n, pic, x, y, type) (DisplayItem.StaticPara.DisplayPic[n] = pic, DisplayItem.StaticPara.DisplayPicOffsetX[n] = x, DisplayItem.StaticPara.DisplayPicOffsetY[n] = y, DisplayItem.StaticPara.BrushType[n] = type)
#define SET_DISPLAY_STATIC_ITEM_WINDOW(n, left, right, top, bottom) (DisplayItem.StaticPara.DisplayWindow[n].WinLeftX = left, DisplayItem.StaticPara.DisplayWindow[n].WinRightX = right, DisplayItem.StaticPara.DisplayWindow[n].WinTopY = top, DisplayItem.StaticPara.DisplayWindow[n].WinBottomY = bottom)

#define SET_DISPLAY_DYNC_ITEM(n, pic, x, y, type)   (DisplayItem.DyncPara.DisplayPic[n] = pic,  DisplayItem.DyncPara.DisplayPicOffsetX[n] = x, DisplayItem.DyncPara.DisplayPicOffsetY[n] = y, DisplayItem.DyncPara.BrushType[n] = type)
#define SET_DISPLAY_DYNC_ITEM_P(n, pic, x, y, type) (DisplayItem->DyncPara.DisplayPic[n] = pic, DisplayItem->DyncPara.DisplayPicOffsetX[n] = x, DisplayItem->DyncPara.DisplayPicOffsetY[n] = y, DisplayItem->DyncPara.BrushType[n] = type)
#define SET_DISPLAY_DYNC_ITEM_WINDOW(n, left, right, top, bottom) (DisplayItem.DyncPara.DisplayWindow[n].WinLeftX = left, DisplayItem.DyncPara.DisplayWindow[n].WinRightX = right, DisplayItem.DyncPara.DisplayWindow[n].WinTopY = top, DisplayItem.DyncPara.DisplayWindow[n].WinBottomY = bottom)

#define SELECT_AREA 1
#define UNSELECT_AREA 0


#define DRAW_ICON                           0
#define DRAW_MIM_ALPHA_ICON                 1
#define DRAW_MIM_ALPHA_ICON_WINDOW          2
#define DRAW_CONST_MAX_ALPHA                3
#define DRAW_MAX_ALPHA_CHANNEL_ICON_WINDOW  4
#define DRAW_ALPHA_CHANNEL_ICON_WINDOW      5
#define DRAW_EDGE_MIN_ALPHA_ICON            6
#define DRAW_CENTER_SPREAD_ICON_WINDOW      7
#define DRAW_MIN_ALPHA_LUMIN_ICON           8
//#define DRAW_CONST_MAX_ALPHA                9
#define DRAW_LUMIN_ICOM_WINDOW              10
#define DRAW_MIN_ALPHA_LUMIN_ICON_WINDOW    11

typedef struct {
    int16_t WinLeftX;
    int16_t WinRightX;
    int16_t WinTopY;
    int16_t WinBottomY;
}DISP_WINDOW;

typedef struct {
    uint32_t pic;
    int16_t x;
    int16_t y;
    uint8_t Radius;
    uint8_t Alpha;
    DISP_WINDOW Window;
}DISPLAY_CENTER_PIC_PARA;
typedef struct {
    uint32_t DisplayPic[EACH_SURFACE_CONTAIN_PIC_NUM];
    int16_t DisplayPicOffsetX[EACH_SURFACE_CONTAIN_PIC_NUM];
    int16_t DisplayPicOffsetY[EACH_SURFACE_CONTAIN_PIC_NUM];
    DISP_WINDOW DisplayWindow[EACH_SURFACE_CONTAIN_PIC_NUM];
    uint8_t BrushType[EACH_SURFACE_CONTAIN_PIC_NUM];
}CENTER_AREA_DISPLAY_PARA;

#define SWITCH_EFFECT_NONE              0
#define SWITCH_EFFECT_IN_ALPHA          0x01
#define SWITCH_EFFECT_OUT_ALPHA         0x02
#define SWITCH_EFFECT_IN_OFFSET         0x04
#define SWITCH_EFFECT_OUT_OFFSET        0x08
#define SWITCH_EFFECT_RADIUS_OFFSET     0x10
#define SWITCH_EFFECT_ALPHA_OFFSET      (SWITCH_EFFECT_IN_ALPHA | SWITCH_EFFECT_OUT_ALPHA | SWITCH_EFFECT_IN_OFFSET | SWITCH_EFFECT_OUT_OFFSET)

enum {
    SWITCH_EFFECT_OFFSET_FADE_IN_RIGHT_TO_LEFT,
    SWITCH_EFFECT_OFFSET_FADE_IN_LEFT_TO_RIGHT,
    SWITCH_EFFECT_OFFSET_FADE_IN_UP_TO_DOWN,
    SWITCH_EFFECT_OFFSET_FADE_IN_DOWN_TO_UP,
};

enum {
    CENTER_AREA_DISPLAY_TYPE_NORMAL,
    CENTER_AREA_DISPLAY_TYPE_ASSIST_LAK,
    CENTER_AREA_DISPLAY_TYPE_ASSIST_DAW,
    CENTER_AREA_DISPLAY_TYPE_USM,
    CENTER_AREA_DISPLAY_TYPE_EVENT,
};

#define TOP_GROUP_MENU_DISABLE          0
#define TOP_GROUP_MENU_ENABLE           1
#define TOP_GROUP_MENU_EVENTSAVE        2

typedef struct {
    uint16_t AliveDisplaytime;
    uint8_t DisplayType;
    uint8_t CurDisplayFlag;
    //uint8_t FadeInOutOffsetEffect;
    uint8_t FadeInOffsetEffect;
    uint8_t FadeOutOffsetEffect;
    //uint8_t FadeInOutAlphaEffect;
    uint8_t FadeInAlphaEffect;
    uint8_t FadeOutAlphaEffect;
    uint8_t FadeInRadiusEffect;
    int16_t FadeInXStep;
    int16_t FadeInYStep;
    int16_t FadeOutXStep;
    int16_t FadeOutYStep;
    CENTER_AREA_DISPLAY_PARA StaticPara;
    CENTER_AREA_DISPLAY_PARA DyncPara;
}CENTER_AREA_DISPLAY_ITEM;
extern CENTER_AREA_DISPLAY_ITEM CenterAreaDisplayList[SAME_TIME_DISPLAY_NUM];
extern uint8_t Flag_EventNeedSaveIsPlayed;
extern uint16_t PageIndicatorRemainTime;
extern uint16_t PressOkClrRemainTime;
extern uint16_t DispayDTE;
extern uint32_t TFT_BilnkTimerDelta;
extern uint32_t EventDoorCnts;
extern uint8_t EventDoor600msOn400msOffLevel;
extern uint8_t EventDoor600msOn400msOffEN;
extern uint32_t EventPasCnts;
extern uint8_t EventPas600msOn400msOffLevel;
extern uint8_t EventPas600msOn400msOffEN;
extern uint32_t EventServiceCnts;
extern uint8_t EventService600msOn400msOffLevel;
extern uint8_t EventService600msOn400msOffEN;
extern uint32_t LKACnts;
extern uint8_t LKA400msLevel;
extern uint8_t LKA400msEN;
extern uint32_t EventAnimationCnts;
extern uint8_t EventAnimationEn;
extern uint8_t EventAnimationLevel;
extern uint8_t Flag_EventFadeOutStart;
extern uint8_t EventWelcomeAnimationEn;
extern uint8_t EventWelcomeAnimationCnts;
extern uint8_t EventWelcomeAnimationLevel;
extern uint32_t GearPopupTimer1msCnts_Old;
extern uint16_t ADASUsmRemainTimer;

extern const uint32_t Num12List[];
extern const uint32_t Num19List[];
extern const uint32_t Num20List[];
extern const uint32_t Num24List[];
extern const uint32_t Number25List[];
extern const uint32_t Number25GrayList[];
extern const uint32_t Number36List[];
extern const uint32_t Num47List[];

extern int32_t CartoonLinearCalculate(int32_t InputRange, int32_t OutputRange, int32_t Input);
extern int32_t CartoonLogCalculate(int32_t InputRange, int32_t OutputRange, int32_t Input);
extern int32_t CartoonExpCalculate(int32_t InputRange, int32_t OutputRange, int32_t Input);
extern void DisplayNum(const uint32_t *NumList, int32_t Num, uint8_t StartPos, uint8_t Interval, int16_t x, int16_t y, uint8_t DisplayType, CENTER_AREA_DISPLAY_ITEM *DisplayItem);
extern uint8_t CheckAlreadyDisplayed(uint8_t DisplayType);
extern void SetCenterAreaSwitchEffect(uint8_t EffectValid, uint8_t OffsetEffect);
extern void UpdataCenterDisp(uint8_t n);
extern void GUI_DrawDispFunc(uint8_t func_num, uint16_t LeftX, uint16_t RightX, uint16_t WinTopY, uint16_t WinBottomY);
extern void SetCenterAreaDisplayList(CENTER_AREA_DISPLAY_ITEM *item, uint16_t DefaultStartTime);
extern uint8_t CheckCenterAreaSwitchEffect(void);
extern void UpdateClusterError(void); 

extern void UpdateCenterTripC(void);   
extern void OneTransverterSixteen(uint8_t *buf);
extern void  NumberDisplay(uint16_t  data,uint8_t  n,uint8_t  point,uint16_t  x,uint16_t  x1,uint16_t  y,uint16_t  y1);
extern uint8_t App_CalDataLen(uint32_t data);
extern uint8_t CluPartNum[16];

#endif