#ifndef __DEBUG_H__
#define __DEBUG_H__

#endif

#ifndef __KEY_H__
#define __KEY_H__

#include <stdlib.h>
#include <stdint.h>
#include "control_comm.h"

#define		KEY1				P36
#define		KEY2				P31
#define		KEY3				P30
#define		KEY4				P07
#define		KEY5				P05
#define		KEY6				P01	

#define		LED1				P55
#define		LED2				P32
#define		LED3				P54
#define		LED4				P06
#define		LED5				P04
#define		LED6				P00

#define		K1					P10
#define		K2					P24 
#define		K3					P13
#define		K4					P12
#define		K5					P26

#define   	ZERO_INIT  	    	P25


#define    KEY(X)		(KEY##X)
typedef int32_t  s32;
typedef int16_t  s16;
typedef int8_t   s8;

typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t  u8;


typedef struct
{
	volatile 	u32 	operate_delay_off_ms;    
	volatile 	u32  	operate_delay_off_s;  
	volatile 	u32		operate_delay_off_min; 
	volatile 	u32		operate_delay_off_h; 
				u8		operate_delay_off_display_flag;
}Filter_Wash_Calc;
typedef struct KEY_OPERATE
{
			u8      operate_delay_off_status;	//延时关机操作期间标志位判断
			u8      operate_delay_off_display_flag;
volatile 	u32 	operate_delay_off_ms;    
volatile 	u32  	operate_delay_off_s;  
volatile 	u32		operate_delay_off_min; 
volatile 	u32		operate_delay_off_h; 
	
			u8     	operate_join_net   ;
		 uint64_t	operate_last_timer   ;
			s8      operate_calibrate_temp;
	
			u8      operate_calibrate_temper;
	
			u8  record_adjust_delay_off;
			Filter_Wash_Calc    filter_calc;
			u16 set_temper_temp;
}KEY_OPERATE;
typedef void (*KeyProcessCallback)(u8 key_id,u8 KeyPressEvent);



#define  Low      0
#define  High     1
#define  NULL     0


#define AntiShakeTime  		6     //30ms =    6*5ms 按键防止抖动时间
#define PressLongTime  		800  //  4s  = 800*5ms 按键长按时间
#define Press10sLongTime  	2000  //  10s = 2000*5ms 退出老化

#define SyskeyScanTimer     5 //5ms
#define KeyEventBufferNum  30


#define  HOT_AND_COLD_APART    0
#define  ONLY_COLD             1
#define  ONLY_HOT              2
#define  HOT_AND_COLD_SHARED   3

enum{
	SYSTEM_MODE_OFF 				= 0,
	SYSTEM_MODE_AUTO 				= 1,
	SYSTEM_MODE_MANUAL 				= 2,
	SYSTEM_MODE_COOLING 			= 3,
	SYSTEM_MODE_HEATING 			= 4,
	SYSTEM_MODE_EMERGENCY_HEATING 	= 5,
	SYSTEM_MODE_PRE_COOLING			= 6,
	SYSTEM_MODE_AIR					= 7,	
	SYSTEM_MODE_DRY					= 8,
	SYSTEM_MODE_SLEEP				= 9,
	SYSTEM_MODE_ROLL				= 10,
};
enum{
	WIND_DIRECT_DOWN 				= 0,
	WIND_DIRECT_MIDDLE				= 1,
	WIND_DIRECT_UP 					= 2,
};

#define   COLD_MODE             0X01					//制冷模式     //wait to modefied    lmm test
#define   HEAT_MODE             0X02 				  //加热模式
#define   AIR_MODE              0X03         	//通风模式
#define   AREFACTION            0X04          	//除湿模式  /Modify by YWQ      

#define   WIND_SPEED_LOW        0x01             //低速
#define   WIND_SPEED_MID        0x02             //中速
#define   WIND_SPEED_HIGH       0x03             //高速
#define   WIND_SPEED_AUTO       0x05             //自动


#define   SET_LONG_TIME         0X01           //长按SET键
#define   SET_SHORT_TIME        0X02           //短按SET键

#define   AIR_MODE_CHANGE       0X01    		   //模式按键      
#define   WIND_SPEED_CHANGE     0X02    		   //风速按键
#define   TIMING_CHANGE         0X03		       //定时按键
#define   POWER_SWITCH_CHANGE   0X04		       //开关按键
#define   SET_CHANGE            0X05    		   //SET按键

#define   RELAY1              	0X00           
#define   RELAY2              	0X01           
#define   RELAY3          		0X02           
#define   RELAY4          		0X03           
#define   RELAY5         		0X04         
#define   RELAY_ALL             0X05         


/*
向右

        L           M           H
A = 	1	B = 	1	C = 	0
A = 	1	B = 	0	C = 	1
A = 	0	B = 	1	C = 	1
A = 	1	B = 	1	C = 	0
A = 	1	B = 	0	C = 	1
A = 	0	B = 	1	C = 	1
A = 	1	B = 	1	C = 	0
A = 	1	B = 	0	C = 	1
A = 	0	B = 	1	C = 	1
A = 	1	B = 	1	C = 	0
A = 	1	B = 	0	C = 	1
A = 	0	B = 	1	C = 	1

向左

A = 	1	B = 	1	C = 	0
A = 	0	B = 	1	C = 	1
A = 	1	B = 	0	C = 	1
A = 	1	B = 	1	C = 	0
A = 	0	B = 	1	C = 	1
A = 	1	B = 	0	C = 	1
A = 	1	B = 	1	C = 	0
A = 	0	B = 	1	C = 	1
A = 	1	B = 	0	C = 	1
A = 	1	B = 	1	C = 	0
A = 	0	B = 	1	C = 	1

*/
#define KeyTotalNum			 6


#define Key_Button    0x01
#define Key_Rotary    0x02

#define NoButtonEvent              0x00
#define ButtonShortEvent           0x80
#define ButtonLongEvent            0x90
#define ButtonLongUpEvent          0xa0
#define Button10sLongEvent         0xb0

#define AIR_CMD_ONOFF					1
#define AIR_CMD_SYSTEM_MODE				2
#define AIR_CMD_FAN_SPEED				3
#define AIR_CMD_FAN_DIRECT				4
#define AIR_CMD_SET_TEMPER				5

typedef struct key_t 
{
    /* 上次按下的按键状态 */
    u8 PreState;
    
    /* 当前按下的按键状态 */
    u8 LastState;
    
    /* 当前按下的按键状态 */
    u8 PreKeyEvent;

    u16  KeyTime;  //消除抖动时间
	
} KeyScan_t;
typedef struct key_init 
{
    /* key id */
    u8 KeyId;
    
	GPIO_T *port;
	
    /* key pin */
    uint32_t u32Pin;
    
    /* 有效电平 */
    u8 Valid_Level;
	
} KeyConfigInit_t;
typedef struct 
{
    /* key id */
    u8 support_tap_num;
    
	u8 save_tap_status[6];

	u8 tap_to_do[6];    //对应（K1,K2,K3,K4,K5）
	
	u8 set_tap ;
	
	u8 tap_end_flage ;
	
} TAP_CONTROL_ST;

extern KEY_OPERATE  sKey_Operation[3];

extern   TAP_CONTROL_ST  Tap_Control;
extern  u8 InputKeyEvent(u8 Key_index,u8 Event);
extern void SetkeyScanTime(u16 uSetkeyScanTime);
void Delay_OFF_Rel_Display(u8 stop_flash,u8 delay_timer,u8 dispaly_data,u8 H_char,u8 bell_char,u8 setting_time_char);

void Control_OnOff_handler(u8 device_type,u8 onoff);

void Control_ChildLock_Onoff(u8 device_type,u8 onoff);

void Fan_PassbyONOFF_By_Mode_Trans(u8 system_mdoe,u8 reset_count_time);

void Relay_Action(u8 control_relay_bits,u8 onoff_bits);
void Tap_Status_Scan(void);
void Tap_Init(void);
void Fan_Speed_Control(u8 wind_speed);

extern u16 GetkeyScanTime( void );

extern void InputButtonInit(void);

extern void key_scan(void);

extern  void  display_power_off(u8 ds_type) ;

extern void display_power_off_flage(void);

void  KeyEventHandle( s16 SetMode ,u8 Rank);

void Oled_Display_whole(void);

void Tap_Status_Scan(void);

void  Save_Tap_Switch(void);
void  Tap_Switch(void);
void  Auto_Wind (void);
void  display_real_temp(int temp_value);



extern void  Aging_test(void);

#endif 


