#include "Gui.h"
#include "DevProperty.h"

void TDevProperty::DrawFixTextSmoker()
{
	if(LanguageEnCn == 0){
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 4, clNearWhite, ItemColor, "灵敏度");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +60, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "读取", 14, clNearBlack);
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +150, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "保存", 14, clNearBlack);
		
		TextRender_string24(Lv.Grid.Left[3] +10, Lv.Grid.Top[3] + 4, clNearWhite, ItemColor, "操作");
		unsigned int aClr;
		if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearBlack;else	aClr = clSilver;
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +60, Lv.Grid.Top[3] + 36, 76, 30, 7, clNearWhite, "灯点", 14, aClr);
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +150, Lv.Grid.Top[3] + 36, 124, 30, 7, clNearWhite, "模拟报警", 14, aClr);
	}else{
		TextRender_string24(Lv.Grid.Left[2] +10, Lv.Grid.Top[2] + 4, clNearWhite, ItemColor, "SENSIT");
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +60, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "Read", 14, clNearBlack);
		TRoundRect::sDrawBySize(Lv.Grid.Left[2] +150, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, "Save", 14, clNearBlack);
		
		TextRender_string24(Lv.Grid.Left[3] +10, Lv.Grid.Top[3] + 4, clNearWhite, ItemColor, "OPR");
		unsigned int aClr;
		if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearBlack;else	aClr = clSilver;
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +60, Lv.Grid.Top[3] + 36, 76, 30, 7, clNearWhite, "LED ", 14, aClr);
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +150, Lv.Grid.Top[3] + 36, 124, 30, 7, clNearWhite, "SimAlarm", 14, aClr);
	}	
}

void TDevProperty::FullRedrawhtSmoker(int Prm)
{
	if(Prm == 0){
		for(int i=2; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
		ReDrawCommonInf();
		DrawFixTextSmoker();
		IList->Edit[0].Show();
		DrawSmokerReadWriteStates();
		DrawLightOnStateSmoke();
		RedrawPanelData();
		Redraw4SmokerSmallPanelData();
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			Check4SelectedHtSmoker();
		}
	}else{
		for(int i=2; i<3; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
		ReDrawCommonInf();
		DrawFixTextSmoker();
		IList->Edit[0].Show();
		DrawSmokerReadWriteStates();
		RedrawPanelData();
		DrawLightOnStateSmoke();
		Redraw4SmokerSmallPanelData();
		if(EdittingDescp){
			CnInput.FullRedraw();
		}else{
			Check4SelectedHtSmoker();
		}
		if(IsPermission)PmsIntervene4Gui.ReDraw4GuiRecall();
	}
}

void TDevProperty::DrawSmokerReadWriteStates()
{
	char *tText;
	if(IsHotKeyCheckingPermission)return;
	if(SmokerReadWriteSta == 0){
		tText="        ";
	}else
	if(SmokerReadWriteSta == 1){
		if(LanguageEnCn==0)tText="获取中  "; else tText="Reading "; 
	}else
	if(SmokerReadWriteSta == 2){
		if(LanguageEnCn==0)tText="获取成功"; else tText="Read OK ";
	}else
	if(SmokerReadWriteSta == 3){
		if(LanguageEnCn==0)tText="获取失败"; else tText="Read Err";
	}else
	if(SmokerReadWriteSta == 4){
		if(LanguageEnCn==0)tText="正在保存"; else tText="Saving  ";
	}else
	if(SmokerReadWriteSta == 5){
		if(LanguageEnCn==0)tText="保存成功"; else tText="Save OK ";
	}else
	if(SmokerReadWriteSta == 6){
		if(LanguageEnCn==0)tText="保存失败"; else tText="Save Err";
	}
	TextRender_string24(IList->Edit[0].Bound.Right + 6, IList->Edit[0].Bound.Top + 4, clNearWhite, ItemColor, tText);
}

void TDevProperty::DrawSmokerReadWriteStates(unsigned char aNewState)
{
	SmokerReadWriteSta = aNewState;
	DrawSmokerReadWriteStates();
}

void TDevProperty::InitHtSmoker()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	
	DrawFixTextSmoker();
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	if(Lv.Panel.Active)RectFillRender(Lv.PanelSmall.Left, Lv.PanelSmall.Top, Lv.PanelSmall.Right, Lv.PanelSmall.Bottom, SmallPanelColor);
	
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	RectFillRender(Lv.PanelSmall.Left + 120, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 120 + 20, Lv.PanelSmall.Top + 6 + 20, clPurple);
	RectFillRender(Lv.PanelSmall.Left + 260, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 260 + 20, Lv.PanelSmall.Top + 6 + 20, clRed);
	RectFillRender(Lv.PanelSmall.Left + 370, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 370 + 20, Lv.PanelSmall.Top + 6 + 20, clBlue);
	
	IList->Edit[0].Init(Lv.Grid.Left[2] +86, Lv.Grid.Top[2] + 4, 100,30,0,0,1,clNearBlack);
	IList->Edit[0].Str.Clear();
	IList->Edit[0].Show(); 
	
	SmokerRt.IsWait4ReadSens = 1;
	SmokerRt.IsWait4WriteSens = 0;
	SmokerRt.RecRdy = 0;
	SmokerRt.RecCmd = 0;
	SmokerRt.WaitTick = 0;
	DrawSmokerReadWriteStates(1);//"获取中"
	
	
	DrawLightOnStateSmoke();
}

void TDevProperty::EditDescpReturnHtSmoker()
{
	PanelIsUsingText = 1;
	
	for(int i=2; i<4; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	
	DrawFixTextSmoker();
	
	DrawLightOnStateSmoke();
	
	IList->Edit[0].Show(); 
	
	ReDrawPanel();
}

void TDevProperty::Redraw4SmokerNewLoad()
{
	//for(int i=2; i<4; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
	
	IList->Edit[0].Str.Clear();
	IList->Edit[0].Show();
	
	SmokerRt.IsWait4ReadSens = 1;
	SmokerRt.IsWait4WriteSens = 0;
	SmokerRt.RecRdy = 0;
	SmokerRt.RecCmd = 0;
	SmokerRt.WaitTick = 0;
	DrawSmokerReadWriteStates(1);//"获取中"
	
	//TextRender_string24(Lv.Grid.Left[3] +10, Lv.Grid.Top[3] + 4, clNearWhite, ItemColor, "操作");
	//TRoundRect::sDrawBySize(Lv.Grid.Left[3] +60, Lv.Grid.Top[3] + 36, 76, 30, 7, clNearWhite, "灯点", 14, clNearBlack);
	//TRoundRect::sDrawBySize(Lv.Grid.Left[3] +150, Lv.Grid.Top[3] + 36, 124, 30, 7, clNearWhite, "模拟报警", 14, clNearBlack);
	
	if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
	
	CurveInit(Lv.Panel.Left+8, Lv.Panel.Top+8, Lv.Panel.Width-16, Lv.Panel.Heigh-16, 3);
	CurveSetMargin(60, 2, 60, 2);
	CurveSetGrid(6, 6, 50, 50);
	CurveSetColor(clRed, clBlue, clDeepGreen, clDeepGreen);
	CurveSetScaling();
	
	DrawLightOnStateSmoke();
}

void TDevProperty::Redraw4SmokerSmallPanelData()
{
	RectFillRender(Lv.PanelSmall.Left + 10, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 10 + 20, Lv.PanelSmall.Top + 6 + 20, clGreen);
	RectFillRender(Lv.PanelSmall.Left + 120, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 120 + 20, Lv.PanelSmall.Top + 6 + 20, clPurple);
	RectFillRender(Lv.PanelSmall.Left + 260, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 260 + 20, Lv.PanelSmall.Top + 6 + 20, clRed);
	RectFillRender(Lv.PanelSmall.Left + 370, Lv.PanelSmall.Top + 6, Lv.PanelSmall.Left + 370 + 20, Lv.PanelSmall.Top + 6 + 20, clBlue);

	TMyString::sClear(TextDraw);
	TMyString::sFrom2Dg(RuntimeData.voltage % 100, TextDraw);
	TMyString::sAddOnChar('.', TextDraw);
	TMyString::sAddOn1Dg(0, TextDraw);
	TMyString::sAddOnChar('V', TextDraw);
	TextRender_string24(Lv.PanelSmall.Left + 32, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
	
	TMyString::sClear(TextDraw);
	TMyString::sAddOnStr("M=", TextDraw);
	TMyString::sAddOn1Dg(RuntimeData.SmokerPrmM % 10000 / 1000, TextDraw);
	TMyString::sAddOnChar('.', TextDraw);
	TMyString::sAddOn3Dg(RuntimeData.SmokerPrmM % 1000, TextDraw);
	TextRender_string24(Lv.PanelSmall.Left + 146, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
	
	TMyString::sFrom4Dg(RuntimeData.SmokerIR, TextDraw);
	TextRender_string24(Lv.PanelSmall.Left + 286, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
	
	TMyString::sFrom4Dg(RuntimeData.SmokerBL, TextDraw);
	TextRender_string24(Lv.PanelSmall.Left + 396, Lv.PanelSmall.Top + 4, clNearWhite, SmallPanelColor, TextDraw);
	
	DrawMac();
}

void TDevProperty::ClearSelectedHtSmoker()
{
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 0;
			IList->EditPortNum.Show();
			break;
		case 2:
			IList->EditAddrNum.Selected = 0;
			IList->EditAddrNum.Show();
			break;
		case 3:
			IList->EditDescpShow.Selected = 0;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 0;
			IList->EditUserCode.Show();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 0;
			IList->EditAreaAssign.Show();
			break;
		case 6:
			IList->Edit[0].Selected = 0;
			IList->Edit[0].Show();
			break;
	}
	
	switch(Tag.Inx){
		case 7:
			if(LanguageEnCn==0)tText="读取";else tText = "Read";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +60, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 8:
			if(LanguageEnCn==0)tText="保存";else tText = "Save";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +150, Lv.Grid.Top[2] + 40, 76, 30, 7, clNearWhite, tText, 14, clNearBlack);
			break;
		case 9:
			//TRoundRect::sDrawBySize(Lv.Grid.Left[3] +60, Lv.Grid.Top[3] + 36, 76, 30, 7, clNearWhite, "灯点", 14, clNearBlack);
			DrawLightOnStateSmoke(-1);
			break;
		case 10:
			unsigned int aClr;
			if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearBlack;else	aClr = clSilver;
			if(LanguageEnCn==0)tText="模拟报警";else tText = "SimAlarm";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +150, Lv.Grid.Top[3] + 36, 124, 30, 7, clNearWhite, tText, 14, aClr);
			break;
	}
}
void TDevProperty::Check4SelectedHtSmoker()
{
	char *tText;
	switch(Tag.Inx){
		case 0:
			
			break;
		case 1:
			IList->EditPortNum.Selected = 1;
			IList->EditPortNum.SetPstTail();
			IList->EditPortNum.Show();
			IList->EditPortNum.ShowCursor();
			break;
		case 2:
			IList->EditAddrNum.Selected = 1;
			IList->EditAddrNum.SetPstTail();
			IList->EditAddrNum.Show();
			IList->EditAddrNum.ShowCursor();
			break;
		case 3:
			IList->EditDescpShow.Selected = 1;
			IList->EditDescpShow.Show();
			break;
		case 4:
			IList->EditUserCode.Selected = 1;
			IList->EditUserCode.SetPstTail();
			IList->EditUserCode.Show();
			IList->EditUserCode.ShowCursor();
			break;
		case 5:
			IList->EditAreaAssign.Selected = 1;
			IList->EditAreaAssign.SetPstTail();
			IList->EditAreaAssign.Show();
			IList->EditAreaAssign.ShowCursor();
			break;
		case 6:
			IList->Edit[0].Selected = 1;
			IList->Edit[0].Show();
			break;
	}
	
	switch(Tag.Inx){
		case 7:
			if(LanguageEnCn==0)tText="读取";else tText = "Read";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +60, Lv.Grid.Top[2] + 40, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
		case 8:
			if(LanguageEnCn==0)tText="保存";else tText = "Save";
			TRoundRect::sDrawBySize(Lv.Grid.Left[2] +150, Lv.Grid.Top[2] + 40, 76, 30, 7, clDeepBlue, tText, 14, clNearWhite);
			break;
		case 9:
			//TRoundRect::sDrawBySize(Lv.Grid.Left[3] +60, Lv.Grid.Top[3] + 36, 76, 30, 7, clDeepBlue, "灯点", 14, clNearWhite);
			DrawLightOnStateSmoke();
			break;
		case 10:
			unsigned int aClr;
			if(RunState == TRunModeCfg::RunModeAdjust)aClr = clNearWhite;else	aClr = clSilver;
			if(LanguageEnCn==0)tText="模拟报警";else tText = "SimAlarm";
			TRoundRect::sDrawBySize(Lv.Grid.Left[3] +150, Lv.Grid.Top[3] + 36, 124, 30, 7, clDeepBlue, tText, 14, aClr);
			break;
	}		
}

void TDevProperty::RedrawSmokeSensValue()
{
	char *tText;
	if(Data.SmokerSens == 1){
		if(LanguageEnCn==0)tText="灵敏"; else tText ="Normal";
	}else
	if(Data.SmokerSens == 2){
		if(LanguageEnCn==0)tText="中灵敏"; else tText ="Middle";
	}else
	if(Data.SmokerSens == 3){
		if(LanguageEnCn==0)tText="高灵敏"; else tText ="ExHigh";
	}else
	if(Data.SmokerSens == 4){
		if(LanguageEnCn==0)tText="超灵敏"; else tText ="Ultra";
	}else{
		if(LanguageEnCn==0)tText="未知  "; else tText ="Unknown";
	}
	IList->Edit[0].Str.FromStr(tText);
	if(EdittingDescp == 0)IList->Edit[0].Show();
}

void TDevProperty::SendSmokeCmdRead()
{
	TCanHeaderID aIde;
	unsigned char cVal;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aPx;
	
	ProcessingRt.DevType = 0;	//点型烟感
	ProcessingRt.DataType = 1;	//烟感灵敏度
	
	Len =4;
	
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	
	CommData[0] = 3;
	
	CommData[1] = Path0;
	ProcessingRt.P0 = Path0;
	
	CommData[2] = Path1;
	ProcessingRt.P1 = Path1;
	
	CommData[3] = ProcessingRt.DataType;
	
	aIde.BitF.Cmd = cmQuerySens;
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
	
	InnerCan.Buf4GuiSend.Insert(aIde, CommData, Len);
}

void TDevProperty::SendSmokeCmdCfg()
{
	TCanHeaderID aIde;
	unsigned char cVal, tP0, tP1;
	unsigned int i;
	unsigned int Len;
	int iVal;
	unsigned char aPx;
	
	ProcessingRt.DevType = 0;	//点型烟感
	ProcessingRt.DataType = 1;	//烟感灵敏度
	
	if(Data.SmokerSens < 4)
		ProcessingRt.dVal[0] = dSmokeSensGrade_MarkValue[Data.SmokerSens];
	else
		ProcessingRt.dVal[0] = 0;
	ProcessingRt.dVal[1] =0;
	ProcessingRt.dVal[2] =0;
	ProcessingRt.dVal[3] =0;
	
	Len =8;
	for(i=0; i<8; i++){
		CommData[i] = 0;
	}
	CommData[0] = 3;
	
	CommData[1] = Path0;
	ProcessingRt.P0 = Path0;
	ProcessingRt.P1 = Path1;
	CommData[2] = ProcessingRt.P1;
		
	aIde.BitF.Cmd = cmDeviceSetSens;

	
	RedrawSmokeSensValue();
	
	CommData[3] = ProcessingRt.DataType;
	CommData[4] = ProcessingRt.dVal[0];
	CommData[5] = ProcessingRt.dVal[1];
	CommData[6] = ProcessingRt.dVal[2];
	CommData[7] = ProcessingRt.dVal[3];
	
	
	aIde.BitF.Pri = 1;
	aIde.BitF.sLvl = 1;
	aIde.BitF.dLvl = 7;
	aIde.BitF.sAddr = 0;
	aIde.BitF.dAddr = 127;
		
	InnerCan.Buf4GuiSend.Insert(aIde, CommData, Len);
}

void TDevProperty::PushSmokeCanData(unsigned char aCmd, unsigned char *pData)
{
	int i;
	if(aCmd == cmDeviceSetSens){
		for(i=0; i<8; i++)RecData[i] = pData[i];
		if(   (ProcessingRt.P0 == RecData[1]) &&
			(ProcessingRt.P1 == RecData[2]) &&
			(ProcessingRt.DataType == RecData[3]) &&
			(ProcessingRt.dVal[0] == RecData[4])) {
				SmokerRt.RecRdy =1;
				SmokerRt.RecCmd =aCmd;
		}
	}else
	if(aCmd == cmQuerySens){
		for(i=0; i<8; i++)RecData[i] = pData[i];
		if(   (ProcessingRt.P0 == RecData[1]) &&
			(ProcessingRt.P1 == RecData[2]) &&
			(ProcessingRt.DataType == RecData[3]) ){
				ProcessingRt.dValGot[0] = RecData[4];
				ProcessingRt.dValGot[1] = RecData[5];
				ProcessingRt.dValGot[2] = RecData[6];
				ProcessingRt.dValGot[3] = RecData[7];
				SmokerRt.RecRdy =1;
				SmokerRt.RecCmd =aCmd;
		}
	}
}

TGuiMsgReturn TDevProperty::KeyInHtSmoker(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	int HasPrc = 0;
	switch(aKey){
		case VK_0:
		case VK_1:
		case VK_2:
		case VK_3:
		case VK_4:
		case VK_5:
		case VK_6:
		case VK_7:
		case VK_8:
		case VK_9:
		case VK_DELETE:
		case VK_LEFT:
		case VK_RIGHT:
			if(Tag.Inx < 6){
				KeyInCommonEdit(aKey);
			}else{
				if(Tag.Inx == 6){
					//Change Sens
					Data.SmokerSens++;
					if(Data.SmokerSens >= 5){
						Data.SmokerSens = 1;
					}
					RedrawSmokeSensValue();
				}else
				if(Tag.Inx == 7){
					//Read Sens
					if(aKey == VK_RIGHT){
						ClearSelectedHtSmoker();
						Tag.Inx = 8;
						Check4SelectedHtSmoker();
					}
				}else
				if(Tag.Inx == 8){
					//Set Sens
					if(aKey == VK_LEFT){
						ClearSelectedHtSmoker();
						Tag.Inx = 7;
						Check4SelectedHtSmoker();
					}
				}else
				if(Tag.Inx == 9){
					//Light Up
					if(aKey == VK_RIGHT){
						ClearSelectedHtSmoker();
						Tag.Inx = 10;
						Check4SelectedHtSmoker();
					}
				}else
				if(Tag.Inx == 10){
					//Sim Alram
					if(aKey == VK_LEFT){
						ClearSelectedHtSmoker();
						Tag.Inx = 9;
						Check4SelectedHtSmoker();
					}
				}
			}
			break;
		case VK_UP:
			if(PortNumValid && AddrNumValid){
				ClearSelectedHtSmoker();
				Tag.Inx > Tag.InxMin ? Tag.Inx-- : Tag.Inx = 10;
				Check4SelectedHtSmoker();
			}
			break;
		case VK_DOWN:
			if(PortNumValid && AddrNumValid){
				ClearSelectedHtSmoker();
				Tag.Inx < 10 ? Tag.Inx++ : Tag.Inx = Tag.InxMin;
				Check4SelectedHtSmoker();
			}
			break;
		case VK_TAB:
			PanelIsUsingText = PanelIsUsingText ? 0 : 1;
			if(PanelIsUsingText == 0){
				CurveHide();
			}
			Check4Selected();
			if(Lv.Panel.Active)RectFillRender(Lv.Panel.Left, Lv.Panel.Top, Lv.Panel.Right, Lv.Panel.Bottom, PanelColor);
			RedrawPanelData();
			break;
		case dfKEY_SETUP:
			break;
		case dfKEY_QUERY:
			PanelDrawData.DesertTextHex = PanelDrawData.DesertTextHex ? 0: 1;
			break;
		case dfKEY_ENCN:
			SendReqMac();
			break;
		case VK_EXECUTE:
			if(PortNumValid && AddrNumValid){
				if(Tag.Inx <6){
					KeyInCommonEnter(aKey);
				}else{
					if(Tag.Inx == 6){
						//Change Sens
						
					}else
					if(Tag.Inx == 7){
						//Read Sens
						SmokerRt.IsWait4ReadSens = 1;
						SmokerRt.IsWait4WriteSens = 0;
						SmokerRt.RecRdy = 0;
						SmokerRt.RecCmd = 0;
						SmokerRt.WaitTick = 0;
						SendSmokeCmdRead();
						DrawSmokerReadWriteStates(1);//"获取中"
					}else
					if(Tag.Inx == 8){
						//Set Sens
						if(SystemPermission >2){
							SmokerRt.IsWait4ReadSens = 0;
							SmokerRt.IsWait4WriteSens = 1;
							SmokerRt.RecRdy = 0;
							SmokerRt.RecCmd = 0;
							SmokerRt.WaitTick = 0;
							SendSmokeCmdCfg();
							DrawSmokerReadWriteStates(4);//"写入中  ")
						}else{
							IsPermission = 1;
							PermissionCmd = pcWriteSmokerSens;
							PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 3);
						}
					}else
					if(Tag.Inx == 9){
						//Light Up
						if(RunState == TRunModeCfg::RunModeAdjust){
							SendCmdLightOn();
							DrawLightOnStateSmoke();
						}
					}else
					if(Tag.Inx == 10){
						//Sim Alram
						if(RunState == TRunModeCfg::RunModeAdjust){
							PermissionCmd = pcSimAlram; //pcSimAlram,pcSimStart,pcSimInputActive,
							if(SystemPermission >1){
								PermissionCmdGO();
							}else{
								IsPermission = 1;
								PmsIntervene4Gui.Show4Gui(Lv.Panel.Left + 16, Lv.Panel.Top + 16, Lv.Panel.Width -34, 140, 2);
							}
						}
					}
				}
			}
			break;
		case VK_RETURN:
			IsShow = 0;
			RealTimeSendCmdAbort();
			aMsg = guiMsgReturn;
			break;
	}
	
	
	return aMsg;
	
}

void TDevProperty::DrawLightOnStateSmoke(int aPrm)
{
	unsigned char aP0, aP1;
	char *tText;
	unsigned int TextColor, bClr, tPrm;
	if( (Path0) && (Path0<=dPORT_MAX_COUNT) && (Path1) ){
		aP0 = Path0 -1;
		aP1 = Path1 -1;
		if( (Tag.Inx == 9) && (aPrm != -1) ){
			TextColor = clNearWhite;
			bClr = clDeepBlue;
		}else{
			if(RunState == TRunModeCfg::RunModeAdjust)TextColor = clNearBlack;else	TextColor = clSilver;
			bClr = clNearWhite;
		}
		if(Port[aP0].HasSetLightOn[aP1]){
			TextColor = clRed;
		}
		if(LanguageEnCn == 0)tText="灯点"; else tText="LED";
		TRoundRect::sDrawBySize(Lv.Grid.Left[3] +60, Lv.Grid.Top[3] + 36, 76, 30, 7, bClr, tText, 14, TextColor);
	}	
}

void TDevProperty::Task1000MsSmoker()
{
	if(SmokerRt.IsWait4ReadSens){
		if(SmokerRt.RecRdy){
			if(SmokerRt.RecCmd == cmQuerySens){
				SmokerRt.RecRdy = 0;
				SmokerRt.IsWait4ReadSens = 0;
				//Add Record Here
				if(ProcessingRt.DataType == 1){
					if(ProcessingRt.dValGot[0] == dSmokeSensGrade_MarkValue[1] )Data.SmokerSens = 1;
					else if(ProcessingRt.dValGot[0] == dSmokeSensGrade_MarkValue[2] )Data.SmokerSens = 2;
					else if(ProcessingRt.dValGot[0] == dSmokeSensGrade_MarkValue[3] )Data.SmokerSens = 3;
					else if(ProcessingRt.dValGot[0] == dSmokeSensGrade_MarkValue[4] )Data.SmokerSens = 4;
					else Data.SmokerSens = 5;
					RedrawSmokeSensValue();
					if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
						DrawSmokerReadWriteStates(2);//"获取中""读取成功"); 
					}else{
						SmokerReadWriteSta =2;
					}
				}
			}
			SmokerRt.RecRdy = 0;
		}
		SmokerRt.WaitTick ++;
		if(SmokerRt.WaitTick > 6){
			SmokerRt.IsWait4ReadSens = 0;
			if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
				DrawSmokerReadWriteStates(3);//"读取失败");
			}else{
				SmokerReadWriteSta =3;
			}
		}
	}else
	if(SmokerRt.IsWait4WriteSens){
		if(SmokerRt.RecRdy){
			if(SmokerRt.RecCmd == cmDeviceSetSens){
				SmokerRt.IsWait4WriteSens = 0;
				//Add Record Here
				aFullPath.Body.pCtl = MainCtl.fData.Split.MyNum;
				aFullPath.Body.P0 = ProcessingRt.P0;
				aFullPath.Body.P1 = ProcessingRt.P1;
				if(ProcessingRt.DataType == 1) {
					Record.OperateAdd_CfgAddrSmokeSensGrade(aFullPath.D32, Data.SmokerSens);
				}
				if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
					DrawSmokerReadWriteStates(5);//"保存成功");
				}else{
					SmokerReadWriteSta = 5;
				}
			}
			SmokerRt.RecRdy = 0;
		}
		SmokerRt.WaitTick ++;
		if(SmokerRt.WaitTick > 6){
			SmokerRt.IsWait4WriteSens = 0;
			if( (EdittingDescp == 0) && (IsHotKeyCheckingPermission == 0) ){
				DrawSmokerReadWriteStates(6);//"保存失败");
			}else{
				SmokerReadWriteSta = 6;
			}
		}
	}
	Redraw4SmokerSmallPanelData();
}


