#include <stdio.h>
#include "mini58series.h"
#include "BL55072A.h"
#include "hardware_init.h"
#include "CC2530_transparent_analyze.h"
#include "control_comm.h"
#include "display_common.h"
								
u16 guSetkeyScanTime 							= SyskeyScanTimer;
u8 gKeyEventCNT[KeyTotalNum]        			= {0,0,0,0,0,0};//按键扫描事件计数
u8 KeyEventBuffer[KeyTotalNum][KeyEventBufferNum]       	= {0};

KeyScan_t gKey1_Button_t      = { High, High, NULL, NULL }; 
KeyScan_t gKey_Button_t[KeyTotalNum] = { { High, High, NULL, NULL },{ High, High, NULL, NULL },{ High, High, NULL, NULL },\
										 { High, High, NULL, NULL },{ High, High, NULL, NULL },{ High, High, NULL, NULL },};

						 
KeyConfigInit_t gKey_Button_Config[] = { { 1, P3, BIT6, High},\
								   { 2, P3, BIT1, High},\
								   { 3, P3, BIT0, High},\
								   { 4, P0, BIT7, High},\
								   { 5, P0, BIT5, High},\
								   { 6, P0, BIT1, High},\
};
u8 boad_test_falg[6]    = {0,0,0,0,0,0};				//index 0 - 5分别代表按键1 - 按键6

KEY_OPERATE  sKey_Operation[3] = {0};
#if 1
TAP_CONTROL_ST  Tap_Control = {6,{0,0,0,0,0,0},{0,0,0,0,0,0},0,0} ;
#else
#endif
//KeyProcessCallback  KeyProcess_Handler_Callbacks = NULL;

static void KEY1_Botton_Process_Handler(u8 KeyPressEvent);
static void KEY2_Botton_Process_Handler(u8 KeyPressEvent);
static void KEY3_Botton_Process_Handler(u8 KeyPressEvent);
static void KEY4_Botton_Process_Handler(u8 KeyPressEvent);
static void KEY5_Botton_Process_Handler(u8 KeyPressEvent);
static void KEY6_Botton_Process_Handler(u8 KeyPressEvent);

void KeyProcess_Handler_Callbacks(u8 key_id,u8 KeyPressEvent);
u8 Get_NextOne_By_Current_Speed_Level(u8 plus_or_sub,u8 fan_speed,u8 type_support);
u8 Get_NextOne_By_Current_wind_direct(u8 plus_or_sub,u8 wind_direct);
void Delay_OFF_Rel_Display(u8 stop_flash,u8 delay_timer,u8 dispaly_data,u8 H_char,u8 bell_char,u8 setting_time_char);
static void Tap_Status_Scan_Task_Start(void);

extern BACKLIGHT_CONTROL sBacklight;

extern  Lcd_Status_Info_t  LCDShowTemp_state_t;

u8   First_Exit_Factory_Mode = 0;

#if DEVICE_TYPE_FAN
u8 auto_time = 0;
u8 auto_type = 0;
#endif
/*
10S 长按处理
*/
static _Bool LongLongPress10s_Handler(u8 keyid,u8 KeyPressEvent)
{
	//退老化处理
	static u32 last_time = 0;
	static u8 first_10s_press = 0;
	if((keyid == 6) &&(KeyPressEvent == Button10sLongEvent))
	{
		if(Oled_Display_Info.aging_test_flag != 2) 
		{
			Spake_Start();
			if( ((Oled_Display_Info.local_timer -  last_time) <= 20*1000)&&first_10s_press )
			{
				first_10s_press = 0;
				//所有指示灯闪烁一次
				kNetIndicatorOptTrigger(7, 200,200, 5*1000/(200+200),0,1 );
				LCD_CONTROL(1);
				BL55072A_DisplayALL();
				Oled_Display_Info.aging_test_flag = 2;		//写入产测标志位
				First_Exit_Factory_Mode  = 1; 
				save_data();	
				aging_test_stop();							//停止老化事件
				task_exit_aging_test_start();				
				return TRUE;
			}
			else
			{
				first_10s_press = 1;
				last_time = Oled_Display_Info.local_timer;
				//所有指示灯闪烁一次
				if(LED1)
					kNetIndicatorOptTrigger(7, 200,200, 1,0,1 );
				else
					kNetIndicatorOptTrigger(7, 200,200, 1,1,0 );
			}
		}
	}
	//滤网清洗事件错误清除
	if((keyid == 2) &&(KeyPressEvent == Button10sLongEvent))
	{
		if(Oled_Display_Info.screen_page == AIR_CONDITION)
		{
			if(Oled_Display_Info.Air_Device.on_off)
			{
				if(Oled_Display_Info.Air_Device.error == 3)
				{
					Oled_Display_Info.Air_Device.error = 0;
					if(Get_Display_Status())    //清除错误
					{
						LCDShowTemp_state_t.LCD_place = DELAY_OFF_TIME_DISPLAY;	
						LCDShowTemp_state_t.LCD_display_count = 0;				
						LCDShowTemp_state_t.LCD_state = OFF;
						LcdShowCTR(LCDShowTemp_state_t);
					}
					Oled_Display_Info.Air_Device.filter_wash_time = 3000;
					save_data();																			//重置滤网时间
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
					return TRUE;
				
				}
			}	
		}	
		else if(Oled_Display_Info.screen_page == FAN)
		{
			if(Oled_Display_Info.FAN_Device.on_off)
			{
				if(Oled_Display_Info.FAN_Device.error == 3)
				{
					Oled_Display_Info.FAN_Device.error = 0;
					if(Get_Display_Status())    															//清除错误
					{
						LCDShowTemp_state_t.LCD_place = DELAY_OFF_TIME_DISPLAY;		
						LCDShowTemp_state_t.LCD_state = OFF;
						LCDShowTemp_state_t.LCD_display_count = 0;			
						LcdShowCTR(LCDShowTemp_state_t);
					}
					Oled_Display_Info.FAN_Device.filter_wash_time = 3000;
					save_data();																			//重置滤网时间
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);									//状态更新上报
					return TRUE;					
				}
			}	
		
		}
	}
	return FALSE;
}
static u8 Get_Key_Pin_By_Index(u8 index)
{
	u8 Key_Pin = 0;
	switch(index)
	{
		case 0:
			Key_Pin = KEY1;
			break;
		case 1:
			Key_Pin = KEY2;
			break;
		case 2:
			Key_Pin = KEY3;
			break;
		case 3:
			Key_Pin = KEY4;
			break;
		case 4:
			Key_Pin = KEY5;
			break;
		case 5:
			Key_Pin = KEY6;
			break;
	}
	return Key_Pin;
}	
/*
控制输入按键扫描速度
*/
void SetkeyScanTime(u16 uSetkeyScanTime)
{
    guSetkeyScanTime = uSetkeyScanTime;
}

u16 GetkeyScanTime( void )
{
    return guSetkeyScanTime;
}
static void ButtonLongEvent_Init(KeyConfigInit_t *Key_Config,u8 Key_Total_Num)
{
	u8 index = 0;
	for(index = 0;index < Key_Total_Num;index++)
	{
		GPIO_SetMode(Key_Config->port,Key_Config->u32Pin,GPIO_MODE_QUASI);
	}


}
void InputButtonInit(void)
{
	ButtonLongEvent_Init(gKey_Button_Config,sizeof(gKey_Button_Config)/sizeof(gKey_Button_Config[0]));
	
	GPIO_SetMode(P5, BIT5, GPIO_MODE_OUTPUT);/* LED1   模式按键 Mode button */
	GPIO_SetMode(P3, BIT2, GPIO_MODE_OUTPUT);/* LED2   风速按键 Wind speed button */
    GPIO_SetMode(P5, BIT4, GPIO_MODE_OUTPUT);/* LED3   定时按键 Timing button */	
    GPIO_SetMode(P0, BIT6, GPIO_MODE_OUTPUT);/* LED4   开关按键 Switch button */
    GPIO_SetMode(P0, BIT4, GPIO_MODE_OUTPUT);/* LED5   设置按键 Setting button */
	GPIO_SetMode(P0, BIT0, GPIO_MODE_OUTPUT);/* LED6   设置按键 Setting button */
	
    GPIO_SetMode(P1, BIT0, GPIO_MODE_OUTPUT); //K1
    GPIO_SetMode(P2, BIT4, GPIO_MODE_OUTPUT); //K2
//  GPIO_SetMode(P1, BIT3, GPIO_MODE_OUTPUT); //K3
//  GPIO_SetMode(P2, BIT4, GPIO_MODE_OUTPUT); //K4	
    GPIO_SetMode(P2, BIT6, GPIO_MODE_OUTPUT); //K5
	
	#if DEVICE_TYPE_FAN
	//老化完成，config K3,K4 relay
	if(Oled_Display_Info.aging_test_flag == 2)
	{
		GPIO_SetMode(P1, BIT3, GPIO_MODE_OUTPUT); //K3
		GPIO_SetMode(P1, BIT2, GPIO_MODE_OUTPUT); //K4	
		
		//K3   = 1;								//默认自动
		K4   = 0;
	}
	#endif
	
	
	GPIO_SetMode(P5, BIT2, GPIO_MODE_OUTPUT); //LCD CONTROL
	P52 = 0;

	
	LED1 = 0;
	LED2 = 0;
	LED3 = 0;
	LED4 = 0;
	LED5 = 0;
	LED6 = 0;
	
	K1   = 0;
	K2   = 0;
//	K3   = 0;
//	K4   = 0;
	K5   = 0;
}

/*
存储按键扫描事件
*/
u8 InputKeyEvent(u8 Key_index,u8 Event)
{
        
	if( KeyEventBufferNum >= gKeyEventCNT[Key_index] )
	{
		KeyEventBuffer[Key_index][gKeyEventCNT[Key_index]] = Event;
		//printf("gKeyEventCNT[%x] = 0x%x; KeyEventBuffer[gKeyEventCNT] = 0x%x\n",Key_index,gKeyEventCNT[Key_index],Event);  
		gKeyEventCNT[Key_index] ++;		
	}
	else
	{
		//printf("Lost KeyEventBuffer = 0x%x",Event);
		return 0xff;               
	}
            
    return NoButtonEvent;
}
u8 GetKeyEvent(u8 index )
{
    u8 uReturnEvent = NoButtonEvent;
    u8 i = NULL;

	if(gKeyEventCNT[index])
	{
		uReturnEvent = KeyEventBuffer[index][0];
		gKeyEventCNT[index]--;                             //更新标记位

		for(i = NULL; i < gKeyEventCNT[index]; i++)        //整理数据
		{
			KeyEventBuffer[index][i] = KeyEventBuffer[index][i+1];
		}
		//printf("GetKeyEvent,index %x uReturnEvent = 0x%x\r\n",index,KeyEventBuffer[index][0]);     
		 
	}
	else
	{
		uReturnEvent = NoButtonEvent;
	}

    return uReturnEvent;     
}
u8 KeyScanState( KeyScan_t* Buttion_T,  u8 ButtonState )
{
    u8 EventReturn = NoButtonEvent;
    static uint8_t count = 0;
    //printf("ButtonState = 0x%x\n",ButtonState);
    
    Buttion_T->LastState = ButtonState;

    ///**** 按键短按事件         ****/
    if( 
          (High == Buttion_T->LastState )
        &&( Low == Buttion_T->PreState )
        &&( AntiShakeTime < Buttion_T->KeyTime )
        &&( PressLongTime > Buttion_T->KeyTime)
        &&( ButtonLongEvent != (Buttion_T->PreKeyEvent) )
        )
    {
        Buttion_T->KeyTime = NULL;
        Buttion_T->PreKeyEvent = ButtonShortEvent;
        EventReturn = ButtonShortEvent;//InputKeyEvent( Key_Button, ModeButtonShortEvent );      
        //DBG_PRINT("EventReturn = 0x%x\n",EventReturn);
    }

	///*****  2s按键长按事件         ****/
    if( 
          ( Low == Buttion_T->LastState )
        &&(  (PressLongTime/2) <= (Buttion_T->KeyTime) )

    )
    {
		
        Buttion_T->KeyTime = NULL;
		count++;
		if(count == 5)				//10s
		{
			count = 0;
			Buttion_T->PreKeyEvent = Button10sLongEvent;
			EventReturn = Button10sLongEvent;//InputKeyEvent( Key_Button, ModeButtonLongEvent );
		}
		else if(count == 2)			//4s
		{
			Buttion_T->PreKeyEvent = ButtonLongEvent;
			EventReturn = ButtonLongEvent;//InputKeyEvent( Key_Button, ModeButtonLongEvent );
		}
    }
	
    ///**** 按键计时，用于消除抖动和判断长/短按事件                      *****/

    if( ( Low == Buttion_T->LastState ))// && ( Buttion_T->KeyTime < PressLongTime ) )
    {
        Buttion_T->KeyTime++;
    }
    else
    {
        Buttion_T->KeyTime = NULL;

        if( ButtonLongEvent == (Buttion_T->PreKeyEvent) )
        {
			count = 0;
            Buttion_T->PreKeyEvent = ButtonLongUpEvent;
            EventReturn = ButtonLongUpEvent;
        }

    }
    ///**** 状态更新       *****/
    if( Buttion_T->LastState != Buttion_T->PreState )  Buttion_T->PreState = Buttion_T->LastState;
	
    return EventReturn;
}

void key_scan(void)
{
    static u8 EventTemp[KeyTotalNum] = {NoButtonEvent,NoButtonEvent,NoButtonEvent,NoButtonEvent,NoButtonEvent,NoButtonEvent};
	u8 i = 0;
    memset(EventTemp,0,sizeof(EventTemp));  
    if(!GetkeyScanTime())
    {
        SetkeyScanTime(SyskeyScanTimer);
		for(i = 0;i<KeyTotalNum;i++)
		{
			if( NoButtonEvent != (EventTemp[i] = KeyScanState( &gKey_Button_t[i], Get_Key_Pin_By_Index(i) ))  )   
			{
				InputKeyEvent(i,EventTemp[i]);
			}
		}
	}
	for(i = 0;i<KeyTotalNum;i++)
	{
		u8 KeyEventTemp = GetKeyEvent(i);
		if(!KeyEventTemp)
			continue;
		boad_test_falg[i]  = 1;							//按键检测功能
		KeyProcess_Handler_Callbacks((i+1),KeyEventTemp);

	}
}
static void LED_BEEP_Feedback(u8 key_id)
{
	if(  ((Oled_Display_Info.screen_page == 1)&&(Oled_Display_Info.Air_Device.no_disturb_mode == 0  ) )
			||((Oled_Display_Info.screen_page == 2)&&(Oled_Display_Info.FLOOR_Device.no_disturb_mode == 0) )
			||((Oled_Display_Info.screen_page == 3)&&(Oled_Display_Info.FAN_Device.no_disturb_mode == 0)   )  )
		Spake_Start();
		
		if(Oled_Display_Info.net_work_flage == IN_LINE)
		{
			kNetIndicatorOptTrigger(key_id, 200, 200, 1, 0, 1 );	
		
		}else{
			kNetIndicatorOptTrigger(key_id, 200, 200, 3, 0, 1 );	
		}
}
void KeyProcess_Handler_Callbacks(u8 key_id,u8 KeyPressEvent)
{
	//printf("####KeyProcess_Handler_Callbacks,keyid = %d,Key_Event = %x\r\n",key_id,KeyPressEvent);
	if(Key_Operate_Config_Operation(key_id,KeyPressEvent))
	{
		LED_BEEP_Feedback(key_id);
		return;
	}
	if(LongLongPress10s_Handler(key_id,KeyPressEvent))
		return;
	//15min-4h老化期间不能操作按键
	if((Oled_Display_Info.aging_test_flag == 1)||(First_Exit_Factory_Mode == 1)||(KeyPressEvent == Button10sLongEvent))   
		return;
	//printf("####KeyProcess_Handler_After ,keyid = %d,Key_Event = %x\r\n",key_id,KeyPressEvent);
	if(KeyPressEvent != ButtonLongEvent)
	{
		Detect_Human_Dispaly();
		if(IsLcdEnterScreenSave())							//息屏状态，触摸按键，该次触发只唤醒，不做有效触发
		{
			Reload_Save_Time();	
			Detect_Human_Dispaly();                        //cannot delete
			return;
		}
		Reload_Save_Time();	
		//地暖的按键2无效
		if( (Oled_Display_Info.screen_page == 2)&&(key_id == 2)&&(Oled_Display_Info.aging_test_flag == 2))
			return;
		LED_BEEP_Feedback(key_id);
	}
	
	/******************************************
	童锁打开后，操作按键处理
	*******************************************/
	if(  ((Oled_Display_Info.screen_page == 1)&&(Oled_Display_Info.Air_Device.lock_flage)) 
	   ||((Oled_Display_Info.screen_page == 2)&&(Oled_Display_Info.FLOOR_Device.lock_flage)) 
	   ||((Oled_Display_Info.screen_page == 3)&&(Oled_Display_Info.FAN_Device.lock_flage)) )
	{
		if((key_id == 3)&&(KeyPressEvent == ButtonLongEvent))
		{
			//处理关机条件下的解锁
			if( (Oled_Display_Info.screen_page == 1)&&(Oled_Display_Info.Air_Device.on_off == 0))
			{
				Control_ChildLock_Onoff(AIR_CONDITION,0);	
				return	;
			}
			else if((Oled_Display_Info.FLOOR_Device.lock_flage)&&(Oled_Display_Info.FLOOR_Device.on_off == 0))
			{
				Control_ChildLock_Onoff(FLOOR_HEATING,0);
				return	;
			}
			else if((Oled_Display_Info.FAN_Device.lock_flage)&&(Oled_Display_Info.FAN_Device.on_off == 0))
			{
				Control_ChildLock_Onoff(FAN,0);	
				return	;
			}
					
		}else{
			if( ((key_id == 3)&&(KeyPressEvent == ButtonShortEvent)) ||
			    (key_id != 3) )
			{
				LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;	
				LCDShowTemp_state_t.LCD_state = ON;
				LcdShowCTR(LCDShowTemp_state_t);
				
				LCDShowTemp_state_t.LCD_state = FLASHING;
				LCDShowTemp_state_t.LCD_display_count = 6;
				LCDShowTemp_state_t.LCD_display_timer = 20;									
				LcdShowCTR(LCDShowTemp_state_t);
				
				ChildLockLedFlash();						//led 3闪烁
				return;
			}
		}
	}
	/******************************************
	非调节风速按键按下，如果之前存在风速闪烁，则打断
	*******************************************/
	if( (gKey_Press_Info.adjust_fan_speed_status)&&((key_id == 1)||(key_id == 3)||(key_id == 4)))    
	{
		delay_confirm_fan_speed();
	}
	/******************************************
	延时关机时间调节期间，如果按下非调节按键，则打断
	*******************************************/
	if((sKey_Operation[Oled_Display_Info.screen_page-1].operate_delay_off_status)&&
		((key_id == 2)||(key_id == 3)||(key_id == 4)))
	{			
		sKey_Operation[Oled_Display_Info.screen_page-1].operate_delay_off_status = 0;
		Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
		Oled_Display_whole();
		delay_operate_delay_off_Task_Stop();
	}
	/******************************************
	温度校准调节期间，如果按下非调节按键，则打断
	*******************************************/
	if((sKey_Operation[Oled_Display_Info.screen_page-1].operate_calibrate_temper)&&(KeyPressEvent != ButtonLongUpEvent)&&
		((key_id == 2)||(key_id == 4) ||(key_id == 3)))
	{
		sKey_Operation[Oled_Display_Info.screen_page-1].operate_calibrate_temper = 0;
		delay_operate_calibrate_temper_Task_Stop();
		
		LCDShowTemp_state_t.LCD_place = CALIBRATE_TEMPER_DISPLAY;	
		LCDShowTemp_state_t.LCD_state = OFF;
		LcdShowCTR(LCDShowTemp_state_t);
		PowerOff();
	}
	/******************************************
	温度校准调节完成后，2s内打开开关，取消2s关机延时
	*******************************************/
	if( (is_operate_calibrate_temper_delay_2s_off_Task_start())&&(key_id == 1) )
	{
		operate_calibrate_temper_delay_2s_off_Task_Stop();
	}
	switch(key_id)
	{
		case 1:
			KEY1_Botton_Process_Handler(KeyPressEvent);
			break;
		case 2:
			KEY2_Botton_Process_Handler(KeyPressEvent);
			break;
		case 3:
			KEY3_Botton_Process_Handler(KeyPressEvent);
			break;
		case 4:
			KEY4_Botton_Process_Handler(KeyPressEvent);
			break;
		case 5:
			KEY5_Botton_Process_Handler(KeyPressEvent);
			break;
		case 6:
			KEY6_Botton_Process_Handler(KeyPressEvent);
			break;
		default:
			break;
	}
}
void Delay_Power_Off_Control(u8 control_type,u16 flashing_time_ms,u16 flash_interval_time_ms,u8 show_num)
{
	LCDShowTemp_state_t.LCD_place = DELAY_OFF_TIME_DISPLAY;
	if(control_type == FLASHING)
	{
		
		LCDShowTemp_state_t.LCD_state = FLASHING;
		if(flash_interval_time_ms)
			LCDShowTemp_state_t.LCD_display_count  = flashing_time_ms/flash_interval_time_ms;								//15s
		else
			LCDShowTemp_state_t.LCD_display_count  = 0;
		LCDShowTemp_state_t.LCD_display_timer  = flash_interval_time_ms/10;								
	}
	else 
	{
		LCDShowTemp_state_t.LCD_state = control_type;
		LCDShowTemp_state_t.LCD_display_count  = 0;								
		LCDShowTemp_state_t.LCD_display_timer  = 0;	
	}
	LCDShowTemp_state_t.LCD_code_data = show_num;
	LcdShowCTR(LCDShowTemp_state_t);
}
void Delay_OFF_Rel_Display(u8 stop_flash,u8 delay_timer,u8 dispaly_data,u8 H_char,u8 bell_char,u8 setting_time_char)
{
	if(stop_flash)
	{
		Delay_Power_Off_Control(DFLASHING,NULL,NULL,dispaly_data);
	}
	
	if(delay_timer)
	{
		if(dispaly_data >0)
			Delay_Power_Off_Control(ON,NULL,NULL,dispaly_data);
	}
	else
	{
		Delay_Power_Off_Control(OFF,NULL,NULL,dispaly_data);
		
	
	}
	if(H_char)
	{
		//显示H图标
		LCDShowTemp_state_t.LCD_place = H_CHAR_DISPLAY;	
		LCDShowTemp_state_t.LCD_state = ON;		
	}
	else{
		LCDShowTemp_state_t.LCD_place = H_CHAR_DISPLAY;	
		LCDShowTemp_state_t.LCD_state = OFF;			
	}
	LcdShowCTR(LCDShowTemp_state_t);	
	if(bell_char){	
		//显示闹钟
		LCDShowTemp_state_t.LCD_place = SETTING_TIMER_DISPLAY;		
		LCDShowTemp_state_t.LCD_state = ON;
		
	}else{
		LCDShowTemp_state_t.LCD_place = SETTING_TIMER_DISPLAY;		
		LCDShowTemp_state_t.LCD_state = OFF;
	}
	LcdShowCTR(LCDShowTemp_state_t);
					
	if(setting_time_char)
	{	
		//显示设定时长字符图标
		LCDShowTemp_state_t.LCD_place = SETTING_TIMER_CHAR_DISPLAY;		
		LCDShowTemp_state_t.LCD_state = ON;
		
	}else{
		LCDShowTemp_state_t.LCD_place = SETTING_TIMER_CHAR_DISPLAY;		
		LCDShowTemp_state_t.LCD_state = OFF;
	}
	LcdShowCTR(LCDShowTemp_state_t);
	
	//关闭可能显示的摄制度字符
	LCDShowTemp_state_t.LCD_place = UPPER_TEMPER_UNIT_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = OFF;
	LcdShowCTR(LCDShowTemp_state_t);
}
void Calib_Temp_Control(u8 control_type,u16 flashing_time_ms,u16 flash_interval_time_ms,u16 show_num)
{
	LCDShowTemp_state_t.LCD_place = CALIBRATE_TEMPER_DISPLAY;
	if(control_type == FLASHING)
	{
		
		LCDShowTemp_state_t.LCD_state = FLASHING;
		if(flash_interval_time_ms)
			LCDShowTemp_state_t.LCD_display_count  = flashing_time_ms/flash_interval_time_ms;								//15s
		else
			LCDShowTemp_state_t.LCD_display_count = 0;
		LCDShowTemp_state_t.LCD_display_timer  = flash_interval_time_ms/10;								
	}
	else 
	{
		LCDShowTemp_state_t.LCD_state = control_type;
		LCDShowTemp_state_t.LCD_display_count  = 0;								
		LCDShowTemp_state_t.LCD_display_timer  = 0;	
	}
	LCDShowTemp_state_t.LCD_code_data = show_num;
	LcdShowCTR(LCDShowTemp_state_t);
}
void Control_OnOff_handler(u8 device_type,u8 onoff)
{
	switch(device_type)
	{
		case AIR_CONDITION:
		{
			if(onoff == 1)
			{
				Oled_Display_Info.Air_Device.on_off = 1;
				Oled_Display_whole();
			}
			else
			{
				PowerOff();
				Oled_Display_Info.Air_Device.on_off = 0;
				if(Oled_Display_Info.Air_Device.power_off_time >0)
				{
					Oled_Display_Info.Air_Device.power_off_time = 0;
					Oled_Display_Info.Air_Device.power_off_flage = 0;						
					sKey_Operation[0].record_adjust_delay_off 		= 0;
				}
			}
		}
			break;
		case FLOOR_HEATING:
		{
			if(onoff == 1)
			{
				Oled_Display_whole();
				Oled_Display_Info.FLOOR_Device.on_off = 1;
				#if DEVICE_TYPE_FLOOR_HEATING
				Tap_Status_Scan_Task_Start();	
				#endif
			}
			else
			{
				PowerOff();
				#if DEVICE_TYPE_FLOOR_HEATING
				Relay_Action(0x01,0x00);																//控制阀门打开
				#endif
				Oled_Display_Info.FLOOR_Device.on_off = 0;
				if(Oled_Display_Info.FLOOR_Device.power_off_time >0)
				{
					Oled_Display_Info.FLOOR_Device.power_off_time = 0;	
					Oled_Display_Info.FLOOR_Device.power_off_flage = 0;				
					sKey_Operation[1].record_adjust_delay_off 		= 0;
				}
			}
		}
			break;
		case FAN:
		{
			if(onoff == 1)
			{
				Oled_Display_whole();
				Oled_Display_Info.FAN_Device.on_off = 1;
				#if DEVICE_TYPE_FAN
					Fan_PassbyONOFF_By_Mode_Trans(Oled_Display_Info.FAN_Device.system_type,1);
					Fan_Speed_Control(Oled_Display_Info.FAN_Device.wind_speed);
				#endif
			}
			else
			{
				PowerOff();
				Oled_Display_Info.FAN_Device.on_off = 0;
				#if DEVICE_TYPE_FAN
				Relay_Action(0x0F,0x00);							//关闭全部继电器
				#endif
				if(Oled_Display_Info.FAN_Device.power_off_time >0)
				{
					Oled_Display_Info.FAN_Device.power_off_time = 0;
					Oled_Display_Info.FAN_Device.power_off_flage = 0;
					sKey_Operation[2].record_adjust_delay_off 		= 0;
				}
			}
		
		}
			break;
	}
}
static void KEY1_Botton_Process_Handler(u8 KeyPressEvent)
{
	switch(KeyPressEvent)
	{
		case ButtonShortEvent:
		{
			if(Oled_Display_Info.screen_page == 1)															//空调页面
			{
				if(Oled_Display_Info.Air_Device.on_off)
				{
					if(sKey_Operation[0].operate_delay_off_status)
					{
						sKey_Operation[0].operate_delay_off_status = 0;
						
						Oled_Display_Info.Air_Device.power_off_time = sKey_Operation[0].record_adjust_delay_off;
						if(Oled_Display_Info.Air_Device.power_off_time >0)
						{
							Oled_Display_Info.Air_Device.power_off_flage  = 1;
							Reset_DelayOFF_timer(AIR_CONDITION);
							Delay_OFF_Rel_Display(1,1,Oled_Display_Info.Air_Device.power_off_time,1,1,1);
						}
						else
						{
							Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
							Display_Up_Contend(AIR_CONDITION);
						}
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
					}
					else 
					{
						Control_OnOff_handler(AIR_CONDITION,0);
						#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
							delay_control_onoff_start();
						#else
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
						#endif	
					}
					
				}
				else
				{
					if(sKey_Operation[0].operate_calibrate_temper)
					{
						u16 display_data = 0;
						sKey_Operation[0].operate_calibrate_temper = 0;
						operate_calibrate_temper_delay_2s_off_Task_Start();
						delay_operate_calibrate_temper_Task_Stop();					//15s 计时取消
						
						display_data = Oled_Display_Info.Air_Device.real_temperature - Oled_Display_Info.Air_Device.correct_temperature + sKey_Operation[0].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						
						Oled_Display_Info.Air_Device.real_temperature = Oled_Display_Info.Air_Device.real_temperature - Oled_Display_Info.Air_Device.correct_temperature + sKey_Operation[0].operate_calibrate_temp;
						Oled_Display_Info.Air_Device.correct_temperature = sKey_Operation[0].operate_calibrate_temp;
						save_data();																			//保存token
						
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
					}
					else{
						Control_OnOff_handler(AIR_CONDITION,1);
						
						#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
							delay_control_onoff_start();
						#else
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
						#endif	
					}
				}
			}
			else if(Oled_Display_Info.screen_page == 2)
			{
				if(Oled_Display_Info.FLOOR_Device.on_off)
				{
					if(sKey_Operation[1].operate_delay_off_status)
					{
						sKey_Operation[1].operate_delay_off_status = 0;
						
						Oled_Display_Info.FLOOR_Device.power_off_time = sKey_Operation[1].record_adjust_delay_off;
						if(Oled_Display_Info.FLOOR_Device.power_off_time >0)
						{
							Oled_Display_Info.FLOOR_Device.power_off_flage  = 1;
							Reset_DelayOFF_timer(FLOOR_HEATING);
							Delay_OFF_Rel_Display(1,1,Oled_Display_Info.FLOOR_Device.power_off_time,1,1,1);
						}
						else
						{
							Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
							Display_Up_Contend(FLOOR_HEATING);
						}
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);									//状态更新上报
					}
					else 
					{
						Control_OnOff_handler(FLOOR_HEATING,0);													//控制阀门关闭					
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);									//状态更新上报
					}
					
				}
				else
				{
					if(sKey_Operation[1].operate_calibrate_temper)
					{
						u16 display_data = 0;
						sKey_Operation[1].operate_calibrate_temper = 0;
						
						operate_calibrate_temper_delay_2s_off_Task_Start();			//2s计时开启
						delay_operate_calibrate_temper_Task_Stop();					//15s 计时取消
						
						display_data = Oled_Display_Info.FLOOR_Device.real_temperature - Oled_Display_Info.FLOOR_Device.correct_temperature + sKey_Operation[1].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						
						Oled_Display_Info.FLOOR_Device.real_temperature = Oled_Display_Info.FLOOR_Device.real_temperature - Oled_Display_Info.FLOOR_Device.correct_temperature + sKey_Operation[1].operate_calibrate_temp;
						Oled_Display_Info.FLOOR_Device.correct_temperature = sKey_Operation[1].operate_calibrate_temp;
						save_data();
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);									//状态更新上报
					}
					else{
						Control_OnOff_handler(FLOOR_HEATING,1);													
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);									//状态更新上报
					}
				}
			}
			else if(Oled_Display_Info.screen_page == 3)
			{
				if(Oled_Display_Info.FAN_Device.on_off)
				{
					if(sKey_Operation[2].operate_delay_off_status)
					{
						sKey_Operation[2].operate_delay_off_status = 0;
						
						Oled_Display_Info.FAN_Device.power_off_time = sKey_Operation[2].record_adjust_delay_off;
						if(Oled_Display_Info.FAN_Device.power_off_time >0)
						{
							Oled_Display_Info.FAN_Device.power_off_flage  = 1;
							Reset_DelayOFF_timer(FAN);
							Delay_OFF_Rel_Display(1,1,Oled_Display_Info.FAN_Device.power_off_time,1,1,1);
						}
						else
						{
							Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
							Display_Up_Contend(FAN);
						}
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);									//状态更新上报
					}
					else 
					{
						Control_OnOff_handler(FAN,0);		
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);									//状态更新上报
					}
					
				}
				else
				{
					if(sKey_Operation[2].operate_calibrate_temper)
					{
						u16 display_data = 0;
						sKey_Operation[2].operate_calibrate_temper = 0;
						operate_calibrate_temper_delay_2s_off_Task_Start();
						
						delay_operate_calibrate_temper_Task_Stop();					//15s 计时取消
						
						display_data = Oled_Display_Info.FAN_Device.real_temperature - Oled_Display_Info.FAN_Device.correct_temperature + sKey_Operation[2].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						
						Oled_Display_Info.FAN_Device.real_temperature = Oled_Display_Info.FAN_Device.real_temperature - Oled_Display_Info.FAN_Device.correct_temperature + sKey_Operation[2].operate_calibrate_temp;
						Oled_Display_Info.FAN_Device.correct_temperature = sKey_Operation[2].operate_calibrate_temp;
						save_data();
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);									//状态更新上报
					}
					else{
						Control_OnOff_handler(FAN,1);	
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);									//状态更新上报
					}
				}
			}
		}
			break;
		case ButtonLongEvent:
		{
			if(Oled_Display_Info.screen_page == AIR_CONDITION)
			{
				if(Oled_Display_Info.Air_Device.on_off)
				{
					//延时关机设置，开启闪烁
					sKey_Operation[0].operate_delay_off_status   = 1;
					
					//显示H,设定时长，当前时间
					Delay_OFF_Rel_Display(0,1,Oled_Display_Info.Air_Device.power_off_time,1,0,1);
					
					sKey_Operation[0].record_adjust_delay_off  = Oled_Display_Info.Air_Device.power_off_time;
					
					Delay_Power_Off_Control(FLASHING,15000,500,Oled_Display_Info.Air_Device.power_off_time);	
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
				}	
			}	
			else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
			{
				if(Oled_Display_Info.FLOOR_Device.on_off)
				{
					//延时关机设置，开启闪烁
					sKey_Operation[1].operate_delay_off_status   = 1;
					
					//显示H,设定时长，当前时间
					Delay_OFF_Rel_Display(0,1,Oled_Display_Info.FLOOR_Device.power_off_time,1,0,1);
					
					sKey_Operation[1].record_adjust_delay_off  = Oled_Display_Info.FLOOR_Device.power_off_time;
					
					Delay_Power_Off_Control(FLASHING,15000,500,Oled_Display_Info.FLOOR_Device.power_off_time);	
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
				}	
			
			
			}
			else if(Oled_Display_Info.screen_page == FAN)
			{
				if(Oled_Display_Info.FAN_Device.on_off)
				{
					//延时关机设置，开启闪烁
					sKey_Operation[2].operate_delay_off_status   = 1;
					
					//显示H,设定时长，当前时间
					Delay_OFF_Rel_Display(0,1,Oled_Display_Info.FAN_Device.power_off_time,1,0,1);
					
					sKey_Operation[2].record_adjust_delay_off  = Oled_Display_Info.FAN_Device.power_off_time;
					
					Delay_Power_Off_Control(FLASHING,15000,500,Oled_Display_Info.FAN_Device.power_off_time);	
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
				}	
			}

		}
			break;
		case ButtonLongUpEvent:
			break;
		default:
			break;
	}



}
static void KEY2_Botton_Process_Handler(u8 KeyPressEvent)
{
	switch(KeyPressEvent)
	{
		case ButtonShortEvent:
		{
			if(Oled_Display_Info.screen_page == AIR_CONDITION)
			{
				if(Oled_Display_Info.Air_Device.on_off == 0)     //开机模式才能操作
					return;
				
				Fan_Button_Handler();
				
			}
			else if(Oled_Display_Info.screen_page == FAN)
			{
				if(Oled_Display_Info.FAN_Device.on_off == 0)     //开机模式才能操作
					return;
				if(Oled_Display_Info.FAN_Device.wind_speed <3)
					Oled_Display_Info.FAN_Device.wind_speed ++;
				else if(Oled_Display_Info.FAN_Device.wind_speed == 3)
					Oled_Display_Info.FAN_Device.wind_speed = 1;
				/********************************************
				显示当前风速
				*********************************************/
				display_set_temp(1,Oled_Display_Info.FAN_Device.wind_speed,1);
				#if DEVICE_TYPE_FAN
				Fan_Speed_Control(Oled_Display_Info.FAN_Device.wind_speed);
				#endif
				state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);	//状态改变通知	
			}
		}
			break;
		case ButtonLongEvent:
			break;
		case ButtonLongUpEvent:
			break;
		case Button10sLongEvent:
		{
			
		
		}
			break;
		default:
			break;
	}
}
static void KEY3_Botton_Process_Handler(u8 KeyPressEvent)
{
	switch(KeyPressEvent)
	{
		case ButtonShortEvent:
		{
			u8 system_mode_temp = 0;
			if(Oled_Display_Info.screen_page == AIR_CONDITION)
			{
				if(Oled_Display_Info.Air_Device.on_off == 0)     //开机模式才能操作
					return;
				system_mode_temp = System_Mode_Trans(AIR_CONDITION,0);
				Oled_Display_Info.Air_Device.system_type = system_mode_temp;
				
				#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
					delay_control_system_mode_start();
				#else
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
				#endif				
				
			}
			else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
			{
				if(Oled_Display_Info.FLOOR_Device.on_off == 0)     //开机模式才能操作
					return;
				system_mode_temp =System_Mode_Trans(FLOOR_HEATING,0);
				
				Oled_Display_Info.FLOOR_Device.system_type = system_mode_temp;
				if(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_AUTO)
				{
					Oled_Display_Info.FLOOR_Device.set_temperature = 260;
					display_set_temp(0,Oled_Display_Info.FLOOR_Device.set_temperature,0);
				}
				
				state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);	//状态改变通知	
			}
			else if(Oled_Display_Info.screen_page == FAN)
			{
				if(Oled_Display_Info.FAN_Device.on_off == 0)     	//开机模式才能操作
					return;
				system_mode_temp = System_Mode_Trans(FAN,0);
				
				Oled_Display_Info.FAN_Device.system_type = system_mode_temp;
				#if DEVICE_TYPE_FAN
				Fan_PassbyONOFF_By_Mode_Trans(system_mode_temp,1);
				#endif
				state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);	//状态改变通知	
			}
		}
			break;
		case ButtonLongEvent:
		{
			if(Oled_Display_Info.screen_page == AIR_CONDITION)
			{
				if(Oled_Display_Info.Air_Device.on_off == 0)     //关机模式才能操作温度校准
				{
					u16 display_data = 0;
					delay_operate_calibrate_temper_Task_Start();
					sKey_Operation[0].operate_calibrate_temper = 1;
					
					sKey_Operation[0].operate_calibrate_temp =  Oled_Display_Info.Air_Device.correct_temperature;
					display_data =  Oled_Display_Info.Air_Device.real_temperature;
					Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					return;
				}
					
				if(Oled_Display_Info.Air_Device.lock_flage)		//处于锁定状态，长按可解锁
				{
					Oled_Display_Info.Air_Device.lock_flage = 0;
					Control_ChildLock_Onoff(AIR_CONDITION,Oled_Display_Info.Air_Device.lock_flage);
				}
				else{											//处于非锁定状态，长按可上锁
					Oled_Display_Info.Air_Device.lock_flage = 1;
					Control_ChildLock_Onoff(AIR_CONDITION,Oled_Display_Info.Air_Device.lock_flage);
				}
			}
			else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
			{
				if(Oled_Display_Info.FLOOR_Device.on_off == 0)     //关机模式才能操作温度校准
				{
					u16 display_data = 0;
					delay_operate_calibrate_temper_Task_Start();
					sKey_Operation[1].operate_calibrate_temper = 1;
					
					sKey_Operation[1].operate_calibrate_temp =  Oled_Display_Info.FLOOR_Device.correct_temperature;
					display_data =  Oled_Display_Info.FLOOR_Device.real_temperature;
					Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					return;
				}
					
				if(Oled_Display_Info.FLOOR_Device.lock_flage)		//处于锁定状态，长按可解锁
				{
					Oled_Display_Info.FLOOR_Device.lock_flage = 0;
					Control_ChildLock_Onoff(FLOOR_HEATING,Oled_Display_Info.FLOOR_Device.lock_flage);		
				}
				else{											//处于非锁定状态，长按可上锁
					Oled_Display_Info.FLOOR_Device.lock_flage = 1;
					Control_ChildLock_Onoff(FLOOR_HEATING,Oled_Display_Info.FLOOR_Device.lock_flage);
				}
			}
			else if(Oled_Display_Info.screen_page == FAN)
			{
				if(Oled_Display_Info.FAN_Device.on_off == 0)     //关机模式才能操作温度校准
				{
					u16 display_data = 0;
					delay_operate_calibrate_temper_Task_Start();
					sKey_Operation[2].operate_calibrate_temper = 1;
					
					sKey_Operation[2].operate_calibrate_temp =  Oled_Display_Info.FAN_Device.correct_temperature;
					display_data =  Oled_Display_Info.FAN_Device.real_temperature;
					Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					return;
				}
					
				if(Oled_Display_Info.FAN_Device.lock_flage)		//处于锁定状态，长按可解锁
				{
					Oled_Display_Info.FAN_Device.lock_flage = 0;
					Control_ChildLock_Onoff(FAN,Oled_Display_Info.FAN_Device.lock_flage);	
				}
				else{											//处于非锁定状态，长按可上锁
					Oled_Display_Info.FAN_Device.lock_flage = 1;
					Control_ChildLock_Onoff(FAN,Oled_Display_Info.FAN_Device.lock_flage);
				}
			}
		}
			break;
		case ButtonLongUpEvent:
			break;
		default:
			break;
	}
}
static void KEY4_Botton_Process_Handler(u8 KeyPressEvent)
{

	switch(KeyPressEvent)
	{
		case ButtonShortEvent:
		{
			u8 bind_device_len = 0;
			u8 device1_type = 0;
			u8 device2_type = 0;
			if(Oled_Display_Info.binding_device == 0)        					//未绑定
				return;
			delay_confirm_system_control(0);   
			bind_device_len = ((Oled_Display_Info.binding_device&0xF0)>>4);
			device1_type = Oled_Display_Info.binding_device&0x03;
			device2_type = ((Oled_Display_Info.binding_device&0x0C)>>2);
			if(bind_device_len == 1)
			{
				if(Oled_Display_Info.screen_page == Oled_Display_Info.device_type)
				{
					if(device1_type !=0)
						Oled_Display_Info.screen_page = device1_type;
					else
						Oled_Display_Info.screen_page = device2_type;
				}
				else
					Oled_Display_Info.screen_page = Oled_Display_Info.device_type;
			}
			else if(bind_device_len == 2)
			{
				if(Oled_Display_Info.screen_page == Oled_Display_Info.device_type)
					Oled_Display_Info.screen_page = device1_type;
				else if(Oled_Display_Info.screen_page == device1_type)
					Oled_Display_Info.screen_page = device2_type;
				else
					Oled_Display_Info.screen_page = Oled_Display_Info.device_type;
			}
			//显示所有的界面
			display_current_page();
		}	
			break;
		default:
			break;
	}
}
static void KEY5_Botton_Process_Handler(u8 KeyPressEvent)
{
	switch(KeyPressEvent)
	{
		case ButtonShortEvent:
		{
			if(Oled_Display_Info.screen_page == AIR_CONDITION)
			{
				if(!Oled_Display_Info.Air_Device.on_off )     //关机情况下不允许调节
				{
					if(sKey_Operation[0].operate_calibrate_temper)
					{
						u16 display_data = 0;
						delay_operate_calibrate_temper_Task_Start();
						if(sKey_Operation[0].operate_calibrate_temp< 90)
							sKey_Operation[0].operate_calibrate_temp +=5;
						
						display_data =  Oled_Display_Info.Air_Device.real_temperature -Oled_Display_Info.Air_Device.correct_temperature + sKey_Operation[0].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					}
					break;  
				}					
					
				if(gKey_Press_Info.adjust_fan_speed_status == 1)
				{
					u8  next_speed = 0;
					if(Oled_Display_Info.Air_Device.air_cond_type == 2)   //线控器支持七档+自动调节
					{
//						next_speed = Get_NextOne_By_Current_Speed_Level(1,Oled_Display_Info.Air_Device.wind_speed,1);
//						display_wind_speed(next_speed,1);	
//						Oled_Display_Info.Air_Device.wind_speed = next_speed;
//						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
						
						if(Oled_Display_Info.Air_Device.system_type != SYSTEM_MODE_DRY)										//美的空调，除湿模式下改变风速无效
						{
							next_speed = Get_NextOne_By_Current_Speed_Level(1,Oled_Display_Info.Air_Device.wind_speed,0);
							display_wind_speed(next_speed,0);
							
							Oled_Display_Info.Air_Device.wind_speed = next_speed;
							#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
								delay_control_fan_speed_start();
							#else
								state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
							#endif
							//Control_AIR_CONDITION_By_RS485(AIR_CMD_FAN_SPEED,next_speed);		//控制空调风速
						}
					}
//					else if(Oled_Display_Info.Air_Device.air_cond_type == 1)   //风机盘管，新风只支持3档+自动调节
//					{
//						if(Oled_Display_Info.Air_Device.system_type != SYSTEM_MODE_DRY)										//美的空调，除湿模式下改变风速无效
//						{
//							next_speed = Get_NextOne_By_Current_Speed_Level(1,Oled_Display_Info.Air_Device.wind_speed,0);
//							display_wind_speed(next_speed,0);
//							//Oled_Display_Info.Air_Device.wind_speed = next_speed;
//							
//							//Control_AIR_CONDITION_By_RS485(AIR_CMD_FAN_SPEED,Oled_Display_Info.Air_Device.wind_speed);		//控制空调风速
//							
//							state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
//						}
//					}
					break; 
				}
//				else if(gKey_Press_Info.adjust_fan_speed_status == 2)
//				{
//					u8 speed_direct = 0;
//					speed_direct = Get_NextOne_By_Current_wind_direct(1,Oled_Display_Info.Air_Device.air_wind_direct);
//					switch(speed_direct)		   //显示当前风向
//					{
//						case 0:
//							display_wind_direct(1,0,0);
//							break;
//						case 1:
//							display_wind_direct(0,1,0);
//							break;
//						case 2:
//							display_wind_direct(0,0,1);
//							break;
//						default:
//							break;
//					}
//					Control_AIR_CONDITION_By_RS485(AIR_CMD_FAN_DIRECT,speed_direct);		//控制空调风向	
//					break; 
//				}
				if(sKey_Operation[0].operate_delay_off_status)
				{
					sKey_Operation[0].record_adjust_delay_off += 5;
					if(sKey_Operation[0].record_adjust_delay_off >= 240)
						sKey_Operation[0].record_adjust_delay_off = 240;
					
					Delay_Power_Off_Control(ON,NULL,NULL,sKey_Operation[0].record_adjust_delay_off);	
					Delay_Power_Off_Control(FLASHING,15000,500,sKey_Operation[0].record_adjust_delay_off);	
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
					break; 
				}
				
				if(Oled_Display_Info.Air_Device.system_type != SYSTEM_MODE_AIR)	
				{
					/**************************************************
					调节设置温度
					**************************************************/
					Oled_Display_Info.Air_Device.set_temperature += 5;
					if(Oled_Display_Info.Air_Device.set_temperature >= 300)
						Oled_Display_Info.Air_Device.set_temperature = 300;
					display_set_temp(0,Oled_Display_Info.Air_Device.set_temperature,0);       //显示设置温度     
					
					#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
						delay_control_set_temp_start();
					#else
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
					#endif
					 
				}
			}
			else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
			{
				if(!Oled_Display_Info.FLOOR_Device.on_off )     //关机情况下不允许调节
				{
					if(sKey_Operation[1].operate_calibrate_temper)
					{
						u16 display_data = 0;
						delay_operate_calibrate_temper_Task_Start();
						if(sKey_Operation[1].operate_calibrate_temp< 90)
							sKey_Operation[1].operate_calibrate_temp +=5;

						display_data =  Oled_Display_Info.FLOOR_Device.real_temperature-Oled_Display_Info.FLOOR_Device.correct_temperature + sKey_Operation[1].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					}
					break;  
				}					
					
				if(sKey_Operation[1].operate_delay_off_status)
				{
					
					sKey_Operation[1].record_adjust_delay_off += 5;
					if(sKey_Operation[1].record_adjust_delay_off >= 240)
						sKey_Operation[1].record_adjust_delay_off = 240;
					Delay_Power_Off_Control(ON,NULL,NULL,sKey_Operation[1].record_adjust_delay_off);	
					Delay_Power_Off_Control(FLASHING,15000,500,sKey_Operation[1].record_adjust_delay_off);
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
					break; 
				}
				/**************************************************
				调节设置温度
				**************************************************/
				if(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_AUTO)
				{
					LCDShowTemp_state_t.LCD_place = SYSTEM_AUTO_CHAR_DISPLAY;	
					LCDShowTemp_state_t.LCD_state = ON;
					LcdShowCTR(LCDShowTemp_state_t);
					
					LCDShowTemp_state_t.LCD_state = FLASHING;
					LCDShowTemp_state_t.LCD_display_count  = 2;								//15s
					LCDShowTemp_state_t.LCD_display_timer  = 20;								
					LcdShowCTR(LCDShowTemp_state_t);
				}
				else{
					Oled_Display_Info.FLOOR_Device.set_temperature += 5;
					if(Oled_Display_Info.FLOOR_Device.set_temperature >= 300)
						Oled_Display_Info.FLOOR_Device.set_temperature = 300;
					display_set_temp(0,Oled_Display_Info.FLOOR_Device.set_temperature,0);       //显示设置温度
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);	//状态改变通知
				}
			}
			else if(Oled_Display_Info.screen_page == FAN)
			{
				if(!Oled_Display_Info.FAN_Device.on_off )     //关机情况下不允许调节
				{
					if(sKey_Operation[2].operate_calibrate_temper)
					{
						u16 display_data = 0;
						delay_operate_calibrate_temper_Task_Start();
						if(sKey_Operation[2].operate_calibrate_temp< 90)
							sKey_Operation[2].operate_calibrate_temp +=5;
														
						display_data =  Oled_Display_Info.FAN_Device.real_temperature- Oled_Display_Info.FAN_Device.correct_temperature + sKey_Operation[2].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					}
					break;  
				}					
				if(gKey_Press_Info.adjust_fan_speed_status == 1)
				{
					u8  next_speed = 0;
					
					next_speed = Get_NextOne_By_Current_Speed_Level(1,Oled_Display_Info.FAN_Device.wind_speed,0);
					display_wind_speed(next_speed,0);	
					
					Oled_Display_Info.FAN_Device.wind_speed = next_speed;
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);	//状态改变通知
					break; 
				}
				if(sKey_Operation[2].operate_delay_off_status)
				{
					sKey_Operation[2].record_adjust_delay_off += 5;
					if(sKey_Operation[2].record_adjust_delay_off >= 240)
						sKey_Operation[2].record_adjust_delay_off = 240;
						
					Delay_Power_Off_Control(ON,NULL,NULL,sKey_Operation[2].record_adjust_delay_off);	
					Delay_Power_Off_Control(FLASHING,15000,500,sKey_Operation[2].record_adjust_delay_off);
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
					break; 
				}
			}
			
			
		}
			break;
//		case ButtonLongEvent:
//			break;
//		case ButtonLongUpEvent:
//			break;
		default:
			break;
	}


}

static void KEY6_Botton_Process_Handler(u8 KeyPressEvent)
{
	switch(KeyPressEvent)
	{
		case ButtonShortEvent:
		{
			if(Oled_Display_Info.screen_page == AIR_CONDITION)
			{
				if(!Oled_Display_Info.Air_Device.on_off )     //关机情况下不允许调节
				{
					if(sKey_Operation[0].operate_calibrate_temper)
					{
						u16 display_data = 0;
						delay_operate_calibrate_temper_Task_Start();
						
						if(sKey_Operation[0].operate_calibrate_temp> -90)
							sKey_Operation[0].operate_calibrate_temp -=5;
						
						display_data =  Oled_Display_Info.Air_Device.real_temperature- Oled_Display_Info.Air_Device.correct_temperature + sKey_Operation[0].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					}
					break;  
				}					
					
				if(gKey_Press_Info.adjust_fan_speed_status == 1)
				{
					u8  next_speed = 0;
					if(Oled_Display_Info.Air_Device.air_cond_type == 2)   //线控器支持七档+自动调节
					{
//						next_speed = Get_NextOne_By_Current_Speed_Level(0,Oled_Display_Info.Air_Device.wind_speed,1);
//						display_wind_speed(next_speed,1);	
						
						if(Oled_Display_Info.Air_Device.system_type != SYSTEM_MODE_DRY)										//美的空调，除湿模式下改变风速无效
						{
							next_speed = Get_NextOne_By_Current_Speed_Level(0,Oled_Display_Info.Air_Device.wind_speed,0);
							display_wind_speed(next_speed,0);
							Oled_Display_Info.Air_Device.wind_speed = next_speed;
							#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
								delay_control_fan_speed_start();
							#else
								state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
							#endif
						}
					}
//					else if(Oled_Display_Info.Air_Device.air_cond_type == 1)   //风机盘管，新风只支持3档+自动调节
//					{
//						next_speed = Get_NextOne_By_Current_Speed_Level(0,Oled_Display_Info.Air_Device.wind_speed,0);
//						display_wind_speed(next_speed,0);	
//						Oled_Display_Info.Air_Device.wind_speed = next_speed;
//					
//						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知	
//					}
					
					break;
				}
//				else if(gKey_Press_Info.adjust_fan_speed_status == 2)
//				{
//					u8 speed_direct = 0;
//					speed_direct = Get_NextOne_By_Current_wind_direct(0,Oled_Display_Info.Air_Device.air_wind_direct);
//					switch(speed_direct)		   //显示当前风向
//					{
//						case 0:
//							display_wind_direct(1,0,0);
//							break;
//						case 1:
//							display_wind_direct(0,1,0);
//							break;
//						case 2:
//							display_wind_direct(0,0,1);
//							break;
//						default:
//							break;
//					}
//					Oled_Display_Info.Air_Device.air_wind_direct = speed_direct;
//					
//					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知	
//					break;
//				}				

				if(sKey_Operation[0].operate_delay_off_status)
				{
					if(sKey_Operation[0].record_adjust_delay_off >=5)
						sKey_Operation[0].record_adjust_delay_off -= 5;	
					Delay_Power_Off_Control(ON,15000,500,sKey_Operation[0].record_adjust_delay_off);
					Delay_Power_Off_Control(FLASHING,15000,500,sKey_Operation[0].record_adjust_delay_off);
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
					break;					
				}
				if(Oled_Display_Info.Air_Device.system_type != SYSTEM_MODE_AIR)	
				{
					Oled_Display_Info.Air_Device.set_temperature -= 5;
					if(Oled_Display_Info.Air_Device.set_temperature <= 160)					//美的空调温度调节范围 17度 - 30度
						Oled_Display_Info.Air_Device.set_temperature = 160;
					display_set_temp(0,Oled_Display_Info.Air_Device.set_temperature,0);       //显示设置温度
						   
					#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
						delay_control_set_temp_start();
					#else
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
					#endif
				}
			}
			else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
			{
				if(!Oled_Display_Info.FLOOR_Device.on_off )     //关机情况下不允许调节
				{
					if(sKey_Operation[1].operate_calibrate_temper)
					{
						u16 display_data = 1;
						delay_operate_calibrate_temper_Task_Start();
						
						if(sKey_Operation[1].operate_calibrate_temp> -90)
							sKey_Operation[1].operate_calibrate_temp -=5;
						
						display_data =  Oled_Display_Info.FLOOR_Device.real_temperature- Oled_Display_Info.FLOOR_Device.correct_temperature + sKey_Operation[1].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					}
					break;  
				}					

				if(sKey_Operation[1].operate_delay_off_status)
				{
					if(sKey_Operation[1].record_adjust_delay_off >=5)
						sKey_Operation[1].record_adjust_delay_off -= 5;
						
					Delay_Power_Off_Control(ON,15000,500,sKey_Operation[1].record_adjust_delay_off);
					Delay_Power_Off_Control(FLASHING,15000,500,sKey_Operation[1].record_adjust_delay_off);
					
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
					break; 
				}
				if(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_AUTO)
				{
					LCDShowTemp_state_t.LCD_place = SYSTEM_AUTO_CHAR_DISPLAY;	
					LCDShowTemp_state_t.LCD_state = ON;
					LcdShowCTR(LCDShowTemp_state_t);
					
					LCDShowTemp_state_t.LCD_state = FLASHING;
					LCDShowTemp_state_t.LCD_display_count  = 2;								//15s
					LCDShowTemp_state_t.LCD_display_timer  = 20;								
					LcdShowCTR(LCDShowTemp_state_t);
				}else{
					Oled_Display_Info.FLOOR_Device.set_temperature -= 5;
					if(Oled_Display_Info.FLOOR_Device.set_temperature <= 160)
						Oled_Display_Info.FLOOR_Device.set_temperature = 160;
					display_set_temp(0,Oled_Display_Info.FLOOR_Device.set_temperature,0);       //显示设置温度
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);	//状态改变通知	
				}

			}
			else if(Oled_Display_Info.screen_page == FAN)
			{
				if(!Oled_Display_Info.FAN_Device.on_off )     //关机情况下不允许调节
				{
					if(sKey_Operation[2].operate_calibrate_temper)
					{
						u16 display_data = 0;
						delay_operate_calibrate_temper_Task_Start();
						
						if(sKey_Operation[2].operate_calibrate_temp> -90)
							sKey_Operation[2].operate_calibrate_temp -=5;
						
						display_data =  Oled_Display_Info.FAN_Device.real_temperature- Oled_Display_Info.FAN_Device.correct_temperature + sKey_Operation[2].operate_calibrate_temp;
						Calib_Temp_Control(ON,0,0,display_data);
						Calib_Temp_Control(FLASHING,15*1000,800,display_data);
					}
					break;  
				}					
					
				if(gKey_Press_Info.adjust_fan_speed_status == 1)
				{
					u8  next_speed = 0;
					next_speed = Get_NextOne_By_Current_Speed_Level(0,Oled_Display_Info.FAN_Device.wind_speed,0);
					display_wind_speed(next_speed,0);	
					
					Oled_Display_Info.FAN_Device.wind_speed = next_speed;
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);	//状态改变通知
					break; 
				}
				
				if(sKey_Operation[2].operate_delay_off_status)
				{
					if(sKey_Operation[2].record_adjust_delay_off >=5)
						sKey_Operation[2].record_adjust_delay_off -= 5;
						
					Delay_Power_Off_Control(ON,15000,500,sKey_Operation[2].record_adjust_delay_off);
					Delay_Power_Off_Control(FLASHING,15000,500,sKey_Operation[2].record_adjust_delay_off);	
					delay_operate_delay_off_Task_Start();											//开启15s倒计时
				}

			}
		
		}
			break;
		case ButtonLongEvent:
		{
			u8 arg[2] = {0};
			static u8 firstLongPressFlg = 0;
			//15min前老化不能操作组网
			if(Oled_Display_Info.aging_test_flag != 2)   
				break;
			if(Oled_Display_Info.net_work_flage == OUT_LINE){
				arg[0] = 1;																  //操作入网
				Send_Device_Data(0,_OPCODE_SET_NET_STATE,arg,1);
				//printf("join network\r\n");
			}
			else{
				if( ((Oled_Display_Info.local_timer - sKey_Operation[0].operate_last_timer) <=10*1000)&&firstLongPressFlg )
				{
					arg[0] = 0;																  //操作离网
					Send_Device_Data(0,_OPCODE_SET_NET_STATE,arg,1);			
					//printf("leave network\r\n");
				}
				else
				{
					firstLongPressFlg = 1;
					//闪烁一次，表示短按通过
					LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
					LCDShowTemp_state_t.LCD_state = ON;
					LcdShowCTR(LCDShowTemp_state_t);
					
					LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
					LCDShowTemp_state_t.LCD_state = FLASHING;
					LCDShowTemp_state_t.LCD_display_count = 2;
					LCDShowTemp_state_t.LCD_display_timer = 20;
					LcdShowCTR(LCDShowTemp_state_t);
				}
			}
			
		}
			break;
		case ButtonLongUpEvent:
		{
			sKey_Operation[0].operate_last_timer = Oled_Display_Info.local_timer;
		}
			break;
		default:
			break;
	}

}

/*********************************************************
查询下一个风速
plus_or_sub  代表是增加还是减少   1，代表增加，0代表减小
wind_direct   表示当前的风向
return 返回下个风向
**********************************************************/
//u8 Get_NextOne_By_Current_wind_direct(u8 plus_or_sub,u8 wind_direct)
//{
//	u8 next_direct = 0;
//	switch(wind_direct)
//	{
//		case 0:
//		{
//			((plus_or_sub) ? (next_direct = 1):(next_direct = 2));
//		}
//			break;
//		case 1:
//		{
//			((plus_or_sub) ? (next_direct = 2):(next_direct = 0));
//		}
//			break;
//		case 2:
//		{
//			((plus_or_sub) ? (next_direct = 0):(next_direct =1));
//		}
//			break;
//	}
//	return next_direct;
//}
/*********************************************************
查询下一个风速
plus_or_sub  代表是增加还是减少   1，代表调高，0代表调小
fan_speed   表示当前的风速等级
type_support   表示支持风速等级   0 ：代表支持1，2，3，5 ， 1：代表支持 0，1，2，3，5，7，8，9
return 返回下个个风速等级
**********************************************************/
u8 Get_NextOne_By_Current_Speed_Level(u8 plus_or_sub,u8 fan_speed,u8 type_support)
{
	u8 next_level = 0;
	switch(fan_speed)
	{
		case 0:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 1):(next_level = 2));
			}
			else
			{
				((type_support) ? (next_level = 5):(next_level = 5));
			}
		}
			break;
		case 1:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 7):(next_level = 2));
			}
			else
			{
				((type_support) ? (next_level = 0):(next_level = 5));
			}
		}
			break;
		case 2:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 8):(next_level = 3));
			}
			else
			{
				((type_support) ? (next_level = 7):(next_level = 1));
			}
		}
			break;
		case 3:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 9):(next_level = 5));
			}
			else
			{
				((type_support) ? (next_level = 8):(next_level = 2));
			}
		}
			break;
		case 5:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 0):(next_level = 1));
			}
			else
			{
				((type_support) ? (next_level = 9):(next_level = 3));
			}
		}
			break;
		case 7:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 2):(next_level = 2));
			}
			else
			{
				((type_support) ? (next_level = 1):(next_level = 5));
			}
		
		}
			break;
		case 8:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 3):(next_level = 2));
			}
			else
			{
				((type_support) ? (next_level = 2):(next_level = 5));
			}
		
		}
			break;
		case 9:
		{
			if(plus_or_sub)
			{
				((type_support) ? (next_level = 5):(next_level = 2));
			}
			else
			{
				((type_support) ? (next_level = 3):(next_level = 5));
			}
		}
			break;
	}
	return next_level;
}
#if ( (DEV_TYPE == 1) &&(DEVICE_TYPE_AIR_CONDITION ==1)) ||(DEVICE_TYPE_FLOOR_HEATING) ||(DEVICE_TYPE_FAN)

/******************************************
阀门开关控制（K1,K2,K3,K4,K5）
para :
	control_relay_bits   : bit0-bit5分别代表继电器1-6
	onoff_bits：		   bit0-bit5分别代表继电器1-6的状态
*******************************************/
void Relay_Action(u8 control_relay_bits,u8 onoff_bits)
{
	u8 i = 0;
	for(i = 0;i<6;i++)
	{
		if(control_relay_bits &(1<<i))
		{
			if(onoff_bits &(1<<i))
			{
				Tap_Control.save_tap_status[i]  = 1;
			}
			else{
				Tap_Control.save_tap_status[i]  = 0;
			}
		}
	}
	Save_Tap_Switch();
}
/******************************************
阀门开关状态改变保存（K1,K2,K3,K4,K5）
*******************************************/
void  Save_Tap_Switch(void)
{
    u8 set = 0;
    for(set = 0;set < 6; set ++)
    {				
        if (Tap_Control.save_tap_status[set] == 1)   //开
        {
            Tap_Control.tap_to_do[set] = 2;
        }
        else if (Tap_Control.save_tap_status[set] == 0)  //关
        {		 
            Tap_Control.tap_to_do[set] = 1;			 
        }			
    } 	
}


/******************************************
阀门开关状态轮询
*******************************************/
void Tap_Switch(void)
{
    if (Tap_Control.tap_end_flage == 0)
    {	
        if (Tap_Control.tap_to_do[Tap_Control.set_tap] != 0)
        {
           Tap_Control. tap_end_flage = 1;			
            EINT_start();	
        }
    }

}
static void Tap_Status_Scan_Task_Start(void)
{
	task_comps[16].task_switch = SWITCH_ON; 
}
static void Tap_Status_Scan_Task_Stop(void)
{
	task_comps[16].task_switch = SWITCH_OFF; 
}
/*
风阀初始化
*/
void Tap_Init(void)
{
	#if DEVICE_TYPE_FLOOR_HEATING
    if(Oled_Display_Info.FLOOR_Device.on_off ==1)  //开机状态
    {	
		if(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_MANUAL)
        {
			if( Oled_Display_Info.FLOOR_Device.set_temperature - Oled_Display_Info.FLOOR_Device.real_temperature > 20)
			{
				Relay_Action(0x01,0x01);																//继电器吸合	
			}
			else if (Oled_Display_Info.FLOOR_Device.real_temperature - Oled_Display_Info.FLOOR_Device.set_temperature > 10)
			{
				Relay_Action(0x01,0x00);																//继电器断开		

			}								 			 
        }
		else if(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_AUTO)	
		{
			if( 260 - Oled_Display_Info.FLOOR_Device.real_temperature > 20)
			{
				Relay_Action(0x01,0x01);																//继电器吸合	
			}
			else if (Oled_Display_Info.FLOOR_Device.real_temperature -260 > 10)
			{
				Relay_Action(0x01,0x00);																//继电器断开		

			}	
		}			
    }
	#elif DEVICE_TYPE_FAN
	Fan_Speed_Control(Oled_Display_Info.FAN_Device.wind_speed);  //默认打开
	
	if((Oled_Display_Info.FAN_Device.on_off ==1)&&(Oled_Display_Info.aging_test_flag != 1))  //开机状态且没处于15min-4h老化期间
    {	 
		Fan_PassbyONOFF_By_Mode_Trans(Oled_Display_Info.FAN_Device.system_type,1);
		Fan_Speed_Control(Oled_Display_Info.FAN_Device.wind_speed);
	}
	#endif
}


/******************************************
//新风模式切换，打开关闭旁通模式
*******************************************/
void Fan_PassbyONOFF_By_Mode_Trans(u8 system_mdoe,u8 reset_count_time)
{
	if(system_mdoe == SYSTEM_MODE_MANUAL)
	{
		Relay_Action(0x08,0x00);
		Tap_Status_Scan_Task_Stop();
	}
	else if(system_mdoe == SYSTEM_MODE_ROLL)
	{
		//开启状态扫描事件
		Tap_Status_Scan_Task_Start();
		Relay_Action(0x08,0x08);
	}
	if(reset_count_time)
	{
		auto_time = 0;			
        auto_type = 0;
	}
}
/******************************************
//新风风速切换
*******************************************/
void Fan_Speed_Control(u8 wind_speed)
{
	switch(wind_speed)
	{
		//K3
		case WIND_SPEED_LOW:
		{
			Relay_Action(0x07,0x04);
		}
			break;
		//K2
		case WIND_SPEED_MID:
		{
			Relay_Action(0x07,0x02);
		}
			break;
		//K1
		case WIND_SPEED_HIGH:
		{
			Relay_Action(0x07,0x01);
		}
			break;
	}
}
#endif
/******************************************
//风阀 冷热阀 轮训，根据温度开启关闭
*******************************************/
void Tap_Status_Scan(void)
{
	#if DEVICE_TYPE_FLOOR_HEATING
    if((Oled_Display_Info.FLOOR_Device.on_off ==1)&&(Oled_Display_Info.aging_test_flag != 1))  //开机状态且没处于15min-4h老化期间
    {	 
        if(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_MANUAL)
        {
			if( Oled_Display_Info.FLOOR_Device.set_temperature - Oled_Display_Info.FLOOR_Device.real_temperature > 20)
			{
				Relay_Action(0x01,0x01);																//继电器吸合	
			}
			else if (Oled_Display_Info.FLOOR_Device.real_temperature - Oled_Display_Info.FLOOR_Device.set_temperature > 10)
			{
				Relay_Action(0x01,0x00);																//继电器断开		

			}								 			 
        }
		else if(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_AUTO)	
		{
			if( 260 - Oled_Display_Info.FLOOR_Device.real_temperature > 20)
			{
				Relay_Action(0x01,0x01);																//继电器吸合	
			}
			else if (Oled_Display_Info.FLOOR_Device.real_temperature -260 > 10)
			{
				Relay_Action(0x01,0x00);																//继电器断开		

			}	
		}			
    }
	#elif DEVICE_TYPE_FAN
	if((Oled_Display_Info.FAN_Device.on_off ==1)&&(Oled_Display_Info.aging_test_flag != 1))  //开机状态且没处于15min-4h老化期间
    {	 
		if(Oled_Display_Info.FAN_Device.system_type != SYSTEM_MODE_ROLL)
			return;
        auto_time ++;
        if(auto_time >= 20)
        {
            auto_time = 0;			
            auto_type ++;
            if (auto_type > 2)
            {
                auto_type = 0;
            }
        }
        switch(auto_type)
        {
            case  0:   //旁通开启20    K4打开
            {
               Relay_Action(0x08,0x08);
                break;
            }					 
            case  1:  //旁通关闭20
            {
                Relay_Action(0x08,0x00);					 
                break;
            }	
            case  2:  //旁通关闭20
            {
                Relay_Action(0x08,0x00);								 
                break;
            }
            default :
            {
                break;    
            }            
        }	
    }
	#endif
}
/******************************************
//童锁操作
*******************************************/
void Control_ChildLock_Onoff(u8 device_type,u8 onoff)
{
	if(device_type == AIR_CONDITION)
	{
		LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;	
		if(onoff)																	//处于锁定状态，长按可解锁
		{
			Oled_Display_Info.Air_Device.lock_flage = 1;
	
			LCDShowTemp_state_t.LCD_state = ON;	
				
		}
		else{	
			Oled_Display_Info.Air_Device.lock_flage = 0;
			
			LCDShowTemp_state_t.LCD_state = OFF;	
		}
		LcdShowCTR(LCDShowTemp_state_t);
		
		state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	
	}
	else if(device_type == FLOOR_HEATING)
	{
		LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;	
		if(onoff)																	//处于锁定状态，长按可解锁
		{
			Oled_Display_Info.FLOOR_Device.lock_flage = 1;
			LCDShowTemp_state_t.LCD_state = ON;		
		}
		else{	
			Oled_Display_Info.FLOOR_Device.lock_flage = 0;	
			LCDShowTemp_state_t.LCD_state = OFF;	
		}
		LcdShowCTR(LCDShowTemp_state_t);
		
		state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
	}
	else if(device_type == FAN)
	{
		LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;	
		if(onoff)																	//处于锁定状态，长按可解锁
		{
			Oled_Display_Info.FAN_Device.lock_flage = 1;
			LCDShowTemp_state_t.LCD_state = ON;	
				
		}
		else{	
			Oled_Display_Info.FAN_Device.lock_flage = 0;		
			LCDShowTemp_state_t.LCD_state = OFF;		
		}
		LcdShowCTR(LCDShowTemp_state_t);
		
		state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
	}
	save_data();
}
