
#include "lt776_gra.h"

extern void LT268_TFT_DrawPoint(UINT16 x,UINT16 y,UINT16 color);
extern void LT768_TFT_DrawSquare_Fill(UINT16 x1,UINT16 y1,UINT16 x2,UINT16 y2,UINT16 color);
extern void LT768_TFT_ShowAscii(UINT16 x,UINT16 y,UINT8 size,UINT8 mode,UINT16 FontColor,UINT16 BackGroundColor,UINT8 *str);

UINT8 DigitToHexAscii(char data)
{
	data&=0x0f;
	if (data>=10) data+=7;
	data+=0x30;
	return(data);
}

void ByteToHexAscii(UINT8 data,char *temp)
{
	*temp=DigitToHexAscii((data&0xF0)>>4);
	*(temp+1)=DigitToHexAscii(data&0x0f);
}

void Show8BitValue(UINT16 x,UINT16 y,UINT8 data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	ByteToHexAscii((UINT8)(data),temp);
	LT768_TFT_ShowAscii(x<<3,y<<4,16,0,fgColor,bgColor,temp);
}

void Show16BitValue(UINT16 x,UINT16 y,UINT16 data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	
	ByteToHexAscii((char)(data>>8),temp);
	LT768_TFT_ShowAscii(x<<3,y<<4,16,0,fgColor,bgColor,temp);
	
	ByteToHexAscii((char)data,temp);
	LT768_TFT_ShowAscii((x+2)<<3,y<<4,16,0,fgColor,bgColor,temp);
}

void Show32BitValue(UINT16 x,UINT16 y,UINT32 data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	
	ByteToHexAscii((char)(data>>24),temp);
	LT768_TFT_ShowAscii(x<<3,y<<4,16,0,fgColor,bgColor,temp);
	ByteToHexAscii((char)(data>>16),temp);
	LT768_TFT_ShowAscii((x+2)<<3,y<<4,16,0,fgColor,bgColor,temp);

	ByteToHexAscii((char)(data>>8),temp);
	LT768_TFT_ShowAscii((x+4)<<3,y<<4,16,0,fgColor,bgColor,temp);
	ByteToHexAscii((char)data,temp);
	LT768_TFT_ShowAscii((x+6)<<3,y<<4,16,0,fgColor,bgColor,temp);
}

void Show16BitDecimal(UINT16 x,UINT16 y,short int data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	UINT16 value,tmpValue=1000,i;

	for (i=0;i<4;i++)
	{
		value=data/tmpValue;
		data=data%tmpValue;
		temp[0]=DigitToHexAscii((char)(value));
		LT768_TFT_ShowAscii((x+i)<<3,y<<4,16,0,fgColor,bgColor,temp);		
		tmpValue/=10;
	}
	
}

void Show32BitDecimal(UINT16 x,UINT16 y,int data,UINT16 fgColor,UINT16 bgColor)
{
	char temp[3];
	UINT16 i;
	UINT32 value,tmpValue=10000000;

	for (i=0;i<8;i++)
	{
		value=data/tmpValue;
		data=data%tmpValue;
		temp[0]=DigitToHexAscii((char)(value));
		LT768_TFT_ShowAscii((x+i)<<3,y<<4,16,0,fgColor,bgColor,temp);		
		tmpValue/=10;
	}

}
