Touch_calibrate.c

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Touch_calibrate.c

      Source Code

      1. static void _Calibrate(void) {
      2. GUI_PID_STATE State;
      3. int i;
      4. int xSize, ySize;
      5. xSize = LCD_GetXSize();
      6. ySize = LCD_GetYSize();
      7. //
      8. // Calculate reference points depending on LCD size
      9. //
      10. _aRefX[0] = (xSize * 5) / 100;
      11. _aRefY[0] = (ySize * 5) / 100;
      12. _aRefX[1] = xSize - (xSize * 5) / 100;
      13. _aRefY[1] = _aRefY[0];
      14. _aRefX[2] = _aRefX[1];
      15. _aRefY[2] = ySize - (ySize * 5) / 100;
      16. _aRefX[3] = _aRefX[0];
      17. _aRefY[3] = _aRefY[2];
      18. _aRefX[4] = xSize / 2;
      19. _aRefY[4] = ySize / 2;
      20. //
      21. // Draw reference points on LCD
      22. //
      23. GUI_TOUCH_GetState(&State);
      24. State.Pressed = 0;
      25. GUI_SetPenSize(3);
      26. for (i = 0; i < NUM_CALIB_POINTS; i++) {
      27. GUI_Clear();
      28. GUI_DispStringHCenterAt("Please touch the point", LCD_GetXSize() / 2, LCD_GetYSize() / 2 - 60);
      29. GUI_DrawCircle(_aRefX[i], _aRefY[i], 5);
      30. while (State.Pressed != 1) {
      31. GUI_Delay(250);
      32. GUI_TOUCH_GetState(&State);
      33. }
      34. if (State.Pressed == 1) {
      35. //
      36. // Store sample points
      37. //
      38. _aSamX[i] = GUI_TOUCH_GetxPhys();
      39. _aSamY[i] = GUI_TOUCH_GetyPhys();
      40. }
      41. State.Pressed = 0;
      42. GUI_Delay(250);
      43. }
      44. //
      45. // Pass measured points to emWin
      46. //
      47. GUI_TOUCH_CalcCoefficients(NUM_CALIB_POINTS, _aRefX, _aRefY, _aSamX, _aSamY, xSize, ySize);
      48. }
      49. /*********************************************************************
      50. *
      51. * Public code
      52. *
      53. **********************************************************************
      54. */
      55. /*********************************************************************
      56. *
      57. * MainTask
      58. */
      59. void MainTask(void) {
      60. GUI_Init();
      61. //
      62. // Calibrate touch ...
      63. //
      64. _Calibrate();
      65. //
      66. // ... and play with it
      67. //
      68. GUI_CURSOR_Show();
      69. BUTTON_Create(100, 100, 200, 50, 1234, WM_CF_SHOW); // A button to be touched
      70. while (1) {
      71. GUI_Delay(100);
      72. }
      73. }
      Display All
      Hi all,

      I am currently working to calibrate resistive touchscreen using emWin library. I see a sample code provided in the library Touch_calibrate.c

      As I am working on this, I can see that the code seems to be stuck at while (State.Pressed != 1) .
      Also, I was able to implement Touch_sample.c and detect touch to see values changing for both analog inputs and positions.

      If someone came across the same problem could you please advise.

      Please see the code I am currently using.



      Thank you in advance for all your help.

      The post was edited 1 time, last by bio_med ().

    • Hi,

      This can have several reasons.

      Either you never pass an up event (State.Pressed == 0) to emWin or the touch gets passed to emWin with the function GUI_PID_StoreState().

      Try to exchange the calls of GUI_TOUCH_GetState() into GUI_PID_GetState() and/or check how the up events are generated.

      Regards,
      Sven
    • Hi Sven,

      Thank you for your response.
      When you say "I never pass an up event (State.Pressed == 0) to emwin", what do you mean? Is there a part of configuration files where I have to manually add (State.Pressed == 0) ?

      I tried to exchange calls of GUI_TOUCH_GetState() into GUI_PID_GetState() and now even when there is no touch, the code seems to exit out of the (State.Pressed == 0) loop.

      Regards,
      Shamili