#include <stdio.h>
#include "mini58series.h"
#include "BL55072A.h"
#include "control_comm.h"
#include "i2c_software_gpio.h"
								
u8 g_u8slaver_addr ;

u8 Display_Num[] = {DisplayChar0,DisplayChar1,DisplayChar2,DisplayChar3,DisplayChar4,DisplayChar5,\
					DisplayChar6,DisplayChar7,DisplayChar8,DisplayChar9,DisplayCharA,DisplayCharB,\
					0XFF,0XFF,DisplayCharE,DisplayCharF,DisplayChar4,DisplayCharr,DisplayCharL,DisplayCharo};

					
					
					
Lcd_Status_Info_t LCDLockIconCTR_t = 
{
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter
};

Lcd_Status_Info_t LCDNetworkIconCTR_t = 
{
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter
};

Lcd_Status_Info_t LCDPowerOFFStartIconCTR_t = 
{
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter
};
Lcd_Status_Info_t LCDWindDirectIconCTR_t = 
{
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter
};
Lcd_Status_Info_t LCDWindSpeedIconCTR_t = 
{
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter
};
Lcd_Status_Info_t LCDCalibrateTemperSettingIconCTR_t = 
{
    (u8)LCDDisplayInvalidParameter,
    (u16)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter
};

Lcd_Status_Info_t LCDAutoSystemModeSettingIconCTR_t = 
{
    (u8)LCDDisplayInvalidParameter,
    (u16)LCDDisplayInvalidParameter,
    (u8)LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter,
    LCDDisplayInvalidParameter
};

u16 guSetLCDShowTime = SysLCDShowTimer;

#if 1 // add by dingmz_frc.20201215
extern u8 g_u8Temp_Buffer[];
extern u8 g_u8Temp_Length;
#endif

void PWM_init(void)
{
    // PWM0 frequency is 100Hz, duty 30%,
    PWM_ConfigOutputChannel(PWM, 0, 1000, 0);
    PWM_EnableDeadZone(PWM, 0, 1);
	
    // 使能PWM输出
    PWM_EnableOutput(PWM, BIT0);

    PWM_Start(PWM, BIT0);
}
/*
控制液晶显示速度
*/
void SetLCDShowTime(u16 uSetLCDShowTime)
{
    guSetLCDShowTime = uSetLCDShowTime;
}

u16 GetLCDShowTime( void )
{
    return guSetLCDShowTime;
}					
					
void BL55072A_Init(uint8_t slaver_addr,u32 freq)
{
	u8 err 				= 0xff;
	//u8 Send_Buffer[10] 	= {0};
	//u8 length  			= 0;
	
	g_u8slaver_addr = slaver_addr;
	I2C_SW_Open(freq);
	CLK_SysTickDelay(5000);      //delay 5ms
	
	g_u8Temp_Length = 0;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_APCTL_OFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET_RST;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
	
	err = I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
	
	//printf("Bl55072A init err = (%d),length = (%d)\r\n", err, length);
}
void BL55072A_DisplayON(void)
{
	//uint8_t buffer[20] = {0};
	//uint8_t length = 0;

	g_u8Temp_Length = 0;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_APCTL_OFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_BLKCTL_OFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFC;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON & 0x7F;

	I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
	//printf("BL55072A Display ON err = (%d),length = (%d)\r\n", err, length);
}
void BL55072A_Clear(void)
{
	//uint8_t buffer[20] = {0};
	//uint8_t length = 0;

	g_u8Temp_Length = 0;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_BLKCTL_OFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFC;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ADSET;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0x00;

	I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
	//printf("BL55072A Display Test err = (%d),length = (%d)\r\n", err, length);
}
void BL55072A_DisplayALL(void)
{
	//u8 Send_Buffer[20] = {0};
	//u8 length = 0;

	g_u8Temp_Length = 0;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_DISCTL_PSM1;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_BLKCTL_OFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFE;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_MODESET_ON;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ICSET;
	g_u8Temp_Buffer[g_u8Temp_Length++] = BL55072A_CMD_ADSET;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;
	g_u8Temp_Buffer[g_u8Temp_Length++] = 0xFF;

	I2C_SW_Send(g_u8slaver_addr, g_u8Temp_Buffer, g_u8Temp_Length);
	
	//printf("BL55072A Display Test err = (%d),length = (%d)\r\n", err, length);
}
static u8  Buffer_Temp[5] = {0};

u8 BL55072A_ReadByte(u8 addr)
{
	static u8 tmp = 0;
	
	memset(Buffer_Temp,0,sizeof(Buffer_Temp));
	Buffer_Temp[0] = BL55072A_CMD_ICSET;
	Buffer_Temp[1] = BL55072A_CMD_ADSET | addr | 0x80;	//cmd end
	I2C_SW_Send(g_u8slaver_addr, Buffer_Temp, 2);
	I2C_SW_Get_Without_Delay(g_u8slaver_addr,(u8 *)&tmp,1);
	return (tmp&0xff);
}
void BL55072A_DisplayGeneral(u8 addr,u8 control_bits,u8 display_bits)
{
	static  u8 Data = 0;
	static  u8 i = 0;
	static  u8 tmp = 0;
	memset(Buffer_Temp,0,sizeof(Buffer_Temp));
	i = Data  = 0;
	tmp =  BL55072A_ReadByte(addr);
	//printf("BL55072A_DisplayGeneral,Process Before TMP DATA = %x\r\n", tmp);
	Buffer_Temp[0] = BL55072A_CMD_ICSET;
	Buffer_Temp[1] = BL55072A_CMD_ADSET | addr;	//cmd end
	
	for(i = 0;i<4;i++)
	{
		if(control_bits&(1<<i))
		{
			if(display_bits&(1<<i)){
				Data |= 1<<i;
			}
			else{
				Data &= ~(1<<i);
			}
		}
		else
		{
			Data |= ( (tmp>>4)&(1<<i) );
		}
	}
	tmp = ((tmp&0x0f) | (Data<<4) );
	//printf("BL55072A_DisplayGeneral,Process After TMP=%x, DATA = %x\r\n",tmp, Data);
	Buffer_Temp[2] = tmp;	//cmd end
	I2C_SW_Send(g_u8slaver_addr, Buffer_Temp, 3);	
	//printf("BL55072A_DisplayGeneral,err = (%d),length = (%d)\r\n", err, length);
}

/*
手动模式外圈
*/
void LcdControlS1( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x08, 0x00 );
}
/*
手动模式内圈
*/
void LcdControlS2( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x04, 0x00 );
}
/*
循环模式外圈
*/
void LcdControlS3( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x02, 0x02 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x02, 0x00 );
}
/*
循环模式内圈
*/
void LcdControlS4( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x01, 0x01 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG0, 0x01, 0x00 );
}
/*
地暖外圈
*/
void LcdControlS5( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x01, 0x01 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x01, 0x00 );
}
/*
地暖内圈
*/
void LcdControlS6( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x02, 0x02 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x02, 0x00 );
}
/*
空调外圈
*/
void LcdControlS7( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x04, 0x00 );
}
/*
空调内圈
*/
void LcdControlS8( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG7, 0x08, 0x00 );
}
/*
新风外圈
*/
void LcdControlS9( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG8, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG8, 0x08, 0x00 );
}
/*
新风内圈
*/
void LcdControlS10( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG10, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG10, 0x08, 0x00 );
}
/*
定时图标
*/
void LcdControlS12( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x08, 0x00 );
}
u8 GetS12State(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG20);

	return (tmp&0x80);
}
/*
自动模式外圈
*/
void LcdControlS13( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x04, 0x00 );
}
/*
自动模式内圈
*/
void LcdControlS14( s16 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x08, 0x00 );
}

u8   GetS14State(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG21);

	return (tmp&0x80);
}
/*
当前温度字体图标
*/
void LcdControlS15( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x01, 0x01 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x01, 0x00 );
}
/*
设定时长字体图标
*/
void LcdControlS16( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x02, 0x02 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG21, 0x02, 0x00 );
}
/*
小时字符图标
*/
void LcdControlS17( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG1, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG1, 0x08, 0x00 );
}
/*
上方摄氏度图标
*/
void LcdControlS18( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG3, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG3, 0x08, 0x00 );
}
/*
组网图标
*/
void LcdControlS19( s16 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x04, 0x00 );
}
u8 GetS19State(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG20);

	return (tmp&0x40);
}
/*
童锁图标
*/
void LcdControlS20( s16 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x02, 0x02 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x02, 0x00 );
}
u8 GetS20State(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG20);

	return (tmp&0x20);
}
/*
中间摄氏度图标
*/
void LcdControlS21( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x01, 0x01 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG20, 0x01, 0x00 );
}
/*
制热外圈图标
*/
void LcdControlS22( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x04, 0x00 );
}
/*
制热内圈图标
*/
void LcdControlS23( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x08, 0x00 );
}
/*
除湿外圈图标
*/
void LcdControlS24( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x01, 0x01 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x01, 0x00 );
}
/*
除湿内圈图标
*/
void LcdControlS25( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x02, 0x02 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG17, 0x02, 0x00 );
}
/*
制冷外圈图标
*/
void LcdControlS26( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x02, 0x02 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x02, 0x00 );
}
/*
制冷内圈图标
*/
void LcdControlS27( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x01, 0x01 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x01, 0x00 );
}
/*
通风外圈图标
*/
void LcdControlS28( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x04, 0x00 );
}
/*
通风内圈图标
*/
void LcdControlS29( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG18, 0x08, 0x00 );
}
/*
睡眠外圈图标
*/
void LcdControlS30( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG19, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG19, 0x04, 0x00 );
}
/*
睡眠内圈图标
*/
void LcdControlS31( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG19, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG19, 0x08, 0x00 );
}

/*
风向上图标
*/
void LcdControlS32( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x04, 0x04 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x04, 0x00 );
}
/*
风向中图标
*/
void LcdControlS33( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x02, 0x02 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x02, 0x00 );
}
/*
风向下图标
*/
void LcdControlS34( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x01, 0x01 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x01, 0x00 );
}
/*
风向字体图标
*/
void LcdControlS35( s16 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG14, 0x08, 0x00 );
}
u8 GetS35State(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG14);

	return (tmp&0x80);
}
/*
风速字体图标
*/
void LcdControlS36( s16 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG15, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG15, 0x08, 0x00 );
}
u8 GetS36State(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG15);

	return (tmp&0x80);
}

/*
显示中间小数点图标
*/
void LcdControlP0( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG12, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG12, 0x08, 0x00 );
}
/*
显示上方小数点图标
*/
void LcdControlP1( u8 uState )
{
	if(uState)
		BL55072A_DisplayGeneral( BL55072A_SEG5, 0x08, 0x08 );
	else
		BL55072A_DisplayGeneral( BL55072A_SEG5, 0x08, 0x00 );
}


void LcdControlSetting(u8 uADD, u8 uNumber  )
{
	u8 High_Byte,Low_Byte;
	if(uNumber>sizeof(Display_Num))
		return;
	
	High_Byte = (Display_Num[uNumber] >>4);
	Low_Byte  = (Display_Num[uNumber]&0x0f);
	BL55072A_DisplayGeneral( uADD, 0x07, High_Byte );
	BL55072A_DisplayGeneral( uADD+1, 0x0F, Low_Byte );
}
void DelayPowerOffControlSetting(s16 time)
{
	u8  temp = 0 ;
	if(time == 0x7fff) 		//show null 
	{
		 BL55072A_DisplayGeneral( BL55072A_SEG1, 0x07, 0 );
		 BL55072A_DisplayGeneral( BL55072A_SEG2, 0x0F, 0 );
		
		 BL55072A_DisplayGeneral( BL55072A_SEG3, 0x07, 0 );
		 BL55072A_DisplayGeneral( BL55072A_SEG4, 0x0F, 0 );
		
		 LcdControlP1(0);
		
		 BL55072A_DisplayGeneral( BL55072A_SEG5, 0x07, 0 );
		 BL55072A_DisplayGeneral( BL55072A_SEG6, 0x0F, 0 );
	}
	else{
		temp = time/100;
		LcdControlSetting(BL55072A_SEG1,temp);
		
		temp = (time/10) %10;
		LcdControlSetting(BL55072A_SEG3,temp);
		
		LcdControlP1(1);
		
		temp = time %10;
		LcdControlSetting(BL55072A_SEG5,temp);	
	}
}
u8 DelayPowerOffGetStat(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG5);

	return (tmp&0x80);
}
void CalibrateTemperControlSetting(s16 temper)
{
	u8  temp = 0 ;
	if(temper == 0x7fff) 							//show null 
	{
		 BL55072A_DisplayGeneral( BL55072A_SEG8, 0x07, 0 );
		 BL55072A_DisplayGeneral( BL55072A_SEG9, 0x0F, 0 );
		
		 BL55072A_DisplayGeneral( BL55072A_SEG10, 0x07, 0 );
		 BL55072A_DisplayGeneral( BL55072A_SEG11, 0x0F, 0 );
		
		 LcdControlP0(0);
		
		 BL55072A_DisplayGeneral( BL55072A_SEG12, 0x07, 0 );
		 BL55072A_DisplayGeneral( BL55072A_SEG13, 0x0F, 0 );
	}
	else if(temper >=0){
		temp = temper/100;
		LcdControlSetting(BL55072A_SEG8,temp);
		
		temp = (temper/10) %10;
		LcdControlSetting(BL55072A_SEG10,temp);
		
		LcdControlP0(1);
		
		temp = temper %10;
		LcdControlSetting(BL55072A_SEG12,temp);	
	}
	else if(temper<0){
		
		//显示负号
		BL55072A_DisplayGeneral( BL55072A_SEG8, 0x07, 0x02 );
		BL55072A_DisplayGeneral( BL55072A_SEG8+1, 0x0F, 0x00 );

		
		temp = ((65536 - temper)/10) %10;
		LcdControlSetting(BL55072A_SEG10,temp);
		
		LcdControlP0(1);
		
		temp = (65536 - temper) %10;
		LcdControlSetting(BL55072A_SEG12,temp);	
	}
}
u8 CalibrateTemperGetStat(void)
{
	u8 tmp = BL55072A_ReadByte(BL55072A_SEG12);

	return (tmp&0x80);
}
void LcdShowCTR( Lcd_Status_Info_t LCDShowTemp_t )
{
    switch( LCDShowTemp_t.LCD_place )
     {
         case SYSTEM_MANUAL_OUTLINE_DISPLAY:
         
             LcdControlS1( LCDShowTemp_t.LCD_state );
             break;   
             
         case SYSTEM_MANUAL_CHAR_DISPLAY: 
             LcdControlS2( LCDShowTemp_t.LCD_state );
             break;  
             
         case SYSTEM_ROLLING_OUTLINE_DISPLAY:
             LcdControlS3( LCDShowTemp_t.LCD_state );
             break; 
             
         case SYSTEM_ROLLING_CHAR_DISPLAY:
             LcdControlS4( LCDShowTemp_t.LCD_state );
             break;         
    
         case SYSTEM_AUTO_OUTLINE_DISPLAY: 
             LcdControlS13( LCDShowTemp_t.LCD_state );
             break;  
             
         case SYSTEM_AUTO_CHAR_DISPLAY:
			 if( FLASHING == LCDShowTemp_t.LCD_state )
             {
                 LCDAutoSystemModeSettingIconCTR_t = LCDShowTemp_t;
             }
             else
			 {
				 LCDAutoSystemModeSettingIconCTR_t = LCDShowTemp_t;
				 LcdControlS14( LCDShowTemp_t.LCD_state );
			 }
             break; 
             
         case DEVICE_TYPE_HEATING_OUTLINE_DISPLAY:
             LcdControlS5( LCDShowTemp_t.LCD_state );
             break;
		 
		 case DEVICE_TYPE_HEATING_CHAR_DISPLAY:
             LcdControlS6( LCDShowTemp_t.LCD_state );
             break;
		 
         case DEVICE_TYPE_AIRCONDITION_OUTLINE_DISPLAY:
             LcdControlS7( LCDShowTemp_t.LCD_state );
             break;
		 
		 case DEVICE_TYPE_AIRCONDITION_CHAR_DISPLAY:
             LcdControlS8( LCDShowTemp_t.LCD_state );
             break; 
		 
		 case DEVICE_TYPE_FAN_OUTLINE_DISPLAY:
             LcdControlS9( LCDShowTemp_t.LCD_state );
             break;
		 
		 case DEVICE_TYPE_FAN_CHAR_DISPLAY:
             LcdControlS10( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SETTING_TIMER_DISPLAY:
             LcdControlS12( LCDShowTemp_t.LCD_state );
             break;
		 
		 case CURRENT_TEMPER_CHAR_DISPLAY:
             LcdControlS15( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SETTING_TIMER_CHAR_DISPLAY:
             LcdControlS16( LCDShowTemp_t.LCD_state );
             break;
		 
		 case MIDDLE_TEMPER_UNIT_DISPLAY:
             LcdControlS21( LCDShowTemp_t.LCD_state );
             break; 
		 
		 case SYSTEM_HEATING_OUTLINE_DISPLAY:
             LcdControlS22( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_HEATING_CHAR_DISPLAY:
             LcdControlS23( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_DRY_OUTLINE_DISPLAY:
             LcdControlS24( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_DRY_CHAR_DISPLAY:
             LcdControlS25( LCDShowTemp_t.LCD_state );
             break;		
		 
		 case SYSTEM_COOL_OUTLINE_DISPLAY:
             LcdControlS26( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_COOL_CHAR_DISPLAY:
             LcdControlS27( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_FAN_OUTLINE_DISPLAY:
             LcdControlS28( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_FAN_CHAR_DISPLAY:
             LcdControlS29( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_SLEEP_OUTLINE_DISPLAY:
             LcdControlS30( LCDShowTemp_t.LCD_state );
             break;
		 
		 case SYSTEM_SLEEP_CHAR_DISPLAY:
             LcdControlS31( LCDShowTemp_t.LCD_state );
             break;	 
		 
		 case WIND_DIRECTION_UP_DISPLAY:
             LcdControlS32( LCDShowTemp_t.LCD_state );
             break;
		 
		 case WIND_DIRECTION_MIDDLE_DISPLAY:
             LcdControlS33( LCDShowTemp_t.LCD_state );
             break;
		 
		 case WIND_DIRECTION_DOWN_DISPLAY:
             LcdControlS34( LCDShowTemp_t.LCD_state );
             break;
		 
		 case WIND_DIRECT_CHAR_DISPLAY:
			 if( FLASHING == LCDShowTemp_t.LCD_state )
             {
                 LCDWindDirectIconCTR_t = LCDShowTemp_t;
             }
             else
			 {
				LCDWindDirectIconCTR_t = LCDShowTemp_t;
				LcdControlS35( LCDShowTemp_t.LCD_state );
			 }
             break;
		 
		 case WIND_SPEED_CHAR_DISPLAY:
			if( FLASHING == LCDShowTemp_t.LCD_state )
             {
                 LCDWindSpeedIconCTR_t = LCDShowTemp_t;
             }
             else
			 {
				LCDWindSpeedIconCTR_t = LCDShowTemp_t;
				LcdControlS36( LCDShowTemp_t.LCD_state );
			 }
             break;
		 
		 case MIDDLE_POINT_DISPLAY:
             LcdControlP0( LCDShowTemp_t.LCD_state );
             break;
		 
		 case UPPER_POINT_DISPLAY:
             LcdControlP1( LCDShowTemp_t.LCD_state );
             break;
		 
		 case H_CHAR_DISPLAY:
			 LcdControlS17( LCDShowTemp_t.LCD_state );
             break;
		 case UPPER_TEMPER_UNIT_DISPLAY:
             LcdControlS18( LCDShowTemp_t.LCD_state );
             break;
		 case ZIGBEE_NET_CAHR_DISPLAY:
		 {
			 if( FLASHING == LCDShowTemp_t.LCD_state )
             {
                 LCDNetworkIconCTR_t = LCDShowTemp_t;
             }
             else
			 {
				LCDNetworkIconCTR_t = LCDShowTemp_t;
				LcdControlS19( LCDShowTemp_t.LCD_state );
			 }
		 }
             break; 
		 case CHILD_LOCK_DISPLAY:
		 {
			 if( FLASHING == LCDShowTemp_t.LCD_state )
             {
                 LCDLockIconCTR_t = LCDShowTemp_t;
             }
             else
			 {
				 LCDLockIconCTR_t = LCDShowTemp_t;
				 LcdControlS20( LCDShowTemp_t.LCD_state );
			 }
		 }
             break;
         case SET_MIDDLE_DIGITRON_DISPLAY_01: 
			 if(LCDShowTemp_t.LCD_state == ON)
			 {
				 if(  (  LCDShowTemp_t.LCD_code_data < 20 ) )
				 {
					 LcdControlSetting(BL55072A_SEG8,LCDShowTemp_t.LCD_code_data);
				 }
             }
			 else
			 {
				 BL55072A_DisplayGeneral( BL55072A_SEG8, 0x07, 0 );
				 BL55072A_DisplayGeneral( BL55072A_SEG9, 0x0F, 0 );
			 }
             break;  
             
         case SET_MIDDLE_DIGITRON_DISPLAY_02: 
			 if(LCDShowTemp_t.LCD_state == ON)
			 {
				 if(  (LCDShowTemp_t.LCD_code_data <20 ) )
				 {
					 LcdControlSetting(BL55072A_SEG10,LCDShowTemp_t.LCD_code_data);
				 }
			 }
			 else
			 {
				 BL55072A_DisplayGeneral( BL55072A_SEG10, 0x07, 0 );
				 BL55072A_DisplayGeneral( BL55072A_SEG11, 0x0F, 0 );
			 }
             break;  
             
         case SET_MIDDLE_DIGITRON_DISPLAY_03: 
			 if(LCDShowTemp_t.LCD_state == ON)
			 {
				 if(  (LCDShowTemp_t.LCD_code_data <20 ) )
				 {
					LcdControlSetting(BL55072A_SEG12,LCDShowTemp_t.LCD_code_data);
				 }
			 }
			 else
			 {
				 BL55072A_DisplayGeneral( BL55072A_SEG12, 0x07, 0 );
				 BL55072A_DisplayGeneral( BL55072A_SEG13, 0x0F, 0 );
			 }
             break;        
    
         case SET_UPPER_DIGITRON_DISPLAY_01:
			 if(LCDShowTemp_t.LCD_state == ON)
			 {
				 if(  (LCDShowTemp_t.LCD_code_data <20 ) )
				 {
					LcdControlSetting(BL55072A_SEG1,LCDShowTemp_t.LCD_code_data);
				 }
             }
			 else
			 {
				 BL55072A_DisplayGeneral( BL55072A_SEG1, 0x07, 0 );
				 BL55072A_DisplayGeneral( BL55072A_SEG2, 0x0F, 0 );
			 }
             break;
             
         case SET_UPPER_DIGITRON_DISPLAY_02: 
			 if(LCDShowTemp_t.LCD_state == ON)
			 {
				 if(  (LCDShowTemp_t.LCD_code_data <20 ) )
				 {
					LcdControlSetting(BL55072A_SEG3,LCDShowTemp_t.LCD_code_data);
				 }
			 }
			 else
			 {
				 BL55072A_DisplayGeneral( BL55072A_SEG3, 0x07, 0 );
				 BL55072A_DisplayGeneral( BL55072A_SEG4, 0x0F, 0 );
			 }
             break;
             
         case SET_UPPER_DIGITRON_DISPLAY_03: 
			 if(LCDShowTemp_t.LCD_state == ON)
			 {
				 if(  (LCDShowTemp_t.LCD_code_data <20 ) )
				 {
					LcdControlSetting(BL55072A_SEG5,LCDShowTemp_t.LCD_code_data);
				 }
			 }
			 else
			 {
				 BL55072A_DisplayGeneral( BL55072A_SEG5, 0x07, 0 );
				 BL55072A_DisplayGeneral( BL55072A_SEG6, 0x0F, 0 );
			 }
             break; 
		case FAN_SPEED_DIGITRON_DISPLAY_01:
			 if(LCDShowTemp_t.LCD_state == ON)
			 {				 
				 if(  (LCDShowTemp_t.LCD_code_data <20 ) )
				 {
					LcdControlSetting(BL55072A_SEG15,LCDShowTemp_t.LCD_code_data);
				 }
			 }
			 else
			 {
				 BL55072A_DisplayGeneral( BL55072A_SEG15, 0x07, 0 );
				 BL55072A_DisplayGeneral( BL55072A_SEG16, 0x0F, 0 );
			 }
			 break;
		case DELAY_OFF_TIME_DISPLAY:
			 if( FLASHING == LCDShowTemp_t.LCD_state )
             {
                 LCDPowerOFFStartIconCTR_t = LCDShowTemp_t;
             }
             else
			 {
				 LCDPowerOFFStartIconCTR_t = LCDShowTemp_t;
				 if(LCDShowTemp_t.LCD_state == ON)
					DelayPowerOffControlSetting( LCDShowTemp_t.LCD_code_data );
				 else
					 DelayPowerOffControlSetting( 0X7fff );
				 LCDPowerOFFStartIconCTR_t.LCD_display_count = 0;	
			 }
             break;			     
		case CALIBRATE_TEMPER_DISPLAY:
			 if( FLASHING == LCDShowTemp_t.LCD_state )
             {
                 LCDCalibrateTemperSettingIconCTR_t = LCDShowTemp_t;
             }
             else
			 {
				 LCDCalibrateTemperSettingIconCTR_t = LCDShowTemp_t;
				 if(LCDShowTemp_t.LCD_state == ON)
					CalibrateTemperControlSetting( LCDShowTemp_t.LCD_code_data );
				 else
					CalibrateTemperControlSetting( 0X7fff );
					
			 }
             break;	
         default: 
             break;
    
     }

}

void LcdShowFlashingCTR( Lcd_Status_Info_t *LCDIconFlashingCTR_t, u16 *IconDisplayTimerTemp,void LcdControlPlace(s16 ), u8 GetPlaceState(void) )
{

    if( FLASHING == ( LCDIconFlashingCTR_t->LCD_state ))
    {
        //DBG_PRINT(" LCDNetworkIconCTR_t.LCD_display_timer = %d\n", LCDNetworkIconCTR_t.LCD_display_timer );
        if( 
            ( LCDDisplayInvalidParameter != LCDIconFlashingCTR_t->LCD_display_timer )
          &&( NULL != LCDIconFlashingCTR_t->LCD_display_timer )
           )
        {
            //DBG_PRINT(" LCDNetworkIconCTR_t.LCD_display_timer = %d\n", LCDNetworkIconCTR_t.LCD_display_timer );
            //DBG_PRINT(" NetworkIconDisplayTimer = %d\n", NetworkIconDisplayTimer );
            if( ( *IconDisplayTimerTemp ) == ( LCDIconFlashingCTR_t->LCD_display_timer ) )
            {
                ( *IconDisplayTimerTemp ) = NULL;
                
                //DBG_PRINT("LCDNetworkIconCTR_t.LCD_display_count = %d\n", LCDNetworkIconCTR_t.LCD_display_count );
                if( LCDIconFlashingCTR_t->LCD_display_count  )                 
                {
                    if( LCDDisplayInvalidParameter != LCDIconFlashingCTR_t->LCD_display_count ) 
						LCDIconFlashingCTR_t->LCD_display_count--;
					if( (LcdControlPlace != DelayPowerOffControlSetting)&&(LcdControlPlace != CalibrateTemperControlSetting) ) 		//处理小数点闪烁
						LcdControlPlace( !GetPlaceState() );
					else																											//处理延时关机，温度校准闪烁
					{
						if(GetPlaceState())
						{
							LcdControlPlace(0x7fff);	
						}
						else
						{
							LcdControlPlace(LCDIconFlashingCTR_t->LCD_code_data);					
						}				
					
					}
                    //printf("t = %d\n", LCDNetworkIconCTR_t.LCD_display_count );
                }
            }
            else
            {
                ( *IconDisplayTimerTemp )++;
            }
    
        }
    }
	else{
		 ( *IconDisplayTimerTemp ) = NULL;
	}
}

u8 IsPowerOffFlashing(void)
{
	return ((LCDPowerOFFStartIconCTR_t.LCD_display_count>0)&&(LCDPowerOFFStartIconCTR_t.LCD_display_count != LCDDisplayInvalidParameter) );
}
void LcdShowRunningAll( void )
{
    static u16 NetworkIconDisplayTimer       = NULL;
    static u16 PowerOFFStartIconDisplayTimer = NULL;
    static u16 LockIconDisplayTimer          = NULL;
    static u16 WindDirectIconDisplayTimer    = NULL;
	static u16 WindSpeedIconDisplayTimer     = NULL;
	static u16 CalibrateTemperIconDisplayTimer = NULL;
	static u16 AutoSystemModeIconDisplayTimer = NULL;
	
    if( !GetLCDShowTime() ) 
    {
        SetLCDShowTime( SysLCDShowTimer );


        ///*  定时 图标显示控制        */
        LcdShowFlashingCTR( &LCDPowerOFFStartIconCTR_t, &PowerOFFStartIconDisplayTimer, DelayPowerOffControlSetting, DelayPowerOffGetStat );
		
		///*  温度校准 图标显示控制        */
        LcdShowFlashingCTR( &LCDCalibrateTemperSettingIconCTR_t, &CalibrateTemperIconDisplayTimer, CalibrateTemperControlSetting, CalibrateTemperGetStat );
		
        ///*  童锁 图标显示控制        */
        LcdShowFlashingCTR( &LCDLockIconCTR_t, &LockIconDisplayTimer, LcdControlS20, GetS20State );
        
        ///*  zigbee 图标显示控制      */
        LcdShowFlashingCTR( &LCDNetworkIconCTR_t, &NetworkIconDisplayTimer, LcdControlS19, GetS19State);
		
		///*  风向字符 图标显示控制      */
        LcdShowFlashingCTR( &LCDWindDirectIconCTR_t, &WindDirectIconDisplayTimer, LcdControlS35, GetS35State);
		
		///*  风速字符 图标显示控制      */
        LcdShowFlashingCTR( &LCDWindSpeedIconCTR_t, &WindSpeedIconDisplayTimer, LcdControlS36, GetS36State );
		
		///*  自动字符 图标显示控制      */
        LcdShowFlashingCTR( &LCDAutoSystemModeSettingIconCTR_t, &AutoSystemModeIconDisplayTimer, LcdControlS14, GetS14State );	
    }
}

