PaulStoffregen / XPT2046_Touchscreen

Touchscreen Arduino Library for XPT2046 Touch Controller Chip
240 stars 84 forks source link

update method inaccurate with screen rotations #28

Open mfarabee opened 4 years ago

mfarabee commented 4 years ago

Description

I am unable to use the update method due to the way the calculations are made (gives wrong values). It looks to me that the in the switch statement, it is predetermined (hard coded) what the raw touch max value is (in this case 4095). The problem I am having is that my display does not go to 4095. Mine is limited to 3900. Also I find that my X and Y dimensions are slightly different (3900 and 3915). If I use your rotation code, I find that my touch point is off, if I rotate my screen. Also my minimum values do not go to zero, mine is showing 260 and 320 respectively.

if (z >= Z_THRESHOLD) { msraw = now; // good read completed, set wait switch (rotation) { case 0: xraw = 4095 - y; yraw = x; break; case 1: xraw = x; yraw = y; break; case 2: xraw = y; yraw = 4095 - x; break; default: // 3 xraw = 4095 - x; yraw = 4095 - y; } }

Steps To Reproduce Problem

The only way to reproduce this problem is to locate screens with different touch return values.

Hardware & Software

Board: ESP32 - NodeMcu Shields / modules used: None Arduino IDE version: 1.8.9 Any other software or hardware: 2.8 TFT 240x320 V1.2 (red pcb with full size SD card).

SOLUTION:

I would like to see some way to set/override the MINIMUM and MAXIMUM raw values for both X and Y dimensions (maybe relative to rotation 0). Then the calculations in the update method could use these numbers for the rotation calculation instead of the hard coded values.