大学生
最后登录1970-1-1
在线时间 小时
注册时间2015-3-15
|
为什么触摸矫正一直循环下去
int Touch_Calibrate(void)
{
#if 1
uint8_t i;
u16 test_x=0,test_y=0;
u16 gap_x=0,gap_y=0;
Coordinate * Ptr;
for(i=0;i<4;i++)
{
LCD_Clear(0,0,320,240,BACKGROUD);
LCD_DispStr(110,110,(uint8_t *)"Touch Calibrate....",RED);
LCD_DispNum(150,90,i+1,RED);
Delay_SysTick(500000);
DrawCross(DisplaySample.x,DisplaySample.y);
do
{
Ptr=Read_2046_2();
}
while( Ptr == (void*)0 );
ScreenSample.x= Ptr->x;
ScreenSample.y= Ptr->y;
}
Cal_Touch_Para(&DisplaySample[0],&ScreenSample[0],&touch_para);
test_x=((touch_para.An*ScreenSample[3].x) \
+(touch_para.Bn*ScreenSample[3].y) \
+touch_para.Cn)/touch_para.Divider;
test_y=((touch_para.Dn*ScreenSample[3].x) \
+(touch_para.En*ScreenSample[3].x) \
+touch_para.Fn)/touch_para.Divider;
gap_x =(test_x>DisplaySample[3].x)?(test_x-DisplaySample[3].x)DisplaySample[3].x-test_x);
gap_y =(test_y>DisplaySample[3].y)?(test_y-DisplaySample[3].y)DisplaySample[3].y-test_y);
LCD_Clear(0, 0, 320, 240, BACKGROUD);
if((gap_x>10)||(gap_y>10))
{
LCD_DispStr(100, 100, (uint8_t *)"Calibrate fail", RED);
LCD_DispStr(100, 120, (uint8_t *)"try again", RED);
Delay_SysTick(2000);
return 1;
}
aa1 = (touch_para.An*1.0)/touch_para.Divider;
bb1 = (touch_para.Bn*1.0)/touch_para.Divider;
cc1 = (touch_para.Cn*1.0)/touch_para.Divider;
aa2 = (touch_para.Dn*1.0)/touch_para.Divider;
bb2 = (touch_para.En*1.0)/touch_para.Divider;
cc2 = (touch_para.Fn*1.0)/touch_para.Divider;
#elif 0
aa1=0.088370;
bb1=-0.000468;
cc1=-24.042172;
aa2=0.0001891;
bb2=0.062395;
cc2=-10.223455;
#endif
LCD_DispStr(100,100,(uint8_t *) "Calibrate Succeed",RED);
Delay_SysTick(1000);
return 0;
}
Coordinate *Read_2046_2(void)
{
static Coordinate screen2;
int TP_X[1],TP_Y[1];
uint8_t count=0;
int buffer[2][10]={{0},{0}}; /*×ø±êXoíY½øDD¶à′Î2éÑù*/
int min_x,max_x;
int min_y,max_y;
int i=0;
do
{ /* Ñ-»·2éÑù10′Î */
Touch_GetAdXY(TP_X,TP_Y);
buffer[0][count]=TP_X[0];
buffer[1][count]=TP_Y[0];
count++;
}
while(!INT_IN_2046&& count<10);
if(INT_IN_2046)
{
touch_flag = 0;
}
if(count ==10)
{
max_x=min_x=buffer[0][0];
max_y=min_y=buffer[1][0];
for(i=1; i<10; i++)
{
if(buffer[0]<min_x)
{
min_x=buffer[0];
}
else
if(buffer[0]>max_x)
{
max_x = buffer[0];
}
}
for(i=1; i<10; i++)
{
if(buffer[1]<min_y)
{
min_y=buffer[1];
}
else
if(buffer[1]>max_y)
{
max_y = buffer[1];
}
}
screen2.x=(buffer[0][0]+buffer[0][1]+buffer[0][2]+buffer[0][3]+buffer[0][4]+buffer[0][5]+buffer[0][6]+buffer[0][7]+buffer[0][8]+buffer[0][9]-min_x-max_x)>>3;
screen2.y=(buffer[1][0]+buffer[1][1]+buffer[1][2]+buffer[1][3]+buffer[1][4]+buffer[1][5]+buffer[1][6]+buffer[1][7]+buffer[1][8]+buffer[1][9]-min_y-max_y)>>3;
return &screen2;
}
return 0;
}
|
|