/*********************************************************************
*
*       TouchTask
*
* Function decription:
*   Handles a controller driven touch screen and uses GUI_TOUCH_StoreState()
*   to pass the values to emWin. Please note that multitasking for
*   emWin is not required at this point.
*/
void TouchTask(void) {
  static U16 xOld;
  static U16 yOld;
  static U8  PressedOld;
  U16 x, y, xDiff, yDiff;
  U8  Pressed;

  do {
    Pressed = // TBD: Insert function which returns:
              //      1, if the touch screen is pressed
              //      0, if the touch screen is released
    //
    // Touch screen is pressed
    //
    if (Pressed) {
      x = // TBD: Insert function which reads current x value
      y = // TBD: Insert function which reads current y value
      //
      // The touch has already been pressed
      //
      if (PressedOld == 1) {
        //
        // Calculate difference between new and old position
        //
        xDiff = (x > xOld) ? (x - xOld) : (xOld - x);
        yDiff = (y > yOld) ? (y - yOld) : (yOld - y);
        //
        // Store state if new position differs significantly from old position
        //
        if (xDiff + yDiff > 2) {
          xOld = x;
          yOld = y;
          GUI_TOUCH_StoreState(x, y);
        }
      }
      //
      // The touch was previously released
      // Store state regardless position
      //
      } else {
        if ((x != 0) && (y != 0)) {
          xOld = x;
          yOld = y;
          PressedOld = 1;
          GUI_TOUCH_StoreState(x, y);
        }
      }
    //
    // Touch screen is not pressed
    // Store state if it was released recently
    //
    } else {
Exemple #2
0
void GUI_TOUCH_Exec(void)
{
    int x,y;
    // calculate Min / Max values 
    if (xyMinMax[0].Min < xyMinMax[0].Max)
    {
        xMin = xyMinMax[0].Min;
        xMax = xyMinMax[0].Max;
    }
    else
    {
        xMax = xyMinMax[0].Min;
        xMin = xyMinMax[0].Max;
    }
    if (xyMinMax[1].Min < xyMinMax[1].Max)
    {
        yMin = xyMinMax[1].Min;
        yMax = xyMinMax[1].Max;
    }
    else
    {
        yMax = xyMinMax[1].Min;
        yMin = xyMinMax[1].Max;
    }
		//参数合法性检测
		if((gpCHGUI->tops->ctrl_get_touch_x == NULL) || (gpCHGUI->tops->ctrl_get_touch_y == NULL))
		{
			return;
		}
    xPhys = gpCHGUI->tops->ctrl_get_touch_x();
    yPhys = gpCHGUI->tops->ctrl_get_touch_y();
    // Convert values into logical values 
    #if !GUI_TOUCH_SWAP_XY   // Is X/Y swapped ?
      x = xPhys;
      y = yPhys;
    #else
      x = yPhys;
      y = xPhys;
    #endif
    if ((x < xMin) || (x > xMax)  || (y < yMin) || (y > yMax)) 
    {
			GUI_TOUCH_StoreState(-1, -1);
    }
    else 
    {
        x = _AD2X(x);
        y = _AD2Y(y);
			GUI_TOUCH_StoreState(x, y);
    }
}
void Calibration(void) 
{
  int ax_Phys[5],ay_Phys[5];
  int move;
/* calculate log. Positions */
  int ax[5] = { 50, LCD_XSIZE-50, LCD_XSIZE-50, 50, (LCD_XSIZE/2)-10};
  int ay[5] = { 50, 50, LCD_YSIZE-50, LCD_YSIZE-50, (LCD_YSIZE/2)-10};

//  GUI_TOUCH_SetDefaultCalibration();
/* _Calibrate upper left */
 for( move =0 ; move<5; move++){
  GUI_SetBkColor(GUI_RED);  
  GUI_Clear();
  GUI_SetColor(GUI_WHITE);
  GUI_FillCircle(ax[move], ay[move], 10);
  GUI_SetColor(GUI_RED);    
  GUI_FillCircle(ax[move], ay[move], 5);
  GUI_SetColor(GUI_WHITE);

  do {
   GUI_PID_STATE State;
   GUI_TOUCH_GetState(&State);
   if (State.Pressed) {
   ax_Phys[move] = State.x;//GUI_TOUCH_GetxPhys();
   ay_Phys[move] = State.y;//GUI_TOUCH_GetyPhys();
   break;
   }
      GUI_Delay (100);
    } while (1); 
  GUI_Delay (4000);
/*  release */
  GUI_TOUCH_StoreState(-1,-1); 
 }

 	GUI_myTOUCH_Calibrate(ax,ay,ax_Phys,ay_Phys);
    GUI_Delay(500);
    GUI_DispStringAt  ("Please touch display to continue...",50,20);
    GUI_TOUCH_StoreState(-1,-1); 

    do {
      GUI_PID_STATE State;
      GUI_TOUCH_GetState(&State);
      if (State.Pressed)
        break;
      GUI_Delay (10);
    } while (1);
}
/*********************************************************************
*
*       GUI_TOUCH_StoreUnstable
*/
void GUI_TOUCH_StoreUnstable(int x, int y) {
  int xDiff, yDiff;
  xDiff = abs (x - _x);
  yDiff = abs (y - _y);
  if (xDiff + yDiff > 2) {
    _x = x;
    _y = y;
    GUI_TOUCH_StoreState(x, y);
  }
}