#include "RuntimeData.h"
#include "GraphDevCfg.h"


extern "C"{
	#include "user_norflash.h"
	#include "user_eeprom.h"
	#include "uart_key_drv.h"
}

#define dWdClr		clSkyBlue
#define dWdDisabelClr	clNearWhite

#define dWWidth	24
#define dWHeigh	24
#define dRoundR	7

const int xRs485	= 20;
const int xCan	= 160;
const int xActive = 20;
const int xClose	= 160;

void TGraphDevCfg::Init()
{
	IsShowing = 0;
	CtlIndex = 0;
	OpaState = 0;
	
	IsPermission =0;
	
	this->CrtNum = GraphAddr;
	if( (this->CrtNum >0) && (this->CrtNum <65) ) {
		CrtNumValid = 1;
	}else{
		CrtNumValid = 0;
	}
}

void TGraphDevCfg::sDelayMs(unsigned int aMs)
{
	volatile unsigned int mTick;
	volatile unsigned int Tick;
	for(Tick=0; Tick<aMs; Tick++){
		for(mTick=0; mTick<160000; mTick++);
		sys_error_led_task();
	}
}

void TGraphDevCfg::RenderBackGround(void)
{
	RectFillRender(ContentGeometry.Left, ContentGeometry.Top, ContentGeometry.Right, ContentGeometry.Bottom, ContentColor);
}

void TGraphDevCfg::RenderBackGround(unsigned int aClr)
{
	RectFillRender(ContentGeometry.Left, ContentGeometry.Top, ContentGeometry.Right, ContentGeometry.Bottom, aClr);
}

void TGraphDevCfg::DrawFixText()
{
	if(LanguageEnCn==0){
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite, CaptionColor, "局域网->消防控制室图形显示装置");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +6, clNearWhite, "接口选择");
		TextRender_string24(Lv.Grid.Left[0] + 210, Lv.Grid.Top[0] +6, clNearWhite, "本机号:");
		TextRender_string24(xRs485 + 30, Lv.Grid.Top[0] + 40, clNearWhite, "RS485");
		TextRender_string24(xCan + 30, Lv.Grid.Top[0] + 40, clNearWhite, "CAN");

		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "图显地址号");
		TextRender_string24(Lv.Grid.Left[1] + 63, Lv.Grid.Top[1] +40, clNearWhite, "选中后按确定键保存");
		TRoundRect::sDrawBySize(xActive, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "开启", 26, clNearBlack);
		TRoundRect::sDrawBySize(xClose, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "关闭", 26, clNearBlack);
	}else{
		TextRender_string24(Lv.Caption.Left + 10, Lv.Caption.Top +4, clNearWhite, CaptionColor, "Local Network->Fire Alram Graphic Display");
		TextRender_string24(Lv.Grid.Left[0] + 10, Lv.Grid.Top[0] +6, clNearWhite, "Port Type Choice");
		TextRender_string24(Lv.Grid.Left[0] + 210, Lv.Grid.Top[0] +6, clNearWhite, "Local");
		TextRender_string24(xRs485 + 30, Lv.Grid.Top[0] + 40, clNearWhite, "RS485");
		TextRender_string24(xCan + 30, Lv.Grid.Top[0] + 40, clNearWhite, "CAN");

		TextRender_string24(Lv.Grid.Left[1] + 10, Lv.Grid.Top[1] +6, clNearWhite, "Graphic-ID ");
		TextRender_string24(Lv.Grid.Left[1] + 63, Lv.Grid.Top[1] +40, clNearWhite, "Press Key OK To Save");
		TRoundRect::sDrawBySize(xActive, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "Enable", 14, clNearBlack);
		TRoundRect::sDrawBySize(xClose, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "Disable", 14, clNearBlack);
	}
}

void TGraphDevCfg::DrawSelf(void)
{
	RenderBackGround();
	RectFillRender(Lv.Caption.Left, Lv.Caption.Top, Lv.Caption.Right, Lv.Caption.Bottom, CaptionColor);
	for(int i=0; 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);
	DrawFixText();
	TextDigitRender2_24(Lv.Grid.Left[0] + 300, Lv.Grid.Top[0] +6, clNearWhite, MainCtl.fData.Split.MyNum);
	IList->EditCtlNum.Init(Lv.Grid.Left[1] +20, Lv.Grid.Top[1] +36, 36, 32, 0,0, 1, clNearWhite);
	IList->EditCtlNum.SetMaxLen(2);
	IList->EditCtlNum.TextClear();
	IList->EditCtlNum.Str.FromUInt2Dg(GraphAddr);
	IList->EditCtlNum.SetPstTail();
	this->CrtNum = GraphAddr;
	if( (this->CrtNum >1) && (this->CrtNum <64) ) {
		CrtNumValid = 1;
		IList->EditCtlNum.SelectedColor = clBlue;
	}else{
		CrtNumValid = 0;
		this->CrtNum =0;
		IList->EditCtlNum.SelectedColor = clRed;
	}
	IList->EditCtlNum.Str.FromUInt2Dg(this->CrtNum);
	DrawLineType();
	IList->EditCtlNum.Show();
	Check4Selected();
	
	ShowSysState();
}

void TGraphDevCfg::Show(void)
{	
	RenderBackGround();
	DrawSelf();
}

void TGraphDevCfg::ShowSysState()
{
	if(LanguageEnCn==0){
		if(GraphUsing){
			TextRender_string24(Lv.Grid.Left[1] + 200, Lv.Grid.Top[1] +6, clNearWhite, ItemColor, "目前图显开启");
		}else{
			TextRender_string24(Lv.Grid.Left[1] + 200, Lv.Grid.Top[1] +6, clSilver, ItemColor, "目前图显关闭");
		}
	}else{
		if(GraphUsing){
			TextRender_string24(Lv.Grid.Left[1] + 200, Lv.Grid.Top[1] +6, clNearWhite, ItemColor, "Graphic Displayer Enabled");
		}else{
			TextRender_string24(Lv.Grid.Left[1] + 200, Lv.Grid.Top[1] +6, clSilver, ItemColor, "Graphic Displayer Disabled");
		}
	}
}

void TGraphDevCfg::FullRedraw(int Prm)
{	
	if(Prm == 0){
		RenderBackGround();
		DrawSelf();
	}else
	if(Prm == 1){
		RectFillRender(GuiRedrawDataList[1][0], GuiRedrawDataList[1][1], GuiRedrawDataList[1][2], GuiRedrawDataList[1][3], ContentColor);
		for(int i=0; i<Lv.Grid.UsingCount; i++)RectFillRender(Lv.Grid.Left[i], Lv.Grid.Top[i], Lv.Grid.Right[i], Lv.Grid.Bottom[i], ItemColor);
		DrawFixText();
		TextDigitRender2_24(Lv.Grid.Left[0] + 310, Lv.Grid.Top[0] +6, clNearWhite, MainCtl.fData.Split.MyNum);
		IList->EditCtlNum.Init(Lv.Grid.Left[1] +20, Lv.Grid.Top[1] +36, 36, 32, 0,0, 1, clNearWhite);
		IList->EditCtlNum.SetMaxLen(2);
		IList->EditCtlNum.TextClear();
		IList->EditCtlNum.Str.FromUInt2Dg(GraphAddr);
		IList->EditCtlNum.SetPstTail();
		this->CrtNum = GraphAddr;
		if( (this->CrtNum >1) && (this->CrtNum <64) ) {
			CrtNumValid = 1;
			IList->EditCtlNum.SelectedColor = clBlue;
		}else{
			CrtNumValid = 0;
			this->CrtNum =0;
			IList->EditCtlNum.SelectedColor = clRed;
		}
		IList->EditCtlNum.Str.FromUInt2Dg(this->CrtNum);
		DrawLineType();
		IList->EditCtlNum.Show();
		
		if(IsPermission){
			PmsIntervene4Gui.ReDraw4GuiRecall();
		}else{
			Check4Selected();
		}
	}
	ShowSysState();
}

void TGraphDevCfg::DrawLineType()
{
	if( GraphLineType == 0){
		TRoundSquare::sDrawBySize(xRs485, Lv.Grid.Top[0] + 40, dWWidth, dWHeigh, dRoundR, dWdClr , 1);
		TRoundSquare::sDrawBySize(xCan,  Lv.Grid.Top[0] + 40, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
	}else{
		TRoundSquare::sDrawBySize(xRs485, Lv.Grid.Top[0] + 40, dWWidth, dWHeigh, dRoundR, dWdDisabelClr , 0);
		TRoundSquare::sDrawBySize(xCan,  Lv.Grid.Top[0] + 40, dWWidth, dWHeigh, dRoundR,  dWdClr , 1);
	}
}

//______________________________________________________________________________________________________________________________
void TGraphDevCfg::ClearSelected(void)
{
	switch(CtlIndex){
		case 0:
			TRoundSquare::sSelected(xRs485, Lv.Grid.Top[0]+40, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 1:
			TRoundSquare::sSelected(xCan, Lv.Grid.Top[0]+40, dWWidth, dWHeigh, 4, ItemColor);
			break;
		case 2:
			IList->EditCtlNum.Selected = 0;
			IList->EditCtlNum.Show();
			break;
		case 3:
			if(LanguageEnCn==0)	TRoundRect::sDrawBySize(xActive, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "开启", 26, clNearBlack);
			else 				TRoundRect::sDrawBySize(xActive, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "Enable", 14, clNearBlack);
			break;
		case 4:
			if(LanguageEnCn==0)	TRoundRect::sDrawBySize(xClose, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "关闭", 26, clNearBlack);
			else				TRoundRect::sDrawBySize(xClose, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clNearWhite, "Disable", 14, clNearBlack);
			break;
		default:

			break;
	}		
}

void TGraphDevCfg::Check4Selected(void)
{
	switch(CtlIndex){
		case 0:
			TRoundSquare::sSelected(xRs485, Lv.Grid.Top[0]+40, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 1:
			TRoundSquare::sSelected(xCan, Lv.Grid.Top[0]+40, dWWidth, dWHeigh, 4, clNearWhite);
			break;
		case 2:
			IList->EditCtlNum.Selected = 1;
			IList->EditCtlNum.SetPstTail();
			IList->EditCtlNum.Show();
			break;
		case 3:
			if(LanguageEnCn==0)	TRoundRect::sDrawBySize(xActive, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clBlue, "开启", 26, clNearWhite);
			else				TRoundRect::sDrawBySize(xActive, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clBlue, "Enable", 14, clNearWhite); 
			break;
		case 4:
			if(LanguageEnCn==0)	TRoundRect::sDrawBySize(xClose, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clBlue, "关闭", 26, clNearWhite);
			else				TRoundRect::sDrawBySize(xClose, 	Lv.Grid.Top[1] + 80, 112, 30, 7, clBlue, "Disable", 14, clNearWhite); 
			break;
		default:

			break;
	}		
}

void TGraphDevCfg::PermissionCmdReturnDraw()
{
	RectFillRender(90, Lv.Grid.Bottom[1] +8, 706, Lv.Grid.Bottom[1] +28 + 140, ContentColor);
	Check4Selected();
}

void TGraphDevCfg::ShowSta()
{
	if(LanguageEnCn==0){
		if(OpaState ==0){
			TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +8, clNearWhite, ContentColor, "        ");
		}else
		if(OpaState ==1){
			TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +8, clNearWhite, ContentColor, "配置成功");
		}else
		if(OpaState ==2){
			TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +8, clNearWhite, ContentColor, "配置失败");
		}
	}else{
		if(OpaState ==0){
			TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +8, clNearWhite, ContentColor, "                   ");
		}else
		if(OpaState ==1){
			TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +8, clNearWhite, ContentColor, "Configured OK      ");
		}else
		if(OpaState ==2){
			TextRender_string24(Lv.Grid.Left[2] + 10, Lv.Grid.Top[2] +8, clNearWhite, ContentColor, "Failed To Configure");
		}
	}
}

void TGraphDevCfg::ShowSta(unsigned char aSta)
{
	OpaState = aSta;
	ShowSta();
}

void TGraphDevCfg::PermissionCmdGO()
{
	int i =0;
	unsigned char tCrtNum = GraphAddr;
	unsigned char tLineType = GraphLineType;
	unsigned char tActive = GraphUsing;
	if(PermissionCmd == 1){
		//Go Active
		WriteCrtCfg(GraphLineType, GraphAddr, 1);
		ReadCrtCfg();
		i=1;
	}else
	if(PermissionCmd == 2){
		//Do Close
		WriteCrtCfg(GraphLineType, GraphAddr, 0);
		ReadCrtCfg();
		i=2;
	}else
	if(PermissionCmd == 11){
		//Set Rs485
		WriteCrtCfg(0, GraphAddr, GraphUsing);
		ReadCrtCfg();
		i=3;
	}else
	if(PermissionCmd == 12){
		//Set CAN
		WriteCrtCfg(1, GraphAddr, GraphUsing);
		ReadCrtCfg();
		i=4;
	}else
	if(PermissionCmd == 13){
		//Set Crt Num
		WriteCrtCfg(GraphLineType, this->CrtNum, GraphUsing);
		ReadCrtCfg();
		i=5;
	}
	if(i){
		if(i == 1){
			if( (tCrtNum == GraphAddr) && (tLineType == GraphLineType) && (1 == GraphUsing) ){
				ShowSta(1);
			}else{
				ShowSta(2);
			}
			ShowSysState();
		}else
		if(i == 2){
			if( (tCrtNum == GraphAddr) && (tLineType == GraphLineType) && (0 == GraphUsing) ){
				ShowSta(1);
			}else{
				ShowSta(2);
			}
			ShowSysState();
		}else
		if(i == 3){
			if( (tCrtNum == GraphAddr) && (0 == GraphLineType) && (0 == GraphUsing) ){
				ShowSta(1);
			}else{
				ShowSta(2);
			}
		}else
		if(i == 4){
			if( (tCrtNum == GraphAddr) && (1 == GraphLineType) && (0 == GraphUsing) ){
				ShowSta(1);
			}else{
				ShowSta(2);
			}
		}else
		if(i == 5){
			if( (this->CrtNum == GraphAddr) && (tLineType == GraphLineType) && (tActive == GraphUsing) ){
				ShowSta(1);
			}else{
				ShowSta(2);
			}
		}
		
		DrawLineType();
		this->CrtNum = GraphAddr;
		if( (this->CrtNum >0) && (this->CrtNum <65) ) {
			CrtNumValid = 1;
			IList->EditCtlNum.SelectedColor = clBlue;
		}else{
			CrtNumValid = 0;
			this->CrtNum =0;
			IList->EditCtlNum.SelectedColor = clRed;
		}
		IList->EditCtlNum.Str.FromUInt2Dg(this->CrtNum);
		DrawLineType();
		IList->EditCtlNum.Show();
	}
}


//_____________________________________________________________________________________________________________________________

TGuiMsgReturn TGraphDevCfg::KeyIn(unsigned char aKey)
{
	TGuiMsgReturn aMsg = guiMsgNone;
	TGuiMsgReturn PmsRtnMsg = guiMsgNone;
	unsigned char aP0,aP1,Err;
	unsigned char x,y,aCh;
	unsigned int aAddr, HadPrc;
	TDMix aFullPath;
	int NoOpa =1;

	if(IsPermission){
		PmsRtnMsg = PmsIntervene4Gui.KeyIn(aKey);
		if(PmsRtnMsg == guiMsgOkAndReturn){
			//Enter And Run Go
			IsPermission = 0;
			PermissionCmdReturnDraw();
			PermissionCmdGO();
		}else
		if(PmsRtnMsg == guiMsgReturn){
			//Not Enter Redraw
			IsPermission = 0;
			PermissionCmdReturnDraw();
		}
		return aMsg;
	}else{
		switch(aKey){
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			case VK_LEFT:
			case VK_RIGHT:
			case VK_DELETE:
				HadPrc =0;
				if( (aKey == VK_LEFT) || (aKey == VK_RIGHT) ){
					if(CtlIndex == 0){
						if(aKey == VK_RIGHT){
							ClearSelected();
							CtlIndex++;
							Check4Selected();
							HadPrc =1;
						}
					}else
					if(CtlIndex == 1){
						if(aKey == VK_LEFT){
							ClearSelected();
							CtlIndex--;
							Check4Selected();
							HadPrc =1;
						}
					}else
					if(CtlIndex == 3){
						if(aKey == VK_RIGHT){
							ClearSelected();
							CtlIndex++;
							Check4Selected();
							HadPrc =1;
						}
					}else
					if(CtlIndex == 4){
						if(aKey == VK_LEFT){
							ClearSelected();
							CtlIndex--;
							Check4Selected();
							HadPrc =1;
						}
					}
				}
				if(HadPrc == 0){
					if(CtlIndex == 2){
						IList->EditCtlNum.KeyIn(aKey);
						int iVal;
						iVal = IList->EditCtlNum.Str.ToInteger();
						if( (iVal <2) || (iVal > 63) ){
							IList->EditCtlNum.SelectedColor = clRed;
							CrtNumValid = 0;
							this->CrtNum = 99;
						}else{
							IList->EditCtlNum.SelectedColor = clBlue;
							CrtNumValid = 1;
							this->CrtNum = iVal;
						}
						IList->EditCtlNum.Show();
					}
				}
				break;
			case VK_UP:
				if(CtlIndex >0){
					if(CtlIndex == 2){
						if(CrtNumValid){
							ClearSelected();
							CtlIndex--;
							Check4Selected();
						}
					}else{
						ClearSelected();
						CtlIndex--;
						Check4Selected();
					}
				}else{
					ClearSelected();
					CtlIndex=4;
					Check4Selected();
				}
				break;
			case VK_DOWN:
				if(CtlIndex <4){
					if(CtlIndex == 2){
						if(CrtNumValid){
							ClearSelected();
							CtlIndex++;
							Check4Selected();
						}
					}else{
						ClearSelected();
						CtlIndex++;
						Check4Selected();
					}
				}else{
					ClearSelected();
					CtlIndex=0;
					Check4Selected();
				}
				break;
			case VK_TAB:

				break;
			case dfKEY_SETUP:
				if(CtlIndex == 0){
					PermissionCmd = 11;
					if(SystemPermission > 2){
						PermissionCmdGO();
						NoOpa =0;
					}else{
						IsPermission = 1;
						ClearSelected();
						PmsIntervene4Gui.Show4Gui(100, Lv.Grid.Bottom[1] + 20, 600 , 140, 3);
						NoOpa =0;
					}
				}else
				if(CtlIndex == 1){
					PermissionCmd = 12;
					if(SystemPermission > 2){
						PermissionCmdGO();
						NoOpa =0;
					}else{
						IsPermission = 1;
						ClearSelected();
						PmsIntervene4Gui.Show4Gui(100, Lv.Grid.Bottom[1] + 20, 600 , 140, 3);
						NoOpa =0;
					}
				}
				break;
			case VK_EXECUTE:
				if(CtlIndex == 0){
					PermissionCmd = 11;
					if(SystemPermission > 2){
						PermissionCmdGO();
						NoOpa =0;
					}else{
						IsPermission = 1;
						ClearSelected();
						PmsIntervene4Gui.Show4Gui(100, Lv.Grid.Bottom[1] + 20, 600 , 140, 3);
						NoOpa =0;
					}
				}else
				if(CtlIndex == 1){
					PermissionCmd = 12;
					if(SystemPermission > 2){
						PermissionCmdGO();
						NoOpa =0;
					}else{
						IsPermission = 1;
						ClearSelected();
						PmsIntervene4Gui.Show4Gui(100, Lv.Grid.Bottom[1] + 20, 600 , 140, 3);
						NoOpa =0;
					}
				}else
				if(CtlIndex == 2){
					if(this->CrtNumValid){
						PermissionCmd = 13;
						if(SystemPermission > 2){
							PermissionCmdGO();
							NoOpa =0;
						}else{
							IsPermission = 1;
							ClearSelected();
							PmsIntervene4Gui.Show4Gui(100, Lv.Grid.Bottom[1] + 20, 600 , 140, 3);
							NoOpa =0;
						}
					}
				}else
				if(CtlIndex == 3){
					//Active
					PermissionCmd = 1;
					if(SystemPermission > 2){
						PermissionCmdGO();
						NoOpa =0;
					}else{
						IsPermission = 1;
						ClearSelected();
						PmsIntervene4Gui.Show4Gui(100, Lv.Grid.Bottom[1] + 20, 600 , 140, 3);
						NoOpa =0;
					}
				}else
				if(CtlIndex == 4){
					//Close
					PermissionCmd = 2;
					if(SystemPermission > 2){
						PermissionCmdGO();
						NoOpa =0;
					}else{
						IsPermission = 1;
						ClearSelected();
						PmsIntervene4Gui.Show4Gui(100, Lv.Grid.Bottom[1] + 20, 600 , 140, 3);
						NoOpa =0;
					}
				}
				break;
			case VK_RETURN:
				IsShowing = 0;
				aMsg = guiMsgReturn;
				break;
		}
		if(NoOpa){
			ShowSta(0);
		}
	}

	return aMsg;	
}

int TGraphDevCfg::ExtRequst(unsigned char Prm)
{
	IsShowing =0;
	return 0;
}

void TGraphDevCfg::WriteCrtCfg(unsigned char aLineType, unsigned char aCrtNum, unsigned char aActive)
{
	volatile unsigned int aWait;
	unsigned int aAddr;
	unsigned char tData[4];
	int i;
	//Read ExistTable 
	tData[0] = aActive;
	tData[1] = aCrtNum;
	tData[2] = aLineType;
	tData[3] = 0;
	aAddr = dEepAddrCrtCfg + 0;
	sDelayMs(10);
	eeprom_write_byte_via_page(0, aAddr, tData, 4);
	sDelayMs(10);
}

void TGraphDevCfg::ReadCrtCfg()
{
	unsigned int aAddr;
	int i;
	unsigned char tData[4];
	//Read ExistTable 
	aAddr = dEepAddrCrtCfg;
	sDelayMs(10);
	eeprom_read_byte(0, aAddr, tData, 4);
	
	GraphUsing = tData[0];
	GraphAddr = tData[1];
	GraphLineType = tData[2];
}

void TGraphDevCfg::sRecoverSetDefault()
{
	volatile unsigned int aWait;
	unsigned int aAddr;
	unsigned char tData[4];
	int i;
	//Read ExistTable 
	tData[0] = 0;
	tData[1] = 2;
	tData[2] = 0;
	tData[3] = 0;
	aAddr = dEepAddrCrtCfg + 0;
	sDelayMs(10);
	eeprom_write_byte_via_page(0, aAddr, tData, 4);
	sDelayMs(10);

	//Read ExistTable 
	sDelayMs(10);
	eeprom_read_byte(0, aAddr, tData, 4);
	
	GraphUsing = tData[0];
	GraphAddr = tData[1];
	GraphLineType = tData[2];	
}








