#include "geometry.h"
#include "font.h"

int lcd_iicpage(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;
	
	
	i2c_init();
	at24cxx_write(0, "0", 1);
	/* 获得LCD的参数: fb_base, xres, yres, bpp */
	get_lcd_params(&fb_base, &xres, &yres, &bpp);

	clear_screen(0x80FFFF);

	/* 输出文字 */
	//fb_print_string(xres/2 - 8 * 17, yres/2-10, " the data of iic addr0:", 0xA0);


	/* 画圆 */

	draw_circle(xres/2-60,  yres/2+60 , 40, 0x800000);
	fb_print_string(xres/2-60-24, yres/2+60-8, " Read", 0xA0);

	/* 画圆 */

	draw_circle(xres/2+60,  yres/2+60 , 40, 0x800000);
	fb_print_string(xres/2+60-24, yres/2+60-8, " Write", 0xA0);
	
	/* 画圆 */

	draw_circle(xres-60, yres-60 , 40, 0x800000);
	fb_print_string(xres-60-24, yres-60-8, "Return", 0xA0);

	
	while (1)
	{
		if (ts_read(&x, &y, &pressure) == 0)
		{

			if (pressure)
			{

				do {
					ts_read_raw(&x1, &y1, &pressure); 
				} while (pressure);
				
				temp1 = x - (xres-60);
				temp2 = y - (yres-60);
				if( (temp1 * temp1 + temp2 * temp2) - 40*40 < 0 )
				{
					
					return 0;
				}

				temp1 = x - (xres/2-60);
				temp2 = y - ( yres/2+60);
				if( (temp1 * temp1 + temp2 * temp2) - 40*40 < 0 )
				{
				
					do_read_at24cxx();
				}

				temp1 = x - (xres/2+60);
				temp2 = y - ( yres/2+60);
				if( (temp1 * temp1 + temp2 * temp2) - 40*40 < 0 )
				{
					do_write_at24cxx();
				}
			}
		}
	}

	

}


