Reistive touch issue

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

    • Reistive touch issue

      Am using iMXRT1064 with Emwin library and 7" resistive touch screen. I am using a custom ADC driver to read x and y values.

      // points p0,p1,p2 x and y pixels
      int touchRefValX[3] = {40,760,400};

      int touchRefValY[3] = {24,240,456};
      // ADC x and y values at above points
      int touchSampleValX[3] = {2552,1528,1954};

      int touchSampleValY[3] = {2295,1960,1803};

      the range of ADC values for x and y are always in around 1400 counts to 2500 counts.for 12 bit range should be 0-4096.
      // init
      GUI_TOUCH_CalcCoefficients(3, &touchRefValX[0], &touchRefValY[0], &touchSampleValX[0], &touchSampleValY[0], 800, 480);

      //read touch
      pressed = get_adc(&touchX,&touchY)
      if(pressed == TRUE){
      touchState.Pressed = TRUE;
      touchState.x = touchX;
      touchState.y = touchY;
      prevState = pressed;
      else if(prevState != pressed){
      touchState.x = -1;
      touchState.y = -1;
      touchState.Pressed = FALSE;
      prevState = pressed;
      I get the pressed and un-pressed but actual touch it does not work as expected.
      i was able to debug and found that i don't get the release events always. When i get the release event then it works as expected.
      I mostly get the WM_NOTIFICATION_CLICKED and WM_NOTIFICATION_MOVED_OUT events but rarely get the WM_NOTIFICATION_RELEASED event.

      What am i doing wrong? Any sample code with similar configuration would be helpful.

      Thanks & Regards

      The post was edited 2 times, last by anuj.tanksali ().

    • Hi,

      You are doing this:

      C Source Code

      1. else if(prevState != pressed){
      2. touchState.x = -1;
      3. touchState.y = -1;
      4. touchState.Pressed = FALSE;
      5. prevState = pressed;
      6. GUI_TOUCH_StoreStateEx(&touchState);
      7. }

      This will lead to wrong touch behavior because the generated "up event" will occur at (-1|-1). emWin will check if there is a window/widget below this point and will generate messages accordingly.

      Lets say you press a button at the center of the screen and it will receive a click message. Now you release the touch screen and the up event occurs at (-1|-1), but there is no button and no release event will be thrown.

      Try to declare "touchState" as static and just modify its x and y member when the touch screen is being pressed. Like:

      Source Code

      1. static GUI_PID_STATE touchState;
      2. pressed = get_adc(&touchX,&touchY)
      3. if(pressed == TRUE){
      4. touchState.Pressed = TRUE;
      5. touchState.x = touchX;
      6. touchState.y = touchY;
      7. GUI_TOUCH_StoreStateEx(&touchState);
      8. prevState = pressed;
      9. }
      10. else if(prevState != pressed){
      11. touchState.Pressed = FALSE;
      12. prevState = pressed;
      13. GUI_TOUCH_StoreStateEx(&touchState);
      14. }
      Display All
    • Hi ,

      Thanks for your reply.
      I realized this earlier and had already corrected the code but still same issue.

      Please see latest code below,
      touchState is declared as static

      uint16_t touchX = 0;
      uint16_t touchY = 0;
      uint8_t pressed = FALSE;
      static uint8_t prevState = FALSE;

      // Call the function to get the raw values of x,y
      pressed = Touch_getPositionRaw(&touchX, &touchY);

      if(pressed == TRUE){
      // Set the parameters to send to emwin.
      touchState.Pressed = TRUE;

      // Set the values;
      touchState.x = touchX;
      touchState.y = touchY;
      // Store the pressed state for emwin to process.
      prevState = pressed;
      else if(prevState != pressed){
      prevState = pressed;
      touchState.Pressed = FALSE;
      // Store the unpressed state for emwin to process.

      I have used 9 point calibration and used calcoefficients as below
      int touchRefValX[TOUCH_MAX_CALIBRATION_POINTS] = {40,400,760,40,400,760,40,400,760};
      int touchRefValY[TOUCH_MAX_CALIBRATION_POINTS] = {24,24,24,240,240,240,456,456,456};

      int touchSampleValX[TOUCH_MAX_CALIBRATION_POINTS] = {2573,1963,1550,2542,1976,1547,2547,1968,1544};
      int touchSampleValY[TOUCH_MAX_CALIBRATION_POINTS] = {2319,2300,2300,1982,1971,1968,1787,1780,1776};

      My init code for touch calibration is as below

      // Set the calibration coefficients.
      GUI_TOUCH_CalcCoefficients(9, &touchRefValX[0], &touchRefValY[0], &touchSampleValX[0], &touchSampleValY[0], 800, 480);

      // Enable use of above calibration coefficients.

      My screen is 800x480 pixels and my ADC range is just 1000 counts from 1500-2500 on x and y direction.
      Will this be any issue?