#include <stdio.h>
#include "mini58series.h"
#include "BL55072A.h"
#include "display_common.h"
#include "Key.h"


extern  Lcd_Status_Info_t  LCDShowTemp_state_t;
#if DEVICE_TYPE_AIR_CONDITION
	OLED_ALL_DSD Oled_Display_Info = { 1,0,1,0,0,0x11,0,0,0,0,{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},{1,0,0,0,260,0,3,0,5,0,2,1,0,0,3000,0,0xff,0xff,0},{1,0,0,0,260,0,2,0,DEV_TYPE,0,0,0},{1,0,0,0,0,2,1,0,0,0,3000,0}};
#elif  DEVICE_TYPE_FLOOR_HEATING
	OLED_ALL_DSD Oled_Display_Info = { 2,0,2,0,0,0x11,0,0,0,0,{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},{1,0,0,0,260,0,3,0,5,0,2,1,0,0,3000,0,0xff,0xff,0},{1,0,0,0,260,0,2,0,DEV_TYPE,0,0,0},{1,0,0,0,0,2,1,0,0,0,3000,0}};
#elif  DEVICE_TYPE_FAN
	OLED_ALL_DSD Oled_Display_Info = { 3,0,3,0,0,0x12,0,0,0,0,{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},{1,0,0,0,260,0,3,0,5,0,2,1,0,0,3000,0,0xff,0xff,0},{1,0,0,0,260,0,2,0,0,0,0,0},{1,0,0,0,0,2,1,0,0,0,3000,0}};
#endif
Key_Operation_Status  gKey_Press_Info = {0};
//	.device_type 		= 1,  //AIR_CONDITION
//	.net_work_flage 	= OUT_LINE,  //   IN_LINE
//	.screen_page        = 1,
//	.aging_test_flag    = 0,
//	.local_timer        = 0,
//	.mcu_Version		= 0x10;
//	.zigbee_Version		= 0;
//	.binding_device		= 0;	//0 未绑定  1，绑定空调，2，地暖，3，绑定新风
//  .is_dispaly_cur_temp = 0;	//是否显示当前温度
//	.Air_Device         ={
//		.onoff  				= 1,
//		.power_off_time  		= 0,
//		.power_off_flage 		= 0,
//		.real_temperature		= 0,
//		.set_temperature		= 260,
//		.correct_temperature	= 0,
//		.system_type			= 3, //SYSTEM_MODE_COOLING
//		.operation_mode			= 0,
//		.wind_speed				= 5,
//		.lock_flage				= 0,
//		.air_cond_type			= 2,//线控器
//		.air_wind_direct		= 1,//风向 中
//		.error					= 0,
//		.screen_save_time		= 0,
//		.filter_wash_time		= 4000;
//		.no_disturb_mode		= 0;
//	}
//	.FLOOR_Device         ={
//		.onoff  				= 1,
//		.power_off_time  		= 0,
//		.power_off_flage 		= 0,
//		.real_temperature		= 0,
//		.set_temperature		= 260,
//		.correct_temperature	= 0,
//		.system_type			= 2, //SYSTEM_MODE_MANUAL 2 手动，1 自动
//		.lock_flage				= 0,
//		.floor_heating_type		= 1,//地暖类型   1.水地暖  0，电地暖
//		.error					= 0,
//		.screen_save_time		= 0,
//		.no_disturb_mode		= 0;
//	}
//	.FAN_Device         ={
//		.onoff  				= 1,
//		.power_off_time  		= 0,
//		.power_off_flage 		= 0,
//		.system_type			= 2, //2 手动，10 循环
//		.wind_speed				= 1, //风速    1 低 2 中 3 高，5，自动 
//		.lock_flage				= 0,
//		.error					= 0,
//		.screen_save_time		= 0,
//		.filter_wash_time		= 3000;
//		.no_disturb_mode		= 0;
//	}
//};
NET_INDICATOR   g_NetOptIndicator[7] = {0,0,0,0,0,0,0} ;

/*************************************************
				显示延时关机时间
***************************************************/
void Display_poweroff_time(u8 display_time)
{
	LCDShowTemp_state_t.LCD_place = DELAY_OFF_TIME_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = ON;
	LCDShowTemp_state_t.LCD_code_data = display_time;
	LcdShowCTR(LCDShowTemp_state_t);

	//显示闹钟
	LCDShowTemp_state_t.LCD_place = SETTING_TIMER_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = ON;
	LcdShowCTR(LCDShowTemp_state_t);
	//显示H图标
	LCDShowTemp_state_t.LCD_place = H_CHAR_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = ON;
	LcdShowCTR(LCDShowTemp_state_t);
	
	//显示设定时长字符图标
	LCDShowTemp_state_t.LCD_place = SETTING_TIMER_CHAR_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = ON;
	LcdShowCTR(LCDShowTemp_state_t);
	
	LCDShowTemp_state_t.LCD_place = UPPER_TEMPER_UNIT_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = OFF;
	LcdShowCTR(LCDShowTemp_state_t);
}
/*************************************************
				显示当前温度
***************************************************/
void Display_Current_Temper(u16 temper)
{
	LCDShowTemp_state_t.LCD_place = DELAY_OFF_TIME_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = ON;
	LCDShowTemp_state_t.LCD_code_data = temper;
	LcdShowCTR(LCDShowTemp_state_t);

	//显示摄氏度℃
	LCDShowTemp_state_t.LCD_place = UPPER_TEMPER_UNIT_DISPLAY;		
	LCDShowTemp_state_t.LCD_state = ON;
	LcdShowCTR(LCDShowTemp_state_t);
}
/*************************************************
				显示中间三个数据
***************************************************/
static void Display_Middle_Digtal(u8 control_bits,int data )
{
	static u8 temp[3] = {0};
	static u8 is_dispaly[3] = {0};
	memset(temp,0,3);
	memset(is_dispaly,0,3);
	if(control_bits == 0x07)			//显示三个字段
	{
		temp[0] = data / 100;
		temp[1] = (data / 10) % 10;
		temp[2] =data % 10;	
		is_dispaly[0] = is_dispaly[1] = is_dispaly[2]  = 1;
	}
	else if(control_bits == 0x02)		//显示中间字段
	{
		temp[1] = data % 10;
		is_dispaly[0] = is_dispaly[2]  = 0;
		is_dispaly[1] = 1;
	}
	else if(control_bits == 0x03)
	{
		temp[1] = data/10;
		temp[2] = data % 10;
		is_dispaly[1] = is_dispaly[2]  = 1;
		is_dispaly[0] = 0;
	}
	LCDShowTemp_state_t.LCD_place = SET_MIDDLE_DIGITRON_DISPLAY_01;
	LCDShowTemp_state_t.LCD_code_data = temp[0];
	LCDShowTemp_state_t.LCD_state = is_dispaly[0];
	LcdShowCTR(LCDShowTemp_state_t);


	LCDShowTemp_state_t.LCD_place = SET_MIDDLE_DIGITRON_DISPLAY_02;
	LCDShowTemp_state_t.LCD_code_data = temp[1];
	LCDShowTemp_state_t.LCD_state = is_dispaly[1];
	LcdShowCTR(LCDShowTemp_state_t);

	LCDShowTemp_state_t.LCD_place = SET_MIDDLE_DIGITRON_DISPLAY_03;
	LCDShowTemp_state_t.LCD_code_data = temp[2];		
	LCDShowTemp_state_t.LCD_state = is_dispaly[2];
	LcdShowCTR(LCDShowTemp_state_t);

}

/*************************************************
				显示外设故障
***************************************************/
void  display_error(u8 error_value)
{
    LCDShowTemp_state_t.LCD_place = SET_UPPER_DIGITRON_DISPLAY_01;
    LCDShowTemp_state_t.LCD_code_data = 14;									//E
    LCDShowTemp_state_t.LCD_state = ON;
    LcdShowCTR(LCDShowTemp_state_t);		

    LCDShowTemp_state_t.LCD_place = SET_UPPER_DIGITRON_DISPLAY_02;
    LCDShowTemp_state_t.LCD_code_data = 17;									//r
    LCDShowTemp_state_t.LCD_state = ON;
    LcdShowCTR(LCDShowTemp_state_t);			

    LCDShowTemp_state_t.LCD_place = SET_UPPER_DIGITRON_DISPLAY_03;
    LCDShowTemp_state_t.LCD_code_data = error_value;
    LCDShowTemp_state_t.LCD_state = ON;
    LcdShowCTR(LCDShowTemp_state_t);

    LCDShowTemp_state_t.LCD_place = UPPER_POINT_DISPLAY;
    LCDShowTemp_state_t.LCD_code_data = 0;
    LCDShowTemp_state_t.LCD_state = OFF;
    LcdShowCTR(LCDShowTemp_state_t);

    LCDShowTemp_state_t.LCD_place = UPPER_TEMPER_UNIT_DISPLAY;
    LCDShowTemp_state_t.LCD_code_data = 0;
    LCDShowTemp_state_t.LCD_state = OFF;
    LcdShowCTR(LCDShowTemp_state_t);	
}
/*************************************************
				显示设置温度
display_mode   0 代表正常模式；
			   1 代表风速模式
***************************************************/
void  display_set_temp(u8 display_mode,int temp_value,u8 ararm_f)
{
	if(display_mode == 0)
	{
		Display_Middle_Digtal(0x07,temp_value);
	}
	else{
		Display_Middle_Digtal(0x02,temp_value);
	}
 
    if (ararm_f)
    {
        LCDShowTemp_state_t.LCD_place = MIDDLE_POINT_DISPLAY;	
        LCDShowTemp_state_t.LCD_state = OFF;
        LcdShowCTR(LCDShowTemp_state_t);

        LCDShowTemp_state_t.LCD_place = MIDDLE_TEMPER_UNIT_DISPLAY;	//温度单位
        LCDShowTemp_state_t.LCD_state = OFF;
        LcdShowCTR(LCDShowTemp_state_t);

    }
    else
    {
        LCDShowTemp_state_t.LCD_place = MIDDLE_POINT_DISPLAY;	
        LCDShowTemp_state_t.LCD_state = ON;
        LcdShowCTR(LCDShowTemp_state_t);

        LCDShowTemp_state_t.LCD_place = MIDDLE_TEMPER_UNIT_DISPLAY;	//温度单位
        LCDShowTemp_state_t.LCD_state = ON;
        LcdShowCTR(LCDShowTemp_state_t);
    }
}

/*************************************************
				显示运行模式
***************************************************/
void  display_system_mode(u8 heat,u8 dry,u8 cold ,u8 air,u8 sleep,u8 manufture,u8 Auto,u8 Roll)
{
	u8 Char_Picture = 0,OutLine = 0;
	Char_Picture = ( (heat&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (heat&0x10) ? 1: 0 ); 					//外圈
	LCDShowTemp_state_t.LCD_place = SYSTEM_HEATING_CHAR_DISPLAY;
	LCDShowTemp_state_t.LCD_state = Char_Picture;
	LcdShowCTR(LCDShowTemp_state_t);	//显示制热图标
	
	LCDShowTemp_state_t.LCD_place = SYSTEM_HEATING_OUTLINE_DISPLAY;
	LCDShowTemp_state_t.LCD_state = OutLine;
	LcdShowCTR(LCDShowTemp_state_t);	//显示制热外圈图标
	
	Char_Picture = ( (dry&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (dry&0x10) ? 1: 0 ); 					//外圈
	LCDShowTemp_state_t.LCD_place = SYSTEM_DRY_CHAR_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Char_Picture;
    LcdShowCTR(LCDShowTemp_state_t);	//显示除湿图标	
	
	LCDShowTemp_state_t.LCD_place = SYSTEM_DRY_OUTLINE_DISPLAY;
    LCDShowTemp_state_t.LCD_state = OutLine;
    LcdShowCTR(LCDShowTemp_state_t);	//显示除湿外圈图标	
	
	Char_Picture = ( (cold&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (cold&0x10) ? 1: 0 ); 					//外圈
    LCDShowTemp_state_t.LCD_place = SYSTEM_COOL_CHAR_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Char_Picture;
    LcdShowCTR(LCDShowTemp_state_t);	//显示制冷图标	
	
	LCDShowTemp_state_t.LCD_place = SYSTEM_COOL_OUTLINE_DISPLAY;
    LCDShowTemp_state_t.LCD_state = OutLine;
    LcdShowCTR(LCDShowTemp_state_t);	//显示制冷图标

	Char_Picture = ( (air&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (air&0x10) ? 1: 0 ); 					//外圈
    LCDShowTemp_state_t.LCD_place = SYSTEM_FAN_CHAR_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Char_Picture;
    LcdShowCTR(LCDShowTemp_state_t);	//显示通风图标	
	
    LCDShowTemp_state_t.LCD_place = SYSTEM_FAN_OUTLINE_DISPLAY;
    LCDShowTemp_state_t.LCD_state = OutLine;
    LcdShowCTR(LCDShowTemp_state_t);	//显示通风外圈图标

	Char_Picture = ( (sleep&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (sleep&0x10) ? 1: 0 ); 					//外圈
	LCDShowTemp_state_t.LCD_place = SYSTEM_SLEEP_CHAR_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Char_Picture;
    LcdShowCTR(LCDShowTemp_state_t);	//显示睡眠图标	
	
	LCDShowTemp_state_t.LCD_place = SYSTEM_SLEEP_OUTLINE_DISPLAY;
    LCDShowTemp_state_t.LCD_state = OutLine;
    LcdShowCTR(LCDShowTemp_state_t);	//显示睡眠外圈图标	
	
	Char_Picture = ( (manufture&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (manufture&0x10) ? 1: 0 ); 					//外圈
	LCDShowTemp_state_t.LCD_place = SYSTEM_MANUAL_CHAR_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Char_Picture;
    LcdShowCTR(LCDShowTemp_state_t);	//显示手动模式图标	
	
	LCDShowTemp_state_t.LCD_place = SYSTEM_MANUAL_OUTLINE_DISPLAY;
    LCDShowTemp_state_t.LCD_state = OutLine;
    LcdShowCTR(LCDShowTemp_state_t);	//显示手动模式外圈图标	
	
	Char_Picture = ( (Auto&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (Auto&0x10) ? 1: 0 ); 					//外圈
	LCDShowTemp_state_t.LCD_place = SYSTEM_AUTO_CHAR_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Char_Picture;
    LcdShowCTR(LCDShowTemp_state_t);	//显示自动模式图标	
	
	LCDShowTemp_state_t.LCD_place = SYSTEM_AUTO_OUTLINE_DISPLAY;
    LCDShowTemp_state_t.LCD_state = OutLine;
    LcdShowCTR(LCDShowTemp_state_t);	//显示自动模式外圈图标	
	
	Char_Picture = ( (Roll&0x01) ? 1: 0 ); 					//内圈
	OutLine		 = ( (Roll&0x10) ? 1: 0 ); 					//外圈
	LCDShowTemp_state_t.LCD_place = SYSTEM_ROLLING_CHAR_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Char_Picture;
    LcdShowCTR(LCDShowTemp_state_t);	//显示循环模式图标	
	
	LCDShowTemp_state_t.LCD_place = SYSTEM_ROLLING_OUTLINE_DISPLAY;
    LCDShowTemp_state_t.LCD_state = OutLine;
    LcdShowCTR(LCDShowTemp_state_t);	//显示循环模式外圈图标	
}
/*************************************************
				显示风速
***************************************************/
void  display_wind_speed(u8 wind_speed,u8 support_type)
{
	u8 display_char = 0; 
	//  0 关  1，低，2，中低 3，中 ，4中高，5，高，6，超高，a 自动	  support_type = 1
	// 1，低 2 ，中  3,高  A自动									  support_type = 0
	switch(wind_speed)
	{
		case 0:case 1:
			display_char = wind_speed;
			break;
		case 2:
		{
			if(support_type)
				display_char = 3;
			else
				display_char = 2;
			break;
		}
		case 3:
		{
			if(support_type)
				display_char = 5;
			else
				display_char = 3;
			break;
		}
		case 5:
		{
			if(support_type)
				display_char = 0x0A;
			else
				display_char = 0X0A;
		}
			break;
		case 7:
			if(support_type)
				display_char = 2;
			break;
		case 8:
			if(support_type)
				display_char = 4;
			break;
		case 9:
			if(support_type)
				display_char = 6;
			break;
	}
    LCDShowTemp_state_t.LCD_place = FAN_SPEED_DIGITRON_DISPLAY_01;
    LCDShowTemp_state_t.LCD_code_data = display_char;
    LCDShowTemp_state_t.LCD_state = ON;
    LcdShowCTR(LCDShowTemp_state_t);
}
/*************************************************
				显示童锁
***************************************************/
void display_child_lock(u8 child_lock)
{
	LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;
	if(child_lock)
	{
		LCDShowTemp_state_t.LCD_state = ON;
	}
	else
	{
		LCDShowTemp_state_t.LCD_state = OFF;
	}
	LcdShowCTR(LCDShowTemp_state_t);
}
/*************************************************
				显示运行模式
***************************************************/
void  display_wind_direct(u8 low,u8 mediu,u8 high)
{
	LCDShowTemp_state_t.LCD_place = WIND_DIRECTION_DOWN_DISPLAY;
	LCDShowTemp_state_t.LCD_state = low;
	LcdShowCTR(LCDShowTemp_state_t);	//风向 下图标
	
	LCDShowTemp_state_t.LCD_place = WIND_DIRECTION_MIDDLE_DISPLAY;
	LCDShowTemp_state_t.LCD_state = mediu;
	LcdShowCTR(LCDShowTemp_state_t);	//风向 中图标
	
	LCDShowTemp_state_t.LCD_place = WIND_DIRECTION_UP_DISPLAY;
	LCDShowTemp_state_t.LCD_state = high;
	LcdShowCTR(LCDShowTemp_state_t);	//风向 中图标
}
#define		LED1				P55
#define		LED2				P32
#define		LED3				P54
#define		LED4				P06
#define		LED5				P04
#define		LED6				P00
static  void  LED_ONOFF(u8 id,u8 onoff)
{
	switch(id)
	{
		case 1:
			(onoff == 1)? (LED1 = 1):(LED1 = 0);
			break;
		case 2:
			(onoff == 1)? (LED2 = 1):(LED2 = 0);
			break;
		case 3:
			(onoff == 1)? (LED3 = 1):(LED3 = 0);
			break;
		case 4:
			(onoff == 1)? (LED4 = 1):(LED4 = 0);
			break;
		case 5:
			(onoff == 1)? (LED5 = 1):(LED5 = 0);
			break;
		case 6:
			(onoff == 1)? (LED6 = 1):(LED6 = 0);
			break;
		case 7:
			(onoff == 1)? (Control_LED_ON_OFF(0xff)):(Control_LED_ON_OFF(0));	
			break;
		default:
			break;
	
	}
}

void Control_LED_ON_OFF(u8 onoff_bits)
{
	((onoff_bits&0x01	   ) ? (LED1 = 1):(LED1 = 0));
	(((onoff_bits>>1)&0x01) ? (LED2 = 1):(LED2 = 0));
	(((onoff_bits>>2)&0x01) ? (LED3 = 1):(LED3 = 0));
	(((onoff_bits>>3)&0x01) ? (LED4 = 1):(LED4 = 0));
	(((onoff_bits>>4)&0x01) ? (LED5 = 1):(LED5 = 0));		
	(((onoff_bits>>5)&0x01) ? (LED6 = 1):(LED6 = 0));		
}
void Operate_Led_Button(u8 device_type,u8 on_off)
{
	if(device_type == FLOOR_HEATING)
	{
		if(on_off)
		{
			Control_LED_ON_OFF(0x3D);
		}
		else
			Control_LED_ON_OFF(0x00);
	}
	else{
		if(on_off)
		{
			Control_LED_ON_OFF(0x3F);
		}
		else
			Control_LED_ON_OFF(0x00);
	}
}

static void Device_Type_Display(u8 air,u8 floor,u8 fan)
{
	LCDShowTemp_state_t.LCD_place = DEVICE_TYPE_AIRCONDITION_CHAR_DISPLAY;	//“空调”字样显示
    LCDShowTemp_state_t.LCD_state = air;
    LcdShowCTR(LCDShowTemp_state_t);
	
	LCDShowTemp_state_t.LCD_place = DEVICE_TYPE_HEATING_CHAR_DISPLAY;		//“地暖”字样显示
    LCDShowTemp_state_t.LCD_state = floor;
    LcdShowCTR(LCDShowTemp_state_t);
	
	LCDShowTemp_state_t.LCD_place = DEVICE_TYPE_FAN_CHAR_DISPLAY;			//“新风”字样显示
    LCDShowTemp_state_t.LCD_state = fan;
    LcdShowCTR(LCDShowTemp_state_t);
}
/************************************************
	显示延时关机、错误码、当前温度字符
	*********************************************/
void Display_Up_Contend(u8 device_type)
{
	if(IsPowerOffFlashing())
		return;
	if(device_type == AIR_CONDITION)
	{
		//显示错误码，优先级低于延时关机,高于当前温度
		if(Oled_Display_Info.Air_Device.power_off_time >0)
		{
			Display_poweroff_time(Oled_Display_Info.Air_Device.power_off_time);
		}
		else if((Oled_Display_Info.Air_Device.error)&&(Oled_Display_Info.Air_Device.power_off_time == 0))
		{
			display_error(Oled_Display_Info.Air_Device.error);
		}
		else if(Oled_Display_Info.is_dispaly_cur_temp)
		{
		   Display_Current_Temper(Oled_Display_Info.Air_Device.real_temperature);
		}
	}
	else if(device_type == FLOOR_HEATING)
	{
		if(Oled_Display_Info.FLOOR_Device.power_off_time >0)
		{
			Display_poweroff_time(Oled_Display_Info.FLOOR_Device.power_off_time);
		}
		else if((Oled_Display_Info.FLOOR_Device.error)&&(Oled_Display_Info.FLOOR_Device.power_off_time == 0))
		{
			display_error(Oled_Display_Info.FLOOR_Device.error);
		}
		else if(Oled_Display_Info.is_dispaly_cur_temp)
	    {
		   Display_Current_Temper(Oled_Display_Info.FLOOR_Device.real_temperature);
	    }
	}
	else if(device_type == FAN)
	{
		if(Oled_Display_Info.FAN_Device.power_off_time >0)
		{
		   Display_poweroff_time(Oled_Display_Info.FAN_Device.power_off_time);
		}
		else if((Oled_Display_Info.FAN_Device.error)&&(Oled_Display_Info.FAN_Device.power_off_time == 0))
		{
		   display_error(Oled_Display_Info.FAN_Device.error);
		}
		else if((Oled_Display_Info.is_dispaly_cur_temp))
		{
		   Display_Current_Temper(Oled_Display_Info.FAN_Device.real_temperature);
		}
	}
}
void Fan_Oled_Display()
{
	/********************************************
    显示“新风”字样	
    *********************************************/
	Device_Type_Display(0,0,1);
	
	/********************************************
	显示工作模式
	*********************************************/
	Displayt_System_Mode(Oled_Display_Info.FAN_Device.system_type);
	
	//儿童锁图标
    /*********************************************/
    LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Oled_Display_Info.FAN_Device.lock_flage;  
    LcdShowCTR(LCDShowTemp_state_t);
	
	/********************************************
	显示当前风速
	*********************************************/
	if(!IsLcdEnterScreenSave())
		display_set_temp(1,Oled_Display_Info.FAN_Device.wind_speed,1);
	else
		display_set_temp(0,Oled_Display_Info.FAN_Device.real_temperature,0);       //显示当前温度
	/********************************************
	显示延时关机、错误码、当前温度字符
	*********************************************/
	if(!IsLcdEnterScreenSave())
		Display_Up_Contend(FAN);
}
void Floor_Heating_Oled_Display()
{
	/********************************************
    显示“地暖”字样	
    *********************************************/
	Device_Type_Display(0,1,0);
	
	/********************************************
    显示设置温度	
    *********************************************/
	display_set_temp(0,Oled_Display_Info.FLOOR_Device.set_temperature,0);       //显示设置温度

	/********************************************
	显示工作模式
	*********************************************/
	Displayt_System_Mode(Oled_Display_Info.FLOOR_Device.system_type);
	
	//儿童锁图标
    /*********************************************/
    LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Oled_Display_Info.FLOOR_Device.lock_flage;  
    LcdShowCTR(LCDShowTemp_state_t);
	
	/********************************************
	显示延时关机、错误码、当前温度字符
	*********************************************/
	if(!IsLcdEnterScreenSave())
		Display_Up_Contend(FLOOR_HEATING);
}
void Air_Oled_Display(void)
{
	/********************************************
    显示“空调”字样	
    *********************************************/
	Device_Type_Display(1,0,0);
	  								//显示设置温度
	/********************************************
    显示设置温度	
    *********************************************/
	display_set_temp(0,Oled_Display_Info.Air_Device.set_temperature,0);       //显示设置温度

	/********************************************
	显示工作模式
	*********************************************/
	Displayt_System_Mode(Oled_Display_Info.Air_Device.system_type);
	/********************************************
    儿童锁图标
    *********************************************/
    LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;
    LCDShowTemp_state_t.LCD_state = Oled_Display_Info.Air_Device.lock_flage;  
    LcdShowCTR(LCDShowTemp_state_t);
	
	/********************************************
	显示延时关机、错误码、当前温度字符
	*********************************************/
	if(!IsLcdEnterScreenSave())
		Display_Up_Contend(AIR_CONDITION);
	
	/********************************************
	显示主从模式
	*********************************************/
	#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
	if( (Oled_Display_Info.Air_Device.power_off_time == 0) &&(Oled_Display_Info.Air_Device.air_master_slavery_mode))
	{
		//显示H图标
		if(!IsLcdEnterScreenSave())
		{
			LCDShowTemp_state_t.LCD_place = H_CHAR_DISPLAY;	
			LCDShowTemp_state_t.LCD_state = ON;	
			LcdShowCTR(LCDShowTemp_state_t);
		}			
	}
	#endif
}
/*************************************************
				开机显示选项
***************************************************/
void Oled_Display_whole(void)
{	
	if(IsLocalConfigMode())
		return;
    LCD_CONTROL(1);								//开机

	if(Oled_Display_Info.screen_page == AIR_CONDITION)
		Air_Oled_Display();
	else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
		Floor_Heating_Oled_Display();
	else if(Oled_Display_Info.screen_page == FAN)
		Fan_Oled_Display();

    /********************************************
    ZigBee信号图标
    *********************************************/
    if (Oled_Display_Info.net_work_flage ==  IN_LINE)
    {
        LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
		LCDShowTemp_state_t.LCD_state = ON;
		LcdShowCTR(LCDShowTemp_state_t);
    }  		
}


void PowerOff(void)
{
	if(Oled_Display_Info.screen_page == AIR_CONDITION)
	{
		if(Oled_Display_Info.Air_Device.on_off)
			BL55072A_Clear();
		if(!IsLcdEnterScreenSave())
		{
			Device_Type_Display(1,0,0);
			
			LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;
			LCDShowTemp_state_t.LCD_state = Oled_Display_Info.Air_Device.lock_flage;  
			LcdShowCTR(LCDShowTemp_state_t);
		}
	}
	else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
	{
		if(Oled_Display_Info.FLOOR_Device.on_off)
			BL55072A_Clear();
		if(!IsLcdEnterScreenSave())
		{
			Device_Type_Display(0,1,0);
			
			LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;
			LCDShowTemp_state_t.LCD_state = Oled_Display_Info.FLOOR_Device.lock_flage;  
			LcdShowCTR(LCDShowTemp_state_t);
		}
	}
	else
	{
		if(Oled_Display_Info.FAN_Device.on_off)
			BL55072A_Clear();
		if(!IsLcdEnterScreenSave())
		{
			Device_Type_Display(0,0,1);
			
			LCDShowTemp_state_t.LCD_place = CHILD_LOCK_DISPLAY;
			LCDShowTemp_state_t.LCD_state = Oled_Display_Info.FAN_Device.lock_flage;  
			LcdShowCTR(LCDShowTemp_state_t);
		}
	}
	
	if(IsLcdEnterScreenSave())
	{
		LCD_CONTROL(0);				//关闭屏幕背景
		return;
	}
	//关闭上放的显示
	Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
	
	LCDShowTemp_state_t.LCD_place = SET_MIDDLE_DIGITRON_DISPLAY_01;
    LCDShowTemp_state_t.LCD_code_data = 0;
    LCDShowTemp_state_t.LCD_state = ON;
    LcdShowCTR(LCDShowTemp_state_t);


    LCDShowTemp_state_t.LCD_place = SET_MIDDLE_DIGITRON_DISPLAY_02;
    LCDShowTemp_state_t.LCD_code_data = 0x0F;
    LCDShowTemp_state_t.LCD_state = ON;
    LcdShowCTR(LCDShowTemp_state_t);

    LCDShowTemp_state_t.LCD_place = SET_MIDDLE_DIGITRON_DISPLAY_03;
    LCDShowTemp_state_t.LCD_code_data = 0x0F;		
    LCDShowTemp_state_t.LCD_state = ON;
    LcdShowCTR(LCDShowTemp_state_t);
	
	LCDShowTemp_state_t.LCD_place = MIDDLE_POINT_DISPLAY;	
    LCDShowTemp_state_t.LCD_state = OFF;
    LcdShowCTR(LCDShowTemp_state_t);
	
	/********************************************
    ZigBee信号图标
    *********************************************/
    if (Oled_Display_Info.net_work_flage ==  IN_LINE)
    {
        LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
		LCDShowTemp_state_t.LCD_state = ON;
		LcdShowCTR(LCDShowTemp_state_t);
    }  	
}
void Displayt_System_Mode(u8 system_mode)
{
	switch(system_mode)
	{
		case SYSTEM_MODE_HEATING:				
		{
			display_system_mode(0x01,0,0,0,0,0,0,0);			//制热
			break;
		}
		case SYSTEM_MODE_DRY:
		{
			display_system_mode(0x00,0x01,0,0,0,0,0,0);		//除湿
			break;
		}
		case SYSTEM_MODE_COOLING:
		{
			display_system_mode(0x00,0x00,0x01,0,0,0,0,0);	//制冷			
			break;
		}
		case SYSTEM_MODE_AIR:
		{
			display_system_mode(0x00,0x00,0,0x01,0,0,0,0);	//通风		
			break;
		}
		case SYSTEM_MODE_SLEEP:
		{
			display_system_mode(0x00,0x00,0,0x00,0x01,0,0,0);	//睡眠	
			break;
		}
		case SYSTEM_MODE_MANUAL:
		{
			display_system_mode(0x00,0x00,0,0x00,0,0X01,0,0);	//手动	
			break;
		}
		case SYSTEM_MODE_AUTO:
		{
			display_system_mode(0x00,0x00,0,0x00,0,0,0X01,0);	//自动	
			break;
		}
		case SYSTEM_MODE_ROLL:
		{
			display_system_mode(0x00,0x00,0,0x00,0,0,0,0X01);	//循环
			break;
		}
	   default:
			break;          
	}
}
void EnterScreenSaveMode(void)
{
	extern u8 First_Exit_Factory_Mode;
	if(First_Exit_Factory_Mode == 1)
		return;
	if(IsLocalConfigMode())
		return;
	BL55072A_Clear();
	switch(Oled_Display_Info.screen_page)
	{
		case AIR_CONDITION:
		{
			if((Oled_Display_Info.Air_Device.on_off)&&(Oled_Display_Info.Air_Device.no_disturb_mode == 0))
			{
				Operate_Led_Button(AIR_CONDITION,0);									// 显示可操作的按键
	
				/********************************************
				显示“空调”字样	
				*********************************************/
				Device_Type_Display(1,0,0);
				
				/********************************************
				显示设置温度	
				*********************************************/
				display_set_temp(0,Oled_Display_Info.Air_Device.set_temperature,0);       //显示设置温度
				
				/********************************************
				显示工作模式
				*********************************************/
				Displayt_System_Mode(Oled_Display_Info.Air_Device.system_type);
				
				if (Oled_Display_Info.net_work_flage ==  IN_LINE)
				{
					LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
					LCDShowTemp_state_t.LCD_state = ON;
					LcdShowCTR(LCDShowTemp_state_t);
				}  	
				
			}
			else{
				Operation_LED(0);     //全关led
				LCD_CONTROL(0);
			}
			
		}
			break;
		case FLOOR_HEATING:
		{
			if((Oled_Display_Info.FLOOR_Device.on_off)&&(Oled_Display_Info.FLOOR_Device.no_disturb_mode == 0))
			{
				Operate_Led_Button(FLOOR_HEATING,0);									// 显示可操作的按键
	
				/********************************************
				显示“地暖”字样	
				*********************************************/
				Device_Type_Display(0,1,0);
				
				/********************************************
				显示设置温度	
				*********************************************/
				display_set_temp(0,Oled_Display_Info.FLOOR_Device.set_temperature,0);       //显示设置温度
				
				/********************************************
				显示工作模式
				*********************************************/
				Displayt_System_Mode(Oled_Display_Info.FLOOR_Device.system_type);
				
				if (Oled_Display_Info.net_work_flage ==  IN_LINE)
				{
					LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
					LCDShowTemp_state_t.LCD_state = ON;
					LcdShowCTR(LCDShowTemp_state_t);
				} 
				
			}
			else{
				Operation_LED(0);     //全关led
				LCD_CONTROL(0);
			}
		}
			break;
		case FAN:
		{
			if((Oled_Display_Info.FAN_Device.on_off)&&(Oled_Display_Info.FAN_Device.no_disturb_mode == 0))
			{
				Operate_Led_Button(FAN,0);									// 显示可操作的按键
	
				/********************************************
				显示“新风”字样	
				*********************************************/
				Device_Type_Display(0,0,1);
				
				/********************************************
				显示设置温度	
				*********************************************/
				display_set_temp(0,Oled_Display_Info.FAN_Device.real_temperature,0);       //显示当前温度
				
				/********************************************
				显示工作模式
				*********************************************/
				Displayt_System_Mode(Oled_Display_Info.FAN_Device.system_type);
				
				if (Oled_Display_Info.net_work_flage ==  IN_LINE)
				{
					LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
					LCDShowTemp_state_t.LCD_state = ON;
					LcdShowCTR(LCDShowTemp_state_t);
				} 
				
			}
			else{
				Operation_LED(0);     //全关led
				LCD_CONTROL(0);
			}
		}
			break;
		default:
		break;
	}
	
}
void Detect_Human_Dispaly(void)
{
	if(IsLocalConfigMode())
		return;
	if(Oled_Display_Info.screen_page == AIR_CONDITION)
	{
		if(Oled_Display_Info.Air_Device.on_off)
		{
			Operate_Led_Button(AIR_CONDITION,1);									// 显示可操作的按键
			Oled_Display_whole();
		}
		else{
			if(sKey_Operation[0].operate_calibrate_temper == 0)    //正在操作温度校准,不显示关机
				PowerOff();
		}
	}
	else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
	{
		if(Oled_Display_Info.FLOOR_Device.on_off)
		{
			//15minà??ˉ?×??￡?è?????ê?μ?
			if(Oled_Display_Info.aging_test_flag == 2)
				Operate_Led_Button(FLOOR_HEATING,1);								// ??ê??é2ù×÷μ?°′?ü
			else
				Operate_Led_Button(AIR_CONDITION,1);
			Oled_Display_whole();
		}
		else{
			if(sKey_Operation[1].operate_calibrate_temper == 0)    //正在操作温度校准,不显示关机
				PowerOff();
		}
	}
	else if(Oled_Display_Info.screen_page == FAN)
	{
		if(Oled_Display_Info.FAN_Device.on_off)
		{
			Operate_Led_Button(FAN,1);
			Oled_Display_whole();
		}
		else{
			if(sKey_Operation[2].operate_calibrate_temper == 0)    //正在操作温度校准,不显示关机
				PowerOff();
		}
	}
}
void display_current_page(void)
{
	if(Oled_Display_Info.screen_page == AIR_CONDITION)
	{
		if(Oled_Display_Info.Air_Device.on_off)
			Oled_Display_whole();											//显示所有的界面
		else
			PowerOff();
	}
	else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
	{
		if(Oled_Display_Info.FLOOR_Device.on_off)
			Oled_Display_whole();											//显示所有的界面
		else
			PowerOff();
	}
	else if(Oled_Display_Info.screen_page == FAN)
	{
		if(Oled_Display_Info.FAN_Device.on_off)
			Oled_Display_whole();											//显示所有的界面
		else
			PowerOff();
	}
}
u8 Get_Last_System_Mode(u8 device_type,u8 current_system_mode,u8 is_support_sleep)
{
	if(device_type == AIR_CONDITION)
	{
		switch(current_system_mode)
		{
			case SYSTEM_MODE_HEATING:
			{
				current_system_mode = SYSTEM_MODE_DRY;
			}
			break;
			case SYSTEM_MODE_DRY:
			{
				current_system_mode = SYSTEM_MODE_COOLING;
			}
			break;
			case SYSTEM_MODE_COOLING:
			{
				current_system_mode = SYSTEM_MODE_AIR;
			}
			break;
			case SYSTEM_MODE_AIR:
			{
				if(is_support_sleep)
					current_system_mode = SYSTEM_MODE_SLEEP;
				else
					current_system_mode = SYSTEM_MODE_HEATING;
			}
			break;
			case SYSTEM_MODE_SLEEP:
			{
				current_system_mode = SYSTEM_MODE_HEATING;
			}
			break;
			default:
				break;
		}
	}
//	else if(device_type == FLOOR_HEATING)
//	{
//	
//	}
//	else
//	{
//	
//	}
	return current_system_mode;
}
/*************************************************
				短按M按键操作空调模式
***************************************************/
u8 System_Mode_Trans(u8 device_type,u8 is_support_sleep)
{
	static u8 i = 0;
	u8  temp_system = 0;
	if(device_type == AIR_CONDITION)
	{
		temp_system = Oled_Display_Info.Air_Device.system_type;
		i = Get_Last_System_Mode(AIR_CONDITION, temp_system,is_support_sleep);
		switch(i)
		{
			case SYSTEM_MODE_HEATING:
			{
				display_system_mode(0x11,0x01,0x01,0x01,is_support_sleep,0,0,0);
				temp_system = i;
			}
			break;
			case SYSTEM_MODE_DRY:
			{
				display_system_mode(0x01,0x11,0x01,0x01,is_support_sleep,0,0,0);
				temp_system = i;
			}
			break;
			case SYSTEM_MODE_COOLING:
			{
				display_system_mode(0x01,0x01,0x11,0x01,is_support_sleep,0,0,0);
				temp_system = i;
			}
			break;
			case SYSTEM_MODE_AIR:
			{
				display_system_mode(0x01,0x01,0x01,0x11,is_support_sleep,0,0,0);
				temp_system = i;
			}
			break;
			case SYSTEM_MODE_SLEEP:
			{
				if(is_support_sleep)
					display_system_mode(0x01,0x01,0x01,0x01,0x11,0,0,0);
				else
					display_system_mode(0x01,0x01,0x01,0x01,0,0,0,0);
				temp_system = i;
			}
			break;
			default:
				break;
		}
	}
	else if(device_type == FLOOR_HEATING)
	{
		temp_system = Oled_Display_Info.FLOOR_Device.system_type;
		i = (temp_system == SYSTEM_MODE_MANUAL)?(SYSTEM_MODE_AUTO):(SYSTEM_MODE_MANUAL);
		switch(i)
		{
			case SYSTEM_MODE_MANUAL:
			{
				display_system_mode(0,0,0,0,0,0X11,0X01,0);
				temp_system = i;
			}
				break;
			case SYSTEM_MODE_AUTO:
			{
				display_system_mode(0,0,0,0,0,0X01,0X11,0);
				temp_system = i;
			}
				break;
			default:
				break;
		}
	}
	else if(device_type == FAN)
	{
		temp_system = Oled_Display_Info.FAN_Device.system_type;
		i = (temp_system == SYSTEM_MODE_MANUAL)?(SYSTEM_MODE_ROLL):(SYSTEM_MODE_MANUAL);
		switch(i)
		{
			case SYSTEM_MODE_MANUAL:
			{
				display_system_mode(0,0,0,0,0,0X11,0,0X01);
				temp_system = i;
			}
			break;
			case SYSTEM_MODE_ROLL:
			{
				display_system_mode(0,0,0,0,0,0X01,0,0X11);
				temp_system = i;
			}
			break;
			default:
				break;
		}
	}
	delay_confirm_system_control(1);           //延时开启	
	return temp_system;
	
}

void delay_confirm_system_mode(void)
{
	delay_confirm_system_control(0);           //延时关闭
	if(Oled_Display_Info.screen_page == AIR_CONDITION)
	{
		if(Oled_Display_Info.Air_Device.on_off == 0)     //开机模式才能操作
			return;
		Displayt_System_Mode(Oled_Display_Info.Air_Device.system_type);
	}
	else if(Oled_Display_Info.screen_page == FLOOR_HEATING)
	{
		if(Oled_Display_Info.FLOOR_Device.on_off == 0)     //开机模式才能操作
			return;
		Displayt_System_Mode(Oled_Display_Info.FLOOR_Device.system_type);
	}
	else if(Oled_Display_Info.screen_page == FAN)
	{
		if(Oled_Display_Info.FAN_Device.on_off == 0)     //开机模式才能操作
			return;
		Displayt_System_Mode(Oled_Display_Info.FAN_Device.system_type);
	}
}
void Fan_speed_and_direct_control(u8 windspeed_onoff,u8 winddirect_onoff)
{
	LCDShowTemp_state_t.LCD_place = WIND_DIRECT_CHAR_DISPLAY;		//关闭风向闪烁
	LCDShowTemp_state_t.LCD_state = winddirect_onoff;
	LcdShowCTR(LCDShowTemp_state_t);
	
	LCDShowTemp_state_t.LCD_place = WIND_SPEED_CHAR_DISPLAY;		//打开风速
	LCDShowTemp_state_t.LCD_state = windspeed_onoff;
	LcdShowCTR(LCDShowTemp_state_t);
}
/*************************************************
				短按风扇按键操作空调模式
***************************************************/
void Fan_Button_Handler(void)
{
	static u8  press_count = 0;

	press_count++;
	if(!gKey_Press_Info.adjust_fan_speed_status )          				//第一次总是显示风速
		press_count = 1;
	if(press_count == 1)		//第一次按下
	{
		Fan_speed_and_direct_control(1,0);
		display_wind_direct(0,0,0);										//关闭风向显示
		
		
		LCDShowTemp_state_t.LCD_place = WIND_SPEED_CHAR_DISPLAY;		//风速
		LCDShowTemp_state_t.LCD_state = FLASHING;
		LCDShowTemp_state_t.LCD_display_timer = 500/10;            		//500ms 一次
		LCDShowTemp_state_t.LCD_display_count = 20;
		LcdShowCTR(LCDShowTemp_state_t);
		
		gKey_Press_Info.adjust_fan_speed_status    = 1;
		if(Oled_Display_Info.screen_page == AIR_CONDITION)
		{
			if(Oled_Display_Info.Air_Device.air_cond_type != 2/*线控器*/)                  //仅线控器支持风向调节
			{
				press_count = 0;
				display_wind_speed(Oled_Display_Info.Air_Device.wind_speed,0);    			//显示当前风速
			}
			else{
				press_count = 0;
				display_wind_speed(Oled_Display_Info.Air_Device.wind_speed,0);    			//显示当前风速
			}
		}
		else if(Oled_Display_Info.screen_page == FAN){
			press_count = 0;
			display_wind_speed(Oled_Display_Info.FAN_Device.wind_speed,0);  
		}
	}
	if(press_count == 2)   //切换风向
	{
		press_count = 0;
		Fan_speed_and_direct_control(0,1);
		
		LCDShowTemp_state_t.LCD_place = FAN_SPEED_DIGITRON_DISPLAY_01; //关闭风速等级显示
		LCDShowTemp_state_t.LCD_state = OFF;
		LcdShowCTR(LCDShowTemp_state_t);
		
		LCDShowTemp_state_t.LCD_place = WIND_DIRECT_CHAR_DISPLAY;		
		LCDShowTemp_state_t.LCD_state = FLASHING;
		LCDShowTemp_state_t.LCD_display_timer = 500/10;            	//1s 一次
		LCDShowTemp_state_t.LCD_display_count = 20;
		LcdShowCTR(LCDShowTemp_state_t);
		
		switch(Oled_Display_Info.Air_Device.air_wind_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;
		}
		gKey_Press_Info.adjust_fan_speed_status    = 2;

	}
	delay_confirm_fan_speed_control(1);
}
void delay_confirm_fan_speed(void)
{
	delay_confirm_fan_speed_control(0);
	gKey_Press_Info.adjust_fan_speed_status    = 0;
	Fan_speed_and_direct_control(0,0);
	display_wind_direct(0,0,0);										//关闭风向显示
	
	LCDShowTemp_state_t.LCD_place = FAN_SPEED_DIGITRON_DISPLAY_01; //关闭风速等级显示
    LCDShowTemp_state_t.LCD_state = OFF;
    LcdShowCTR(LCDShowTemp_state_t);
}
void Set_CMD_Handler(u8 device_type,u16 opcode,u8 *arg,u8 arg_len)
{
	if(arg == NULL)
		return;
	switch(device_type)
	{
		case 1:  																					//空调
		{
			switch(opcode)
			{
				case OPCODE_GENERAL_SWITCH:  																					//空调
				{
					u8 onoff = arg[0];
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新开关状态
						Oled_Display_Info.Air_Device.on_off = onoff; 
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
						break;
					}						
					if(onoff == ON)
					{
						if(Oled_Display_Info.Air_Device.on_off == 0)
						{
							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.Air_Device.on_off == 1)
						{
							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
						}
					}
					
					arg[0] = 0;
					arg[1] = onoff;
				}
				break;
				case OPCODE_GENERAL_OPERATION_MODE:
				{
					u8 system_mode = arg[0];
					if(Oled_Display_Info.Air_Device.on_off == 0)
						return;
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新状态
						arg[0] = 0;
						arg[1] = system_mode;
						Oled_Display_Info.Air_Device.system_type = system_mode;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
						break;
					}
					if(Oled_Display_Info.Air_Device.on_off)
					{
						Displayt_System_Mode(system_mode);
						Oled_Display_Info.Air_Device.system_type = system_mode;
						#if  (DEV_TYPE == 0) &&(DEVICE_TYPE_AIR_CONDITION ==1)
							delay_control_system_mode_start();
						#else
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
						#endif
						arg[0] = 0;
					}
					else
						arg[0] = 0xff;
					arg[1] = system_mode;
				}
					break;
				case OPCODE_GENERAL_SET_TEMPERATURE:
				{
					u16 set_temper = arg[0];
					set_temper = (set_temper<<8) | (arg[1]&0xff);
					arg[1] = set_temper >>8;
					arg[2] = set_temper&0xff;
					if(Oled_Display_Info.Air_Device.on_off == 0)
						return;
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新状态
						arg[0] = 0;
						Oled_Display_Info.Air_Device.set_temperature = set_temper;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);	//状态改变通知
						break;
					}
					//通风模式下不可以调节设定温度
					if((Oled_Display_Info.Air_Device.on_off)&&(Oled_Display_Info.Air_Device.system_type !=SYSTEM_MODE_AIR))  
					{
						display_set_temp(0,set_temper,0);
						Oled_Display_Info.Air_Device.set_temperature = set_temper;
						arg[0] = 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
						arg[0] = 0xff;
				}
					break;
				case OPCODE_GENERAL_SET_WIND_SPEED:											//下发控制不需要显示			
				{
					u8 wind_speed = arg[0];
					arg[1] = wind_speed;
					if(Oled_Display_Info.Air_Device.on_off == 0)
						return;
					Oled_Display_Info.Air_Device.wind_speed = wind_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
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_ERROR_CODE:										
				{
					u8 error_code = arg[0];
					arg[1] = error_code;
					Oled_Display_Info.Air_Device.error = error_code; 
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
				}
					break;
				case OPCODE_GENERAL_SET_CHILD_LOCK:
				{
					u8 child_lock = arg[0];
					arg[1] = child_lock;
					
					Oled_Display_Info.Air_Device.lock_flage = child_lock; 
					if(Get_Display_Status())
						display_child_lock(child_lock);
					save_data();											//保存token
					arg[0] = 0;
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
				}
					break;
				case OPCODE_GENERAL_SET_DELAY_OFF_TIME:							
				{
					u8 delay_off_time = arg[0];
					arg[1] = delay_off_time;
					
					if(Oled_Display_Info.Air_Device.on_off == 0)
						return;
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新状态
						arg[0] = 0;
						arg[1] = delay_off_time;
						Oled_Display_Info.Air_Device.power_off_time = delay_off_time;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						break;
					}
					Oled_Display_Info.Air_Device.power_off_time  = delay_off_time; 

					if( (Get_Display_Status())&&(delay_off_time >0) )
						Display_poweroff_time(delay_off_time);
					else if((Get_Display_Status())&&(delay_off_time ==0)&&(Oled_Display_Info.Air_Device.power_off_flage))
						Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
					
					if(delay_off_time >0)
						Oled_Display_Info.Air_Device.power_off_flage  = 1;
					else if(Oled_Display_Info.Air_Device.power_off_flage == 1)
						Oled_Display_Info.Air_Device.power_off_flage = 0;
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
					arg[0] = 0;

				}
					break;
				case OPCODE_GENERAL_SET_SWING_MODE:						
				{
					u8 swing_mode = arg[0];
					arg[1] = swing_mode;
					#if 0    					//美的不支持风向调节
					Oled_Display_Info.Air_Device.air_wind_direct = swing_mode; 
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
					#endif
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_SET_SCREEN_SAVE_TIME:						
				{
					u8 screen_save_time = arg[0];
					arg[1] = screen_save_time;
					
					Oled_Display_Info.Air_Device.screen_save_time = screen_save_time; 
					save_data();															//保存token
					
					arg[0] = 0;
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
				}
					break;
				case OPCODE_GENERAL_SET_FILTER_CLEANING_TIME:						
				{
					u16 filter_wash_time = ((u16)arg[0]) << 8 | arg[1] ;
					arg[1] = filter_wash_time >>8;
					arg[2] = filter_wash_time&0xff;
					
					Oled_Display_Info.Air_Device.filter_wash_time = filter_wash_time; 
					save_data();															//保存token
					
					arg[0] = 0;
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
				}
					break;
				case OPCODE_GENERAL_CURRENT_REAL_TEMPER:								//不处理当前的温度
				{
//					u16 filter_wash_time = arg[0] <<8 | arg[1] ;
//					arg[1] = filter_wash_time>>8;
//					arg[2] = filter_wash_time&0xff;
//					
//					Oled_Display_Info.Air_Device.filter_wash_time = filter_wash_time; 
//					arg[0] = 0;
//					printf("filter_wash_time = %d\r\n",Oled_Display_Info.Air_Device.filter_wash_time);
	
				}
					break;
				case OPCODE_GENERAL_SET_TEMPER_CALIBRATION:								//温度校准				
				{
					s8 calibration_temp = arg[0] ;
					arg[1] = calibration_temp;
					
					Oled_Display_Info.Air_Device.real_temperature = Oled_Display_Info.Air_Device.real_temperature -Oled_Display_Info.Air_Device.correct_temperature + calibration_temp;
					Oled_Display_Info.Air_Device.correct_temperature = calibration_temp; 
					save_data();															//保存token
					
					arg[0] = 0;
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
				}
					break;
				case OPCODE_GENERAL_SET_NO_DISTURB_MODE:								
				{
					s8 no_disturb_mode = arg[0] ;
					arg[1] = no_disturb_mode;
					
					Oled_Display_Info.Air_Device.no_disturb_mode = no_disturb_mode; 
					save_data();															//保存token
					if(IsLcdEnterScreenSave() &&(Oled_Display_Info.screen_page == device_type)&&no_disturb_mode)
					{
						LCD_CONTROL(0);
						BL55072A_Clear();
					}
					else if(IsLcdEnterScreenSave()&&(no_disturb_mode == 0)&&(Oled_Display_Info.Air_Device.on_off))
					{
						LCD_CONTROL(1);
						EnterScreenSaveMode();
					}
					arg[0] = 0;
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,1);									//状态更新上报
				}
					break;
			}	
		}
		break;
		case 2:																						//地暖
		{
			switch(opcode)
			{
				case OPCODE_GENERAL_SWITCH:  																					//空调
				{
					u8 onoff = arg[0];
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新开关状态
						Oled_Display_Info.FLOOR_Device.on_off = onoff; 
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						break;
					}						
					if(onoff == ON)
					{
						if(Oled_Display_Info.FLOOR_Device.on_off == 0)
						{
							Control_OnOff_handler(FLOOR_HEATING,1);													//控制阀门关闭	
							
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						}
					}
					else
					{
						if(Oled_Display_Info.FLOOR_Device.on_off == 1)
						{
							Control_OnOff_handler(FLOOR_HEATING,0);													//控制阀门关闭	
							
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
							
						}
					}
					arg[0] = 0;
					arg[1] = onoff;
				}
				break;
				case OPCODE_GENERAL_OPERATION_MODE:
				{
					u8 system_mode = arg[0];
					if(Oled_Display_Info.FLOOR_Device.on_off == 0)
						return;
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新状态
						arg[0] = 0;
						arg[1] = system_mode;
						Oled_Display_Info.FLOOR_Device.system_type = system_mode;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						break;
					}
					if(Oled_Display_Info.FLOOR_Device.on_off)
					{
						Displayt_System_Mode(system_mode);
						Oled_Display_Info.FLOOR_Device.system_type = system_mode;
						
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						arg[0] = 0;
					}
					else
						arg[0] = 0xff;
					arg[1] = system_mode;
				}
					break;
				case OPCODE_GENERAL_SET_TEMPERATURE:
				{
					u16 set_temper = ((u16)arg[0])<<8 | arg[1];
					arg[1] = set_temper >>8;
					arg[2] = set_temper&0xff;
					if( Oled_Display_Info.FLOOR_Device.on_off == 0)
						return;
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新状态
						arg[0] = 0;
						Oled_Display_Info.FLOOR_Device.set_temperature = set_temper;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						break;
					}
					if( (Oled_Display_Info.FLOOR_Device.on_off)&&(Oled_Display_Info.FLOOR_Device.system_type == SYSTEM_MODE_MANUAL) )
					{
						display_set_temp(0,set_temper,0);
						Oled_Display_Info.FLOOR_Device.set_temperature = set_temper;
						
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						arg[0] = 0;
					}
					else
						arg[0] = 0xff;
				}
					break;
				case OPCODE_GENERAL_ERROR_CODE:										
				{
					u8 error_code = arg[0];
					arg[1] = error_code;
					arg[0] = 0;
					Oled_Display_Info.FLOOR_Device.error = error_code; 
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
				}
					break;
				case OPCODE_GENERAL_SET_CHILD_LOCK:
				{
					u8 child_lock = arg[0];
					arg[1] = child_lock;
					
					Oled_Display_Info.FLOOR_Device.lock_flage = child_lock; 
					if(Get_Display_Status())
						display_child_lock(child_lock);
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
					save_data();											//保存token
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_SET_DELAY_OFF_TIME:							
				{
					u8 delay_off_time = arg[0];
					arg[1] = delay_off_time;
					
					if(Oled_Display_Info.FLOOR_Device.on_off == 0)
						return;
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新状态
						arg[0] = 0;
						arg[1] = delay_off_time;
						Oled_Display_Info.FLOOR_Device.power_off_time = delay_off_time;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
						break;
					}
					Oled_Display_Info.FLOOR_Device.power_off_time = delay_off_time; 
	
					if( (Get_Display_Status())&&(delay_off_time >0) )
						Display_poweroff_time(delay_off_time);
					else if((Get_Display_Status())&&(delay_off_time ==0)&&(Oled_Display_Info.FLOOR_Device.power_off_flage))
						Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
					
					if(delay_off_time >0)
						Oled_Display_Info.FLOOR_Device.power_off_flage  = 1;
					else if(Oled_Display_Info.FLOOR_Device.power_off_flage == 1)
						Oled_Display_Info.FLOOR_Device.power_off_flage = 0;
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
					arg[0] = 0;

				}
					break;
				case OPCODE_GENERAL_SET_SCREEN_SAVE_TIME:						
				{
					u8 screen_save_time = arg[0];
					arg[1] = screen_save_time;
					
					Oled_Display_Info.FLOOR_Device.screen_save_time = screen_save_time; 
					
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
					save_data();															//保存token
					
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_CURRENT_REAL_TEMPER:								//不处理当前的温度
				{
//					u16 filter_wash_time = arg[0] <<8 | arg[1] ;
//					arg[1] = filter_wash_time>>8;
//					arg[2] = filter_wash_time&0xff;
//					
//					Oled_Display_Info.Air_Device.filter_wash_time = filter_wash_time; 
//					arg[0] = 0;
//					printf("filter_wash_time = %d\r\n",Oled_Display_Info.Air_Device.filter_wash_time);
	
				}
					break;
				case OPCODE_GENERAL_SET_TEMPER_CALIBRATION:								//温度校准				
				{
					s8 calibration_temp = arg[0] ;
					arg[1] = calibration_temp;
					
					Oled_Display_Info.FLOOR_Device.real_temperature = Oled_Display_Info.FLOOR_Device.real_temperature -Oled_Display_Info.FLOOR_Device.correct_temperature + calibration_temp;
					Oled_Display_Info.FLOOR_Device.correct_temperature = calibration_temp; 
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
					save_data();															//保存token
					
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_SET_NO_DISTURB_MODE:								
				{
					s8 no_disturb_mode = arg[0] ;
					arg[1] = no_disturb_mode;
					
					Oled_Display_Info.FLOOR_Device.no_disturb_mode = no_disturb_mode; 
					if(IsLcdEnterScreenSave() &&(Oled_Display_Info.screen_page == device_type)&&no_disturb_mode)
					{
						LCD_CONTROL(0);
						BL55072A_Clear();
					}
					else if(IsLcdEnterScreenSave()&&(no_disturb_mode == 0)&&(Oled_Display_Info.FLOOR_Device.on_off))
					{
						LCD_CONTROL(1);
						EnterScreenSaveMode();
					}
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,2);
					save_data();															//保存token
					
					arg[0] = 0;
				}
					break;
			}	
		}
		break;
		case 3:																						//新风
		{
			switch(opcode)
			{
				case OPCODE_GENERAL_SWITCH:  																					//空调
				{
					u8 onoff = arg[0];
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新开关状态
						Oled_Display_Info.FAN_Device.on_off = onoff;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);						
						break;
					}						
					if(onoff == ON)
					{
						if(Oled_Display_Info.FAN_Device.on_off == 0)
						{
							Control_OnOff_handler(FAN,1);
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
						}
					}
					else
					{
						if(Oled_Display_Info.FAN_Device.on_off == 1)
						{
							Control_OnOff_handler(FAN,0);
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
							
						}
					}
					arg[0] = 0;
					arg[1] = onoff;
				}
				break;
				case OPCODE_GENERAL_OPERATION_MODE:
				{
					u8 system_mode = arg[0];
					if(Oled_Display_Info.FAN_Device.on_off)
					{
						if(Oled_Display_Info.screen_page != device_type) 
						{
							//仅仅更新状态
							arg[0] = 0;
							arg[1] = system_mode;
							Oled_Display_Info.FAN_Device.system_type = system_mode;
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
							break;
						}
						
						Displayt_System_Mode(system_mode);
						#if DEVICE_TYPE_FAN		
						if(Oled_Display_Info.FAN_Device.system_type != system_mode)
							Fan_PassbyONOFF_By_Mode_Trans(system_mode,1);
						#endif
						Oled_Display_Info.FAN_Device.system_type = system_mode;
						arg[0] = 0;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
					}
					else
						arg[0] = 0xff;
					arg[1] = system_mode;
				}
					break;
				case OPCODE_GENERAL_SET_WIND_SPEED:											//下发控制不需要显示			
				{
					u8 wind_speed = arg[0];
					arg[1] = wind_speed;
					if(Oled_Display_Info.FAN_Device.on_off)
					{
						if(Oled_Display_Info.screen_page != device_type) 
						{
							//仅仅更新状态
							arg[0] = 0;
							arg[1] = wind_speed;
							Oled_Display_Info.FAN_Device.wind_speed = wind_speed;
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
							break;
						}
						
						Oled_Display_Info.FAN_Device.wind_speed = wind_speed;
						#if DEVICE_TYPE_FAN						
						Fan_Speed_Control(wind_speed);
						#endif
						if(Get_Display_Status())
							display_set_temp(1,Oled_Display_Info.FAN_Device.wind_speed,1);
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
						arg[0] = 0;
					}
					else
						arg[0] = 0xff;
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_ERROR_CODE:										
				{
					u8 error_code = arg[0];
					arg[1] = error_code;
					Oled_Display_Info.FAN_Device.error = error_code; 
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);

				}
					break;
				case OPCODE_GENERAL_SET_CHILD_LOCK:
				{
					u8 child_lock = arg[0];
					arg[1] = child_lock;
					if(Oled_Display_Info.screen_page != device_type) 
					{
						//仅仅更新状态
						arg[0] = 0;
						arg[1] = child_lock;
						Oled_Display_Info.FAN_Device.lock_flage = child_lock;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
						break;
					}
					Oled_Display_Info.FAN_Device.lock_flage = child_lock; 
					if((sBacklight.blacklight_flag)&&(Oled_Display_Info.screen_page == 3))
						display_child_lock(child_lock);
					save_data();											//保存token
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_SET_DELAY_OFF_TIME:							
				{
					u8 delay_off_time = arg[0];
					arg[1] = delay_off_time;
					if(Oled_Display_Info.FAN_Device.on_off)
					{
						if(Oled_Display_Info.screen_page != device_type) 
						{
							//仅仅更新状态
							arg[0] = 0;
							arg[1] = delay_off_time;
							Oled_Display_Info.FAN_Device.power_off_time = delay_off_time;
							state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
							break;
						}
						Oled_Display_Info.FAN_Device.power_off_time = delay_off_time; 
						
						if( (Get_Display_Status() ) &&(delay_off_time >0))
							Display_poweroff_time(delay_off_time);
						else if((Get_Display_Status())&&(delay_off_time ==0)&&(Oled_Display_Info.FAN_Device.power_off_flage))
							Delay_OFF_Rel_Display(1,0,NULL,0,0,0);
					
						if(delay_off_time >0)
							Oled_Display_Info.FAN_Device.power_off_flage  = 1;
						else if(Oled_Display_Info.FAN_Device.power_off_flage == 1)
							Oled_Display_Info.FAN_Device.power_off_flage = 0;
						state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
					}
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_SET_SCREEN_SAVE_TIME:						
				{
					u8 screen_save_time = arg[0];
					arg[1] = screen_save_time;
					
					Oled_Display_Info.FAN_Device.screen_save_time = screen_save_time; 
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
					save_data();															//保存token
					
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_SET_FILTER_CLEANING_TIME:						
				{
					u16 filter_wash_time = ((u16)arg[0]) << 8 | arg[1] ;
					arg[1] = filter_wash_time >>8;
					arg[2] = filter_wash_time&0xff;
					
					Oled_Display_Info.FAN_Device.filter_wash_time = filter_wash_time; 
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
					save_data();															//保存token
					
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_CURRENT_REAL_TEMPER:								//不处理当前的温度
				{
//					u16 filter_wash_time = arg[0] <<8 | arg[1] ;
//					arg[1] = filter_wash_time>>8;
//					arg[2] = filter_wash_time&0xff;
//					
//					Oled_Display_Info.Air_Device.filter_wash_time = filter_wash_time; 
//					arg[0] = 0;
	
				}
					break;
				case OPCODE_GENERAL_SET_TEMPER_CALIBRATION:								//温度校准				
				{
					s8 calibration_temp = arg[0] ;
					arg[1] = calibration_temp;
					
					Oled_Display_Info.FAN_Device.real_temperature = Oled_Display_Info.FAN_Device.real_temperature -Oled_Display_Info.FAN_Device.correct_temperature + calibration_temp;
					Oled_Display_Info.FAN_Device.correct_temperature = calibration_temp; 
					save_data();															//保存token
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
					
					arg[0] = 0;
				}
					break;
				case OPCODE_GENERAL_SET_NO_DISTURB_MODE:								
				{
					s8 no_disturb_mode = arg[0] ;
					arg[1] = no_disturb_mode;
					
					Oled_Display_Info.FAN_Device.no_disturb_mode = no_disturb_mode; 
					if(IsLcdEnterScreenSave() &&(Oled_Display_Info.screen_page == device_type)&&no_disturb_mode)
					{
						LCD_CONTROL(0);
						BL55072A_Clear();
					}
					else if(IsLcdEnterScreenSave()&&(no_disturb_mode == 0)&&(Oled_Display_Info.FAN_Device.on_off))
					{
						LCD_CONTROL(1);
						EnterScreenSaveMode();
					}
					state_change_report(OPCODE_GENERAL_REPORT_STATUS,3);
					save_data();															//保存token
					
					arg[0] = 0;
				}
					break;
			}	
		
		}
		break;
		default:
		break;
	
	}
}
//进入本地配置界面
Local_Config_Operation  local_config_operate = {0,0,0,0,2,{3,100},0,0,0};

/************************************************************
设置模式10秒计时
*************************************************************/	
void Setup_Mode_Handle (void)
{
    if (local_config_operate.enter_config_mode)
    {
        local_config_operate.config_time_ms ++;
        if(local_config_operate.config_time_ms >= 1000)
        {
            local_config_operate.config_time_ms = 0;
            local_config_operate.config_time_s ++;
            if(local_config_operate.config_time_s >= 10)
            {
                local_config_operate.config_time_s = 0;
				//退出配置模式
				local_config_operate.enter_config_mode = 0;
				local_config_operate.config_timeout_display = 1;	
            }
        }	
    }	
}
void Reset_Time_Count(void)
{
	local_config_operate.config_time_ms = 0;
	local_config_operate.config_time_s = 0;
}
u8 IsLocalConfigMode(void)
{
	return local_config_operate.enter_config_mode;
}
u8 Key_Operate_Config_Operation(u8 keyid,u8 keyEvent)
{
	static u8 index = 0;
	if( ( (Oled_Display_Info.device_type == 1)&(Oled_Display_Info.Air_Device.on_off == 1))||
		( (Oled_Display_Info.device_type == 2)&(Oled_Display_Info.FLOOR_Device.on_off == 1)) ||
		( (Oled_Display_Info.device_type == 3)&(Oled_Display_Info.FAN_Device.on_off == 1)) )
	{
		return 0;
	}
	if((local_config_operate.enter_config_mode == 0)&&(keyid == 4)&&(keyEvent == 0xb0))
	{
		//进入配置模式
		local_config_operate.enter_config_mode 			= 1;
		local_config_operate.config_page 				= 1;
		local_config_operate.config_page1_func_value 	= local_config_operate.support_function_list[index];
	}
	if(local_config_operate.enter_config_mode == 0)
	{
		index = 0;
		return 0;
	}
	//有按键按下，则重置倒计时时间
	Reset_Time_Count();     
	switch(keyid)
	{
		case 1:										//确认按键
		{
			if((local_config_operate.config_page == 1)&&(keyEvent == 0x80)	)     //下一步
			{
				local_config_operate.config_page = 2;
				switch(local_config_operate.config_page1_func_value)
				{
					#if (DEVICE_TYPE_AIR_CONDITION &&(DEV_TYPE == 1 ))
					case LOCAL_FUNC_FAN_PANEL_SETTING:
					{
						local_config_operate.config_page2_value = 0;	
					}
						break;
					#endif
					case LOCAL_FUNC_CALIBRATE_TEMPER:
						break;
					case LOCAL_FUNC_IS_DISPLAY_CURRENT_TEMPER:
					{
						local_config_operate.config_page2_value = Oled_Display_Info.is_dispaly_cur_temp;				
					}
						break;
					case LOCAL_FUNC_SCREEN_SAVING_TIME:
						break;
					case LOCAL_FUNC_RESET_FACTORY:
						local_config_operate.config_page = 1;
						break;
					default:
						break;
				}
			}
			else if( (local_config_operate.config_page == 1)&&(keyEvent == 0x90))
			{
				if(local_config_operate.config_page1_func_value == LOCAL_FUNC_RESET_FACTORY)
				{
					u8 data = 0;
					//恢复出厂 设备离网
					if(Oled_Display_Info.net_work_flage == IN_LINE)
						Send_Device_Data(0,_OPCODE_SET_NET_STATE,&data,1);	
					//token 值恢复默认
					Oled_Display_Info.is_dispaly_cur_temp = 0;
					Oled_Display_Info.binding_device  = 0;						
					#if DEVICE_TYPE_AIR_CONDITION
						Oled_Display_Info.Air_Device.filter_wash_time = 3000;
						Oled_Display_Info.Air_Device.lock_flage = 0;
						Oled_Display_Info.Air_Device.no_disturb_mode = 0;
						Oled_Display_Info.Air_Device.correct_temperature = 0;
						Oled_Display_Info.Air_Device.screen_save_time = 0;
						Oled_Display_Info.Air_Device.operation_mode = 0;
					#elif DEVICE_TYPE_FLOOR_HEATING
						Oled_Display_Info.FLOOR_Device.lock_flage = 0;
						Oled_Display_Info.FLOOR_Device.no_disturb_mode = 0;
						Oled_Display_Info.FLOOR_Device.correct_temperature = 0;
						Oled_Display_Info.FLOOR_Device.screen_save_time = 0;
					#elif DEVICE_TYPE_FAN
						Oled_Display_Info.FAN_Device.filter_wash_time = 3000;
						Oled_Display_Info.FAN_Device.lock_flage = 0;
						Oled_Display_Info.FAN_Device.no_disturb_mode = 0;
						Oled_Display_Info.FAN_Device.correct_temperature = 0;
						Oled_Display_Info.FAN_Device.screen_save_time = 0;
					#endif
					save_data();
					local_config_operate.enter_config_mode = 0;
					Control_OnOff_handler(Oled_Display_Info.device_type,0);     //显示关
					return 1;	
				}
			}
			else if((local_config_operate.config_page == 2)&&(keyEvent == 0x90)	)								 					//长按完成配置
			{
				switch(local_config_operate.config_page1_func_value)
				{
					#if (DEVICE_TYPE_AIR_CONDITION &&(DEV_TYPE == 1 ))
					case LOCAL_FUNC_FAN_PANEL_SETTING:
					{
						Oled_Display_Info.Air_Device.operation_mode = local_config_operate.config_page2_value;
						save_data();						
					}
						break;
					#endif
					case LOCAL_FUNC_CALIBRATE_TEMPER:
						break;
					case LOCAL_FUNC_IS_DISPLAY_CURRENT_TEMPER:
					{
						Oled_Display_Info.is_dispaly_cur_temp = local_config_operate.config_page2_value;
						save_data();						
					}
						break;
					case LOCAL_FUNC_SCREEN_SAVING_TIME:
						break;
				}
				Control_OnOff_handler(Oled_Display_Info.device_type,0);     //显示关
				return 1;		
			}
			else if(keyEvent == 0xa0)										//抬起退出配置界面
			{
				local_config_operate.enter_config_mode = 0;
				return 1;
			}
			break;
		}
		case 2:	case 3:														//打断
		{
			local_config_operate.enter_config_mode = 0;
			Control_OnOff_handler(Oled_Display_Info.device_type,0);     	//显示关
			return 1;		
		}
		case 4:																//返回上一步
		{
			if((local_config_operate.config_page == 2)&&(keyEvent == 0x80))
			{
				local_config_operate.config_page = 1;
			}
			break;
		}
		case 5:										//+ -
		case 6:	
		{	
			if((local_config_operate.config_page == 1)&&(keyEvent == 0x80))
			{
				if(index <local_config_operate.support_function_len)
				{
					if(keyid == 5 )
					{
						index++;
						if(index == local_config_operate.support_function_len)
							index = 0;
					}
					else
					{
						if(index > 0)
							index--;
						else
							index = local_config_operate.support_function_len - 1; 
					}	
					local_config_operate.config_page1_func_value 	= local_config_operate.support_function_list[index];
				}
			}
			else if((local_config_operate.config_page == 2)&&(keyEvent == 0x80))
			{
				switch(local_config_operate.config_page1_func_value)
				{
					#if (DEVICE_TYPE_AIR_CONDITION &&(DEV_TYPE == 1 ))
					case LOCAL_FUNC_FAN_PANEL_SETTING:
					{
						switch(local_config_operate.config_page2_value)
						{
							case 0:
							{
								if(keyid == 5 )
									local_config_operate.config_page2_value = 1;
								else
									local_config_operate.config_page2_value = 3;
							}
								break;
							case 1:
							{
								if(keyid == 5 )
									local_config_operate.config_page2_value = 2;
								else
									local_config_operate.config_page2_value = 0;
							}
								break;	
							case 2:
							{
								if(keyid == 5 )
									local_config_operate.config_page2_value = 3;
								else
									local_config_operate.config_page2_value = 1;
							}
								break;
							case 3:
							{
								if(keyid == 5 )
									local_config_operate.config_page2_value = 0;
								else
									local_config_operate.config_page2_value = 2;
							}
								break;
							default:
								break;
						}
					}
						break;
					#endif
					case LOCAL_FUNC_CALIBRATE_TEMPER:
						break;
					case LOCAL_FUNC_IS_DISPLAY_CURRENT_TEMPER:
					{
						if(local_config_operate.config_page2_value == 1)
							local_config_operate.config_page2_value = 0;
						else
							local_config_operate.config_page2_value = 1;
					}
						break;
					case LOCAL_FUNC_SCREEN_SAVING_TIME:
						break;
					case LOCAL_FUNC_RESET_FACTORY:
					{
						break;
					}
					
				}
			}
		}
			break;
		default:
			break;
	}
	//显示当前界面
	if(local_config_operate.config_page == 1)
		Display_Middle_Digtal(0X07,local_config_operate.config_page1_func_value);
	else if(local_config_operate.config_page == 2)
		Display_Middle_Digtal(0X03,local_config_operate.config_page2_value);
	return 1;
}
u16  gSetNetScanTime  = 20;
u16 GetNetScanTime( void )
{
    return gSetNetScanTime;
}
void SetNetScanTime(u16 uSetkeyScanTime)
{
    gSetNetScanTime = uSetkeyScanTime;
}
/***
OTA 指示灯控制
***/
void NetIndicatorOptDriver(u8 onoff)
{
	LCDShowTemp_state_t.LCD_place = ZIGBEE_NET_CAHR_DISPLAY;
	if(onoff == 1)
		LCDShowTemp_state_t.LCD_state = ON;
	else	
		LCDShowTemp_state_t.LCD_state = OFF;
	LcdShowCTR(LCDShowTemp_state_t);
}
u8  kNetIndicatorIsBlinking(void)
{
	return (g_NetOptIndicator[0].blink_cnt>0);
}
u8  kLedIsBlinking(u8 led_id)
{
	return (g_NetOptIndicator[led_id].blink_cnt>0);
}
u8  kAllLedIsBlinking(void)
{
	return (g_NetOptIndicator[7].blink_cnt>0);
}
/*	DESP: Indicator lamp behavior control interface.
	Auth: lmm_frc.20201218.
id = 0,网络图标
id 1-6 指示灯1-6
id 7   所有指示灯
*/
void kNetIndicatorOptTrigger(uint8_t id, uint32_t duration_on_ms, uint32_t duration_off_ms, uint32_t times, u8 start, u8 end )
{
	g_NetOptIndicator[id].onDuration  = duration_on_ms / SysIndicatorScanTimer;
	g_NetOptIndicator[id].offDuration = duration_off_ms/ SysIndicatorScanTimer;

	g_NetOptIndicator[id].start = start;
	g_NetOptIndicator[id].end = end;

	if( g_NetOptIndicator[id].start == ON ) {
		if(id == 0)
			NetIndicatorOptDriver(ON);
		else
			LED_ONOFF(id,ON);
		
		g_NetOptIndicator[id].onCounter  = g_NetOptIndicator[id].onDuration;
	}else {
		if(id == 0)
			NetIndicatorOptDriver(OFF);
		else
			LED_ONOFF(id,OFF);
		g_NetOptIndicator[id].offCounter = g_NetOptIndicator[id].offDuration;
	}

	g_NetOptIndicator[id].blink_cnt   = times;

	//modify by maozj 20200302
	if (g_NetOptIndicator[id].blink_cnt != 0){
		SetkeyScanTime(SysIndicatorScanTimer);						//重置时间
	}
}
/*	DESP: Led module action detection task callback interface.
 * 	Auth: dingmz_frc.20191107.
 * */
void kLedModuleActionDetectCallback(void )
{
	if(!GetNetScanTime())
    {
		u8 i = 0;
        SetNetScanTime(SysIndicatorScanTimer);
		// PROCESS...
		for(i = 0;i<8;i++)
		{
			if( g_NetOptIndicator[i].blink_cnt > 0 ) {

				if( g_NetOptIndicator[i].onCounter > 0 ) {
					if((--g_NetOptIndicator[i].onCounter) == 0) {
						// 检测闪烁次数递减
						if( g_NetOptIndicator[i].start == OFF ) {
							if(--g_NetOptIndicator[i].blink_cnt == 0 ) {
								if(i == 0)
									NetIndicatorOptDriver(g_NetOptIndicator[i].end);
								else
									LED_ONOFF(i,g_NetOptIndicator[i].end);
							}
						}

						if( g_NetOptIndicator[i].blink_cnt > 0 ) {
							if(i == 0)
								NetIndicatorOptDriver(OFF);
							else
								LED_ONOFF(i,OFF);
							g_NetOptIndicator[i].offCounter = g_NetOptIndicator[i].offDuration;
						}
					}
				}else {
					if((--g_NetOptIndicator[i].offCounter) == 0) {
						// 检测闪烁次数递减
						if(g_NetOptIndicator[i].start == ON ) {
							if(--g_NetOptIndicator[i].blink_cnt == 0 ) {
								if(i == 0)
									NetIndicatorOptDriver(g_NetOptIndicator[i].end);
								else
									LED_ONOFF(i,g_NetOptIndicator[i].end);
							}
						}

						if( g_NetOptIndicator[i].blink_cnt > 0 ) {
							if(i == 0)
								NetIndicatorOptDriver(ON);
							else
								LED_ONOFF(i,ON);
							g_NetOptIndicator[i].onCounter = g_NetOptIndicator[i].onDuration;
						}
					}
				}
			}
		}
	}
}
