void _ExecCalibration(void) {
  int ax_Phys[2],ay_Phys[2];
/* calculate log. Positions */
  int ax[2] = { 15, LCD_XSIZE -1-15};
//  const int ay[2] = { 15, LCD_YSIZE-1-15};
  int ay[2] = { LCD_YSIZE-1-15, 15};

  CalibrationComplete = 0;
  GUI_TOUCH_SetDefaultCalibration();
/* _Calibrate upper left */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[0], ay[0], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[0], ay[0], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringAt("Press here", ax[0]+20, ay[0]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed) {
      ax_Phys[0] = GUI_TOUCH_GetxPhys();
      ay_Phys[0] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (100);
  } while (1);
/* Tell user to release */
  GUI_Clear();
  GUI_DispStringAt("OK", ax[0]+20, ay[0]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed == 0) {
      break;
    }
    GUI_Delay (100);
  } while (1);
/* _Calibrate lower right */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[1], ay[1], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[1], ay[1], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_SetTextAlign(GUI_TA_RIGHT);
  GUI_DispStringAt("Press here", ax[1]-20, ay[1]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed) {
      ax_Phys[1] = GUI_TOUCH_GetxPhys();
      ay_Phys[1] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (100);
  } while (1);
  GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]);
  GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]);
  { /* calculate and display values for configuration file */
    int x0, x1;
    int y0, y1;
    GUI_Clear();
    _Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1], &x0, &x1);
    _Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1], &y0, &y1);
    GUI_DispStringAt("x0: ", 0, 0); GUI_DispDec(x0, 4); GUI_DispNextLine();
    GUI_DispString  ("x1: ");       GUI_DispDec(x1, 4); GUI_DispNextLine();
    GUI_DispString  ("y0: ");       GUI_DispDec(y0, 4); GUI_DispNextLine();
    GUI_DispString  ("y1: ");       GUI_DispDec(y1, 4); GUI_DispNextLine();
    GUI_DispString  ("Please touch display to continue...");
    GUI_Delay(1000);
    do {
      GUI_PID_STATE State;
      GUI_TOUCH_GetState(&State);
      if (State.Pressed)
        break;
      GUI_Delay (10);
    } while (1);
  }
  CalibrationComplete = 1;
}
Ejemplo n.º 2
0
void _ExecCalibration(void) {
  int x,y;
  uint16_t data[6];
  uint16_t get_data[6];
  int ax_Phys[2],ay_Phys[2];
/* calculate log. Positions */
  int ax[2] = { 15, LCD_XSIZE -1-15};
//  const int ay[2] = { 15, LCD_YSIZE-1-15};
  int ay[2] = { LCD_YSIZE-1-15, 15};
  GUI_TOUCH_SetDefaultCalibration();
/* _Calibrate upper left */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[0], ay[0], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[0], ay[0], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_DispStringAt("Press here", ax[0]+20, ay[0]);
  do {

#if 0
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
	 if (State.Pressed) {
#endif

#if 1
  x = TPReadX();
  y = TPReadY();
  if ((x>=3700)&&(y>=3400)&&(x<3800)&&(y<3600)) {

#endif
      ax_Phys[0] = GUI_TOUCH_GetxPhys();
      ay_Phys[0] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (3000);
  } while (1);
/* Tell user to release */
  GUI_Clear();
  GUI_DispStringAt("OK", ax[0]+20, ay[0]);
  do {
    GUI_PID_STATE State;
    GUI_TOUCH_GetState(&State);
    if (State.Pressed == 0) {
      break;
    }
    GUI_Delay (100);
  } while (1);
/* _Calibrate lower right */
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);  GUI_FillCircle(ax[1], ay[1], 10);
  GUI_SetColor(GUI_RED);    GUI_FillCircle(ax[1], ay[1], 5);
  GUI_SetColor(GUI_WHITE);
  GUI_SetTextAlign(GUI_TA_RIGHT);
  GUI_DispStringAt("Press here", ax[1]-20, ay[1]);
  do {

#if 1
  x = TPReadX();
  y = TPReadY();
  if ((y>450)&&(y<620)&&(x>350)&&(x<450)) {
#endif

#if 0
	GUI_PID_STATE State;
  	GUI_TOUCH_GetState(&State);
	if (State.Pressed) {
#endif

      ax_Phys[1] = GUI_TOUCH_GetxPhys();
      ay_Phys[1] = GUI_TOUCH_GetyPhys();
      break;
    }
    GUI_Delay (3000);
  } while (1);
  GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]);
  GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]);
  { /* calculate and display values for configuration file */
    int x0, x1;
    int y0, y1;
    GUI_Clear();
    _Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1], &x0, &x1);
    _Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1], &y0, &y1);
    GUI_DispStringAt("x0: ", 0, 0); GUI_DispDec(x0, 4); GUI_DispNextLine();
    GUI_DispString  ("x1: ");       GUI_DispDec(x1, 4); GUI_DispNextLine();
    GUI_DispString  ("y0: ");       GUI_DispDec(y0, 4); GUI_DispNextLine();
    GUI_DispString  ("y1: ");       GUI_DispDec(y1, 4); GUI_DispNextLine();
    GUI_DispString  ("Please touch display to continue...");
    GUI_Delay(1000);

	data[0]=  CAL_READY;
	data[1]= ax_Phys[0];
	data[2]= ay_Phys[0];
	data[3]= ax_Phys[1];
	data[4]= ay_Phys[1];

	#if 1
	save_calibrate_to_flash(data);
	get_calibrate_data(get_data);

	GUI_DispStringAt("x0: ", 100, 0); GUI_DispDec(get_data[1], 4); GUI_DispNextLine();
    GUI_DispString  ("x1: ");       GUI_DispDec(get_data[2], 4); GUI_DispNextLine();
    GUI_DispString  ("y0: ");       GUI_DispDec(get_data[3], 4); GUI_DispNextLine();
    GUI_DispString  ("y1: ");       GUI_DispDec(get_data[4], 4); GUI_DispNextLine();
	GUI_DispString  ("state: ");       GUI_DispDec(get_data[0], 4); GUI_DispNextLine();
	#endif

    do {
      GUI_PID_STATE State;
      GUI_TOUCH_GetState(&State);
      if (State.Pressed)
      break;
      GUI_Delay (10);
    } while (1);
  }
}



int run_cal(void)
{
  if(get_calibrate_state()== CAL_READY)
  {
  	get_calibration();
  }else{
	#if 1
  	 _ExecCalibration();
	#endif	

	#if 0
	Calibration();
	#endif
  }
}

int get_calibration(void)
{
  uint16_t cal_data[5];
  int ax_Phys[2],ay_Phys[2];
  int ax[2] = { 15, LCD_XSIZE -1-15};
  int ay[2] = { LCD_YSIZE-1-15, 15};

  get_calibrate_data(cal_data);

  ax_Phys[0] = cal_data[1];
  ay_Phys[0] = cal_data[2];
  
  ax_Phys[1] = cal_data[3];
  ay_Phys[1] = cal_data[4];
  
  GUI_TOUCH_Calibrate(GUI_COORD_X, ax[0], ax[1], ax_Phys[0], ax_Phys[1]);
  GUI_TOUCH_Calibrate(GUI_COORD_Y, ay[0], ay[1], ay_Phys[0], ay_Phys[1]);
}


#if 0			

void myAD2XY( int *adx , int *ady ){
 float f_dat;
 int dat1;

 f_dat = (float)(*ady - admy)/(float)(*adx - admx);
 if(f_dat>0){
  if( *adx>admx && admk[2] >=f_dat) dat1 = 1;
  else if( *adx>admx && admk[2] < f_dat ) dat1 =2;//2
  else if( *adx<admx && admk[0] >=f_dat ) dat1 =0;
  else if( *adx<admx && admk[0] < f_dat ) dat1 =3;//0
  else{ dat1 =0; }//*adx =0;*ady =0; }
 }else{
  if( *adx>admx && admk[1] >=f_dat) dat1 = 0;
  else if( *adx>admx && admk[1] < f_dat ) dat1 =1;//1
  else if( *adx<admx && admk[3] >=f_dat ) dat1 =3;
  else if( *adx<admx && admk[3] < f_dat ) dat1 =2;//3
  else{ dat1 =0; }//*adx =0;*ady =0; }
 }
 *adx = (int)(Factors[dat1][0].a*(*adx)+Factors[dat1][0].b*(*ady)+Factors[dat1][0].c); 
 *ady = (int)(Factors[dat1][1].a*(*adx)+Factors[dat1][1].b*(*ady)+Factors[dat1][1].c);
}