#include "Dwin.h"
#include "usart.h"
#include <stdio.h>
#include <string.h>
#include "CollectMaster485.h"
#include "TerminalSlave485.h"
#include "ScreenMaster485.h"
#include "Elec_Seal.h"
#include "main.h"
#include "KeySlave485.h"

#include "cmsis_os.h"

Run_mode_key Run_mode_key_info;
uint8_t Lcd_sleep_flag =2;//1休眠状态  3 唤醒状态   2执行唤醒
uint8_t DateDwin[8];
uint8_t time_Set_Dwin[14]={0x5A, 0xA5, 0x0B ,0x82 ,0x00 ,0x9C ,0x5A ,0xA5 ,0x13 ,0x05 ,0x1B ,0x0b ,0x1b ,0x19};

SemaphoreHandle_t xSemaphore = NULL;
int Init_Dwin_Signal(void)
{
	xSemaphore = xSemaphoreCreateMutex();
	if(xSemaphore==NULL)
	{
		return 0;
	}
	usart3_rx_flag=1;
	return 1;
}


/******************************************************************************
写8位数据
输入：写入地址：addr16，  写入数据：data16
输出返回：无	
5A A5 04 83 00 10 04

将会收到：            年 月 日 星期；时，分，秒.
5A A5 0C 83 00 10 04 15 01 06 03 14 28 11 00 
5A A5 0C 83 00 10 04 15 01 07 04 15 1C 30 00 
******************************************************************************/
void GetDateFromDwin(void)
{ 
	uint8_t TxDwinDataBuf[7];
    TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x04;								
	TxDwinDataBuf[3]=0x83;
	TxDwinDataBuf[4]=0x00;
	TxDwinDataBuf[5]=0x10;
	TxDwinDataBuf[6]=0x04;
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 5) == pdFALSE)
	{
		return;
	}
		ScreenMaster485_Send_Data(TxDwinDataBuf,7);
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );
	//HAL_Delay(20);//
}


/******************************************************************************
写8位数据
输入：写入地址：addr16，  写入数据：data16
输出返回：无	
5A A5       05   82   10 01     00 03
******************************************************************************/
void WrDwinCmd8(uint16_t addr16,uint8_t data8)
{
	uint8_t TxDwinDataBuf[7];
  TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x04;								
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	TxDwinDataBuf[6]=data8;
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 5) == pdFALSE)
	{
		return;
	}
		ScreenMaster485_Send_Data(TxDwinDataBuf,7);
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );
//	HAL_Delay(10);//
}




/******************************************************************************
写16位数据
输入：写入地址：addr16，  写入数据：data16
输出返回：无	
5A A5       05   82   10 01     00 03
******************************************************************************/
void WrDwinCmd16(uint16_t addr16,uint16_t data16)
{
	uint8_t TxDwinDataBuf[8];
  	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x05;								//数据长度+命令+地址+数据
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	TxDwinDataBuf[6]=data16>>8;
	TxDwinDataBuf[7]=data16;	

	//taskENTER_CRITICAL();
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 500) == pdFALSE)
	{
		return;
	}
	ScreenMaster485_Send_Data(TxDwinDataBuf,8);
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );
	//taskEXIT_CRITICAL();
	//osDelay(10);//HAL_Delay(10);//
	
}

/******************************************************************************
发送命令
写32位数据
输入：写入地址：addr16，  写入数据：data32
输出返回：无	
5A A5       07   82      00 84      5A 01     00 03
******************************************************************************/
void WrDwinCmd32(uint16_t addr16,uint32_t data32)
{
	uint8_t TxDwinDataBuf[10];
    TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x07;								//数据长度+命令+地址+数据
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	TxDwinDataBuf[6]=data32>>24;
	TxDwinDataBuf[7]=data32>>16;
	TxDwinDataBuf[8]=data32>>8;
	TxDwinDataBuf[9]=data32;	
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 500) == pdFALSE)
	{
		return;
	}																			
		ScreenMaster485_Send_Data(TxDwinDataBuf,10);
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );		
	//osDelay(15);//HAL_Delay(15);//
}
/******************************************************************************
发送命令
写16位数据
输入：写入地址：addr16，  写入数据：*buf
输出返回：无	
******************************************************************************/
void WrDwinBuf16(uint16_t addr16,uint16_t *buf)
{
	uint8_t TxDwinDataBuf[8];
	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x05;							
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	TxDwinDataBuf[6]=(*buf)>>8;
	TxDwinDataBuf[7]=*buf;
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 150) == pdFALSE)
	{
		return;
	}	
		ScreenMaster485_Send_Data(TxDwinDataBuf,8);
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );		
	//HAL_Delay(10);//
}

/******************************************************************************
发送命令
写16位数据
输入：写入地址：addr16，  写入数据：*buf
输出返回：无	
******************************************************************************/
void WrDwinBuf32(uint16_t addr16,uint16_t *buf)
{
	uint8_t TxDwinDataBuf[10];
	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x07;						
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	TxDwinDataBuf[6]=(*buf)>>8;
	TxDwinDataBuf[7]=*buf++;
	TxDwinDataBuf[8]=(*buf)>>8;
	TxDwinDataBuf[9]=*buf;	
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 5) == pdFALSE)
	{
		return;
	}							
		ScreenMaster485_Send_Data(TxDwinDataBuf,10);
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );		
	//	HAL_Delay(10);//
	
}


/******************************************************************************
发送命令
写N个数据（字）
输入：写入地址：addr16，  写入数据：*buf  n： 发送的地址个数
输出返回：无	
******************************************************************************/
//void WrDwinBuf(uint16_t addr16,uint16_t *buf,uint8_t n)
//{
//	uint8_t i,num;
//	uint8_t TxDwinDataBuf[100];
//	num = (n<<1);
//	TxDwinDataBuf[0]=STARTSIGN_H;
//	TxDwinDataBuf[1]=STARTSIGN_L;
//	TxDwinDataBuf[2]=num+3;						
//	TxDwinDataBuf[3]=0x82;
//	TxDwinDataBuf[4]=addr16>>8;
//	TxDwinDataBuf[5]=addr16;
//	for(i=0;i<num;i+=2)
//	{
//		TxDwinDataBuf[i+6]=(*buf)>>8;
//		TxDwinDataBuf[i+7]=*buf++;
//	}	
//		ScreenMaster485_Send_Data(TxDwinDataBuf,6+num);
//	HAL_Delay(20);//
//	
//}

uint8_t TxDwinDataBuf[512];
void WrDwinBuf(uint16_t addr16,uint16_t *buf,uint16_t n,uint8_t LSB_Mode)
{
	uint16_t i,num;
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 200) == pdFALSE)
	{
		return;
	}
	num = (n<<1);
	
	if(num>255-7)
	{
		num = 255-7;//防止溢出错误
	}
	
	
	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=num+3;						
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	for(i=0;i<num;i+=2)
	{
		if(LSB_Mode==1)//先发送低位字节
		{		
			TxDwinDataBuf[i+7]=(*buf)>>8;
			TxDwinDataBuf[i+6]=*buf++;
		}
		else //先发送高位字节
		{//李伟修改 20210531    迪文屏的高低存储跟常规的是反过来的	
			TxDwinDataBuf[i+6]=(*buf)>>8;
			TxDwinDataBuf[i+7]=*buf++;
				
		}

		

	}	
	
	ScreenMaster485_Send_Data(TxDwinDataBuf,6+num);
//	osDelay(10);
#if 0	
	if(num<10)
	{
			HAL_Delay(10);
	}
	else
	{
			//HAL_Delay(num);
		  ;//HAL_Delay(20);
		  osDelay(20);
		
	}
#endif	
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );
}




/******************************************************************************
发送命令
写N个数据（字）
输入：写入地址：addr16，  写入数据：*buf  n： 发送的地址个数
输出返回：无	
******************************************************************************/
void WrDwinBuf_u8(uint16_t addr16,uint8_t *buf,uint8_t n)
{
	uint8_t i,num;
	uint8_t TxDwinDataBuf[100];
	num = (n);
	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=num+3;						
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	for(i=0;i<num;i+=1)
	{
		TxDwinDataBuf[i+6]=(*buf);
		//TxDwinDataBuf[i+7]=*buf++;
	}	
		ScreenMaster485_Send_Data(TxDwinDataBuf,6+num);
//	HAL_Delay(10);//
	
}



/******************************************************************************
读取一个字的，读16位数据
输入：写入地址：addr16，  写入数据：*buf
输出返回：无			
******************************************************************************/
void RdDwinData16(uint16_t addr16,uint8_t len)
{
	uint8_t TxDwinDataBuf[8];
	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x04;									
	TxDwinDataBuf[3]=0x83;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	TxDwinDataBuf[6]=len;																				
		ScreenMaster485_Send_Data(TxDwinDataBuf,7);
//	HAL_Delay(10);//
	
}



/******************************************************************************
读取一个字的，读16位数据
输入：写入地址：addr16，  写入数据：*buf
输出返回：无			
******************************************************************************/
void Restart_LCD(void)
{
	uint8_t TxDwinDataBuf[10];
	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x07;									
	TxDwinDataBuf[3]=0x82;
	TxDwinDataBuf[4]=0x00;//addr16>>8;
	TxDwinDataBuf[5]=0x04;//addr16;
 
	TxDwinDataBuf[6]=0x55;									
	TxDwinDataBuf[7]=0xAA;
	TxDwinDataBuf[8]=0x5a;// 
	TxDwinDataBuf[9]=0xa5;// 
	if(xSemaphore && xSemaphoreTake( xSemaphore, ( TickType_t ) 50) == pdFALSE)
	{
		return;
	}
		ScreenMaster485_Send_Data(TxDwinDataBuf,10);
	if(xSemaphore)
		xSemaphoreGive( xSemaphore );
	HAL_Delay(10);//
	
}



/******************************************************************************
读取2个字的数据32位
输入：无
输出返回：无	
******************************************************************************/
void RdDwinData32(uint16_t addr16,uint8_t len)
{
	uint8_t TxDwinDataBuf[8];
	TxDwinDataBuf[0]=STARTSIGN_H;
	TxDwinDataBuf[1]=STARTSIGN_L;
	TxDwinDataBuf[2]=0x06;									//êy?Y3¤?è+?üá?+μ??·
	TxDwinDataBuf[3]=0x83;
	TxDwinDataBuf[4]=addr16>>8;
	TxDwinDataBuf[5]=addr16;
	TxDwinDataBuf[6]=len;
		ScreenMaster485_Send_Data(TxDwinDataBuf,7);
	
//	HAL_Delay(10);//
	
	
}


/******************************************************************************
接收液晶发下来的数据，并存在结构体中
输入：无
输出返回：无	
******************************************************************************/
//void  RxAddrData (void)
//{
//  	u16  i;
//	DIWEN_com();
//	for(i = 0; i < CMDBUF_SIZE; i++)
//	{
//		if(ADDR_COMM == RxCmdBuf[i].Cmd_Addr)
//		{
//			ADDR_COMM=0xff;
//			RxCmdBuf[i].Cmd_Flag =	1;
//			RxCmdBuf[i].Cmd_Data = DATA_COMM;
//		}
//	}  
//}

/******************************************************************************
分析数据并处理数据
输入：无
输出返回：无	
******************************************************************************/
void Lcd_Cmd_Handle(void)
{
//	RxAddrData();
	
}

/******************************************************************************
界面跳转
输入：ID
输出返回：无	
******************************************************************************/
void Jump_page_id(uint8_t id)
{
	WrDwinCmd32(0x0084,0x5A010000|id);
	Run_mode_key_info.current_page = id;
}

/******************************************************************************
首页
数字：表示页面，在工程中可以看出
输入：无
输出返回：无	
******************************************************************************/

uint8_t Special_Stor;
void Go_homepage(void)
{
	
	switch (all_Store)
				{
					case 1:
						Jump_page_id(1);//跳到主界面常规1仓
						Run_mode_key_info.Main_Page_id =1;//状态界面
						Run_mode_key_info.Full_oil_id = 10;//装油界面
						Run_mode_key_info.offLoading_oil_id =19;//卸油界面
						break;
					case 2:
//						if((StoreNumber == 1)&&Special_Stor)//跳到1仓2盖((Config_info_all.ManHole_Big_info&0x0f)==0x02)
//						{
//							Jump_page_id(2);
//							Run_mode_key_info.Main_Page_id =2;
//							Run_mode_key_info.Full_oil_id = 11;
//							Run_mode_key_info.offLoading_oil_id =20;
//						}
//						else //常规2仓
//						{
							Jump_page_id(3);
							Run_mode_key_info.Main_Page_id =3;
							Run_mode_key_info.Full_oil_id = 12;
							Run_mode_key_info.offLoading_oil_id =21;
//						}
						break;
					case 3:
						Jump_page_id(4);
						Run_mode_key_info.Main_Page_id =4;
						Run_mode_key_info.Full_oil_id = 13;
						Run_mode_key_info.offLoading_oil_id =22;
						break;
					case 4:
						Jump_page_id(5);
						Run_mode_key_info.Main_Page_id =5;
						Run_mode_key_info.Full_oil_id = 14;
						Run_mode_key_info.offLoading_oil_id =23;
						break;
					case 5:
						Jump_page_id(6);
						 Run_mode_key_info.Main_Page_id =6;
						Run_mode_key_info.Full_oil_id = 15;
						Run_mode_key_info.offLoading_oil_id =24;
						break;
					case 6:
						Jump_page_id(7);
						Run_mode_key_info.Main_Page_id =7;
						Run_mode_key_info.Full_oil_id = 16;
						Run_mode_key_info.offLoading_oil_id =25;
						break;
					case 7:
						Jump_page_id(8);
						Run_mode_key_info.Main_Page_id =8;
						Run_mode_key_info.Full_oil_id = 17;
						Run_mode_key_info.offLoading_oil_id =26;
						break;
					case 8:
						Jump_page_id(9);
						Run_mode_key_info.Main_Page_id =9;
						Run_mode_key_info.Full_oil_id = 18;
						Run_mode_key_info.offLoading_oil_id =27;
						break;
					default:break;
				}
				Run_mode_key_info.Liquid_id = 54;
}
/******************************************************************************
屏幕初始化
输入：无
输出返回：无	
******************************************************************************/
void Lcd_Init(void)
{
	//初始化界面
	

	WrDwinCmd16(ADDR_DWIN_CoverSmall,0x00);//人孔小盖关
//	HAL_Delay(15);
	WrDwinCmd16(ADDR_DWIN_CoverBig,0x00);//人孔大盖关
//	HAL_Delay(15);
	WrDwinCmd16(ADDR_DWIN_HaiDiFa,0x00);//底阀关
//	HAL_Delay(15);
	
	
	WrDwinCmd16(ADDR_DWIN_XieYouFa,0x00);//卸油阀关
//	HAL_Delay(15);
	
	WrDwinCmd16(ADDR_DWIN_Seal_Lock,0xff);//锁不显示--
//	HAL_Delay(15);
	
	WrDwinCmd16(ADDR_DWIN_Seal_UnLock,0xff);//锁开不显示
//	HAL_Delay(15);
	
	WrDwinCmd16(ADDR_DWIN_Car_State,0x00);//状态正常
//	HAL_Delay(15);
	Go_homepage();//回到首页
	
//	//位控制
//	WrDwinCmd16(0x1000,0xff);//人孔小盖开 位控制
//	WrDwinCmd16(0x1003,0xff);//人孔大盖开
//	WrDwinCmd16(0x1006,0xff);//底阀开
//	WrDwinCmd16(0x1009,0xff);//卸油阀开
//	WrDwinCmd16(0x100c,0xFF);//锁不显示
//	WrDwinCmd16(0x100F,0x00);//锁开显示
//	
//	WrDwinCmd16(0x1000,0x00);//人孔小盖关
//	WrDwinCmd16(0x1003,0x00);//人孔大盖关
//	WrDwinCmd16(0x1006,0x00);//底阀关
//	WrDwinCmd16(0x1009,0x00);//卸油阀关
//	
//	WrDwinCmd16(0x100c,0x00);//锁显示
//	WrDwinCmd16(0x100F,0xff);//锁开不显示
//	
//	WrDwinCmd16(0x100c,0xff);//锁不显示
//	WrDwinCmd16(0x100F,0xff);//锁开不显示
//	WrDwinCmd16(0x1022,0x00);//状态正常
//	
//	
//	WrDwinCmd16(0x1012,0x04);//油量 数值控制
//	WrDwinCmd16(0x1014,0x01);//
//	WrDwinCmd16(0x1016,0x02);//
//	WrDwinCmd16(0x1018,0x03);//油量
//	WrDwinCmd16(0x101a,0x04);//
//	WrDwinCmd16(0x101c,0x02);//
//	WrDwinCmd16(0x101e,0x00);//油量
//	WrDwinCmd16(0x1020,0x01);//
//	WrDwinCmd16(0x1022,0x01);//状态异常
//	
//	//进入装油界面
//	WrDwinCmd32(0x0084,0x5A010000|18);
//	
//	WrDwinCmd16(0x1028,0x01);//装油模式 上装
//	WrDwinCmd16(0x1026,0x00);//油量仓
//	WrDwinCmd16(0x1024,0x01);//罐仓状态 装油中
//	WrDwinCmd16(0x102a,0x01);//装油动画开始 1
//		WrDwinCmd16(0x102c,0x01);//装油动画开始 2
//			WrDwinCmd16(0x102e,0x01);//装油动画开始 3
//				WrDwinCmd16(0x1030,0x01);//装油动画开始 4
//					WrDwinCmd16(0x1032,0x01);//装油动画开始 5
//						WrDwinCmd16(0x1034,0x01);//装油动画开始 6
//							WrDwinCmd16(0x1036,0x01);//装油动画开始 7
//								WrDwinCmd16(0x1038,0x01);//装油动画开始 8
//	
//	
//	
//	WrDwinCmd16(0x1028,0x00);//装油模式 下装
//	WrDwinCmd16(0x1026,0x08);//油量仓
//	WrDwinCmd16(0x1024,0x00);//罐仓状态 空闲中
//	WrDwinCmd16(0x102a,0x00);//装油动画停止 1
//		WrDwinCmd16(0x102c,0x00);//装油动画停止 2
//			WrDwinCmd16(0x102e,0x00);//装油动画停止 3
//				WrDwinCmd16(0x1030,0x00);//装油动画停止 4
//					WrDwinCmd16(0x1032,0x00);//装油动画停止 5
//						WrDwinCmd16(0x1034,0x00);//装油动画停止 6
//							WrDwinCmd16(0x1036,0x00);//装油动画停止 7
//								WrDwinCmd16(0x1038,0x00);//装油动画停止 8
//								
//								
//								
////进入卸油界面
//	WrDwinCmd32(0x0084,0x5A010000|27);
//	WrDwinCmd16(0x1024,0x00);//罐仓状态 空闲中
//	WrDwinCmd16(0x1026,0x01);//油量仓
//	WrDwinCmd16(0x1024,0x01);//罐仓状态 卸油中
//	
//	WrDwinCmd16(0x1012,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x102a,0x01);//卸油动画开始 1
//	
//		WrDwinCmd16(0x1014,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x102c,0x01);//卸油动画开始 2
//	
//		WrDwinCmd16(0x1016,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x102e,0x01);//卸油动画开始 3
//	
//		WrDwinCmd16(0x1018,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1030,0x01);//卸油动画开始 4
//	
//	
//		WrDwinCmd16(0x101a,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1032,0x01);//卸油动画开始 5
//	
//		WrDwinCmd16(0x101c,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1034,0x01);//卸油动画开始 6
//	
//		WrDwinCmd16(0x101e,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1036,0x01);//卸油动画开始 7
//	
//		WrDwinCmd16(0x1020,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1038,0x01);//卸油动画开始 8
//	WrDwinCmd16(0x103a,0x01);//仓数显示
//	WrDwinCmd16(0x103c,0x01);//装油警告，弹窗
//	WrDwinCmd16(0x103e,0x01);//卸油油警告，弹窗
//	WrDwinCmd16(0x1040,0x01);//指纹识别，弹窗

//卸油阀异常 1042
//底阀异常 1044
//人孔小盖异常 1046
//人孔大盖异常 1048

//登录用户名 104a
//登录密码 104c
//密码错误  104e

//时间设置
//年 104e
//月 1050
//日 1052
//时 1054
//分 1056
//秒 1058
		
		
		
}

/******************************************************************************
显示车辆状态与阀门状态
输入：无
输出返回：无	
******************************************************************************/
uint8_t a=0,b=0,c=0,d=0,i =0;
uint8_t e1=0,f1=0,g1=0,h1=0;
void Dispaly_CarAndValveState(void)
{
	uint8_t e=0,f=0,g=0,h=0;
	e=0,f=0,g=0,h=0;
	for(i=0;i<StoreNumber;i++)
	{
		a|= (0x0001&(IO_Date.IO_state[0]>>i*4))<<i;
		b|= (0x0001&(IO_Date.IO_state[0]>>(i*4+1)))<<i;
		c|= (0x0001&(IO_Date.IO_state[0]>>(i*4+2)))<<i;
		d|= (0x0001&(IO_Date.IO_state[0]>>(i*4+3)))<<i;
		e|= (0x0001&(IO_Date.IO_normalstate[0]>>i*4))<<i;
		f|= (0x0001&(IO_Date.IO_normalstate[0]>>(i*4+1)))<<i;
		g|= (0x0001&(IO_Date.IO_normalstate[0]>>(i*4+2)))<<i;
		h|= (0x0001&(IO_Date.IO_normalstate[0]>>(i*4+3)))<<i;
		if((((Full_Oil_allinfo.Start_Decrease_flag&(1<<i))==(1<<i))||(Full_Oil_allinfo.Loading_Oil_state&(1<<i))==(1<<i))&&(Run_mode_key_info.current_page !=Run_mode_key_info.Main_Page_id))
			WrDwinCmd16(ADDR_DWIN_Loading_Oil+(i*2),(((~IO_Date.IO_unload_switch>>i)&0x01)==0x01?0:00));//本仓在卸油或者装油，显示动画，不显示油量Ever_Oil_baseaddr
		else	
			WrDwinCmd16(ADDR_DWIN_Loading_Oil+(i*2),(((~IO_Date.IO_unload_switch>>i)&0x01)==0x01?0x00:0x04));
		
	}
//		WrDwinCmd16(0x1000,a);//人孔小盖关
//		WrDwinCmd16(0x1003,b);//人孔大盖关
//		WrDwinCmd16(0x1006,d);//底阀关
//		WrDwinCmd16(0x1009,c);//卸油阀关
		if(e1!=e)
		{
			WrDwinCmd16(ADDR_DWIN_StateYiChang_CoverSmall,e);//人孔小盖异常
			e1=e;
		}
		if(f1!=f)
		{
			WrDwinCmd16(ADDR_DWIN_StateYiChang_CoverBig,f);//人孔大盖异常
			f1=f;
		}
		if(h1!=h)
		{
			WrDwinCmd16(ADDR_DWIN_StateYiChang_HaiDiFa,h);//底阀异常
			h1 = h;
		}
		if(g1!=g)
		{
			WrDwinCmd16(ADDR_DWIN_StateYiChang_XieYouFa,g);//卸油阀异常
			g1 = g;
		}
#if 0		
		if(Full_Oil_allinfo.Null_ID!=Full_Oil_allinfo.Null_ID_disp)
		{
			WrDwinCmd16(0x1012,(((Full_Oil_allinfo.Null_ID>>0)&0x01)==0x01?0:0x04));//油量 数值控制 1  0x04为油量
			WrDwinCmd16(0x1014,(((Full_Oil_allinfo.Null_ID>>1)&0x01)==0x01?0:0x04));// 2
			WrDwinCmd16(0x1016,(((Full_Oil_allinfo.Null_ID>>2)&0x01)==0x01?0:0x04));// 3
			WrDwinCmd16(0x1018,(((Full_Oil_allinfo.Null_ID>>3)&0x01)==0x01?0:0x04));//油量 4
//	WrDwinCmd16(0x101a,(((Full_Oil_allinfo.Null_ID>>4)&0x01)==0x01?0:0x04));// 5
//	WrDwinCmd16(0x101c,(((Full_Oil_allinfo.Null_ID>>5)&0x01)==0x01?0:0x04));// 6
//	WrDwinCmd16(0x101e,(((Full_Oil_allinfo.Null_ID>>6)&0x01)==0x01?0:0x04));//油量 7
//	WrDwinCmd16(0x1020,(((Full_Oil_allinfo.Null_ID>>7)&0x01)==0x01?0:0x04));// 8
			Full_Oil_allinfo.Null_ID_disp=Full_Oil_allinfo.Null_ID;
		}
#endif		
  		
	
	if((Full_Oil_allinfo.Auto_sealedOK_ID ==0)&&(Full_Oil_allinfo.Break_sealing_Id ==0))// 
	{//解封状态两把锁均不显示
		WrDwinCmd16(ADDR_DWIN_Seal_Lock,0xff);//锁不显示
		WrDwinCmd16(ADDR_DWIN_Seal_UnLock,0xff);//锁开不显示
	}
	else
	{ //显示施封图片--一把锁上的锁；该处逻辑是反的----某一位为0，则显示该位的锁
		WrDwinCmd16(ADDR_DWIN_Seal_Lock,(~Full_Oil_allinfo.Auto_sealedOK_ID));//锁显示
	}
	
	
	if((Full_Oil_allinfo.Break_sealing_Id>0)&&(IO_Date.IO_unload_switch>0))
	{
		WrDwinCmd16(ADDR_DWIN_Seal_UnLock,(~Full_Oil_allinfo.Break_sealing_Id));//锁开显示
		
		//WrDwinCmd16(ADDR_DWIN_Seal_Lock,(~Full_Oil_allinfo.Auto_sealedOK_ID));//锁显示
		
		
//		WrDwinCmd16(ADDR_DWIN_Seal_Lock,(Full_Oil_allinfo.Break_sealing_Id));//锁不显示   李伟添加  20211028 避免图标混乱
//		
//		FM25L16B_WriteByte(ADDR_Auto_sealedOK_ID,(uint8_t)Full_Oil_allinfo.Auto_sealedOK_ID);//保存施封状态20200428
//		FM25L16B_WriteByte(ADDR_Break_sealing_Id,Full_Oil_allinfo.Break_sealing_Id);//保存破封状态20200428
//		//WrDwinCmd16(ADDR_DWIN_Seal_UnLock,(~Full_Oil_allinfo.Auto_sealedOK_ID));//锁不显示   李伟添加  20211028 避免图标混乱
	}
	else
	{
		WrDwinCmd16(ADDR_DWIN_Seal_UnLock,(~Full_Oil_allinfo.Break_sealing_Id));//锁开bu显示
	}
	
	
	
	if(Full_Oil_allinfo.Car_state!=Full_Oil_allinfo.Car_state_disp)
	{
		if (Full_Oil_allinfo.Car_state == 0)		//车辆状态OK
			WrDwinCmd16(ADDR_DWIN_Car_State, 0x00); //状态正常
		else if (Full_Oil_allinfo.Car_state == 1)
			WrDwinCmd16(ADDR_DWIN_Car_State, 0x02); //状态NOK
		else
			WrDwinCmd16(ADDR_DWIN_Car_State, 0x01); //状态破封
		Full_Oil_allinfo.Car_state_disp=Full_Oil_allinfo.Car_state;
	}
	
	
	
	if(Lcd_sleep_flag ==1)//屏幕休眠
	{
			WrDwinCmd16(0x0082,0x0000);//亮度调节0x0000~0x6464
	}
	else if(Lcd_sleep_flag==2)//唤醒休眠
	{
			Lcd_sleep_flag =3;
		//Jump_page_id(Run_mode_key_info.current_page);
			WrDwinCmd16(0x0082,0x3600);//亮度调节0x0000~0x646
	}
}
/******************************************************************************
装油动画
输入：mode 装油模式 sedata  装油的仓
输出返回：无	
******************************************************************************/
void FULL_oil_draw(uint8_t mode,uint8_t se_data)//装油动画
{
	uint8_t i=0;
	if(se_data!=0)
		WrDwinCmd16(ADDR_DWIN_Operation_State,0x01);//罐仓状态 装油中
	else
		WrDwinCmd16(ADDR_DWIN_Operation_State,0x00);//罐仓状态 空闲中
	
 
	
	WrDwinCmd16(ADDR_DWIN_Loading_Oil_Mode,mode);//装油模式 上装1 下装0
 
	
	
	WrDwinCmd16(ADDR_DWIN_Num_Of_CangId,se_data);//油量仓12345678
 
	
	for(i=0;i<StoreNumber;i++)
	{
		WrDwinCmd16(ADDR_DWIN_UnLoading_Oil_Mode+i*2,(se_data&(0x01<<i))>>i);
		//HAL_Delay(10);//
		
	}
//	WrDwinCmd16(0x102a,0x01);//装油动画开始 1
//	WrDwinCmd16(0x102c,0x01);//装油动画开始 2
//	WrDwinCmd16(0x102e,0x01);//装油动画开始 3
//	WrDwinCmd16(0x1030,0x01);//装油动画开始 4
//	WrDwinCmd16(0x1032,0x01);//装油动画开始 5
//	WrDwinCmd16(0x1034,0x01);//装油动画开始 6
//	WrDwinCmd16(0x1036,0x01);//装油动画开始 7
//	WrDwinCmd16(0x1038,0x01);//装油动画开始 8
}
/******************************************************************************
卸油动画
输入: sedata  装油的仓
输出返回：无	
******************************************************************************/
void Off_loading_draw(uint8_t se_data)
{
	uint8_t i=0;
		if(se_data!=0)
			WrDwinCmd16(ADDR_DWIN_Operation_State,0x01);//罐仓状态 卸油中
		else
			WrDwinCmd16(ADDR_DWIN_Operation_State,0x00);//罐仓状态 空闲中
		
 
		
		WrDwinCmd16(ADDR_DWIN_Num_Of_CangId,se_data);//卸量仓12345678
		
 
		
	for(i=0;i<StoreNumber;i++)
	{
		WrDwinCmd16(ADDR_DWIN_UnLoading_Oil_Mode+i*2,(se_data&(0x01<<i))>>i);
		//HAL_Delay(10);//
		
	}
		
//	WrDwinCmd16(0x1024,0x00);//罐仓状态 空闲中
//	WrDwinCmd16(0x1026,0x01);//油量仓
//	WrDwinCmd16(0x1024,0x01);//罐仓状态 卸油中
//	
//	WrDwinCmd16(0x1012,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x102a,0x01);//卸油动画开始 1
//	
//		WrDwinCmd16(0x1014,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x102c,0x01);//卸油动画开始 2
//	
//		WrDwinCmd16(0x1016,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x102e,0x01);//卸油动画开始 3
//	
//		WrDwinCmd16(0x1018,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1030,0x01);//卸油动画开始 4
//	
//	
//		WrDwinCmd16(0x101a,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1032,0x01);//卸油动画开始 5
//	
//		WrDwinCmd16(0x101c,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1034,0x01);//卸油动画开始 6
//	
//		WrDwinCmd16(0x101e,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1036,0x01);//卸油动画开始 7
//	
//		WrDwinCmd16(0x1020,0x00);//1仓油量 数值控制
//	WrDwinCmd16(0x1038,0x01);//卸油动画开始 8

/*
5A A5 07 82 0082 6420 07D0 
（10秒后进入背光，点击变亮，10000/5=2000 换算成16进制为07D0，范围00-64,100级亮度调节）
*/
}

void Read_REAL_Time(void)
{
	/*
	5A A5 0B 82 009C 5A A5 12 06 1B 15 15 15 （18年6月27号21时21分21秒，16进制数据） 读RTC：5A A5 04 83 0010 04
	*/
	RdDwinData16(0x0010,4);
	
}
void Wakeup_lcd(void)
{
	uint8_t  PopWinCmdBuf[14]={0x5A ,0xA5 ,0x0B ,0x82 ,0x00 ,0xD4 ,0x5A ,0xA5 ,0x00 ,0x04 ,0x00 ,0x00 ,0x00 ,0x00};
	//5A A5 0B 82 00D4 5AA5 0004 00EE 008F
		UartWrite(&huart2,PopWinCmdBuf,14);
}
void Display_input_time(uint8_t flag,uint8_t *time)
{
	uint8_t arr[6]={0};
	uint8_t i =0;
	for(i=0;i<6;i++)
	{
		//arr[i]=time[i*2]-0x30+time[i*2+1]-0x30;
		if(time[i*2]!=0x00)
		{
			if(time[i*2+1]!=0x00)
				arr[i] = (time[i*2]-0x30)*10+(time[i*2+1]-0x30);
			else
				arr[i] = time[i*2]-0x30;
		}
		else
		{
			break;
		}
	}
		WrDwinCmd16(0x104e,arr[0]);//年
	  HAL_Delay(10);//
		WrDwinCmd16(0x1050,arr[1]);//月
	  HAL_Delay(10);//
		WrDwinCmd16(0x1052,arr[2]);//日
		HAL_Delay(10);//
		WrDwinCmd16(0x1054,arr[3]);//时
		HAL_Delay(10);//
		WrDwinCmd16(0x1056,arr[4]);//分
	  HAL_Delay(10);//
		WrDwinCmd16(0x1058,arr[5]);//秒
	  HAL_Delay(10);//
	
	if(flag ==1)//发送时间确认修改
	{
		flag =0;
		Send_Time(arr);
	}
}
//time 要修改的时间
void Send_Time(uint8_t * time)
{
//	u8 i =0;
	
	memcpy(time_Set_Dwin+8,time,6);
	UartWrite(&huart2,time_Set_Dwin,14);
/*	delay_ms(100);*/
}

//flag 显示密码错误信息 pawd_num 密码个数
//登录用户名 104a
//登录密码 104c
//密码错误  105a
void Dispay_login(uint8_t flag,uint8_t pawd_num)
{
	WrDwinCmd16(0x104a,0);
	HAL_Delay(10);//
	
	if(pawd_num<7)
		WrDwinCmd16(0x104c,pawd_num);
	HAL_Delay(10);//
	
	if(flag==1)
		WrDwinCmd16(0x105a,1);//密码错误提示
	else
		WrDwinCmd16(0x105a,0);
	
}
