#include "geometry.h"
#include "font.h"

int lcd_mainpage(void)
{
	unsigned int fb_base;
	int xres, yres, bpp;
	int x, y, pressure;
	int x1, y1;
	unsigned char *p0;
	unsigned short *p;
	unsigned int *p2;
	int i,j,temp1,temp2;
	char *name[10] = {"  LED ","Button","  LCD ","  TS  ","  IIC ","  SPI ","  Res "," DTH11","DS18B20","HS0038"};
	

	/* 获得LCD的参数: fb_base, xres, yres, bpp */
	get_lcd_params(&fb_base, &xres, &yres, &bpp);

	clear_screen(0x80FFFF);

	/* 输出文字 */
	fb_print_string(xres/2 - 8 * 12, 30, "Module Function Test Menu", 0xff);
	/* 画圆 */

	for(j = 0; j< 2; j++)
	{
		for( i = 0; i< 5; i++)
		{
			draw_circle(60 + i * 90, 110+j * 90 , 40, 0x800000);
			fb_print_string(60 + i * 90-24, 110+j * 90-8, name[j*5+i], 0xA0);
		}

	}

	while (1)
	{
		if (ts_read(&x, &y, &pressure) == 0)
		{
			
			if (pressure)
			{
				do {
					ts_read_raw(&x1, &y1, &pressure); 
				} while (pressure);

				for(j = 0; j< 2; j++)
				{
					for( i = 0; i< 5; i++)
					{
						temp1 = x - (60 + i * 90);
						temp2 = y - ( 110+j * 90);
						if( (temp1 * temp1 + temp2 * temp2) - 40*40 < 0 )
							return j*5+i;
					}

				}
				
			}
		}
	}

	

}