Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch reading fails after a number of tries #34

Open
AurumVR opened this issue Nov 10, 2020 · 1 comment
Open

Touch reading fails after a number of tries #34

AurumVR opened this issue Nov 10, 2020 · 1 comment

Comments

@AurumVR
Copy link

AurumVR commented Nov 10, 2020

I am using a 3.95" TFT board which has a XPT2046 touch controller, and this library to work with it. If I try to use it with an interrupt like

XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN);

after enough poking at the screen at a random time it breaks and keeps repeating the last successfully read values. More about this below.

Also: using the touched() function in the main loop is bad practice as it does a full reading making the SPI bus glow red with all the unnecessary readings to determine from the value of Z if there was a touch whereas we have an interrupt for that (if configured to use).

Which don't work by the way.

After enough poking at my screen at a random occassion Z reading falls below the threshold and isrWake is set false at

if (z < Z_THRESHOLD_INT) { // if ( !touched ) {
if (255 != tirqPin)
{
isrWake = false;
Serial.println("isrWake -> FALSE");
}
}

and never recovers, because

{
XPT2046_Touchscreen *o = isrPinptr;
o->isrWake = true;
}

where it would be restored, never actually runs, effectively breaking the code at

if (!isrWake) return;

in the data update() function.

My method is to use the lib without an interrupt:

XPT2046_Touchscreen ts(CS_PIN, 255);

instead make my own ISR detecting the TS-IRQ low level and do a reading by then. Yet it's a workaround, not a solution.

Forgive me if I wasn't clear or overlooked something, I'm not a programmer. Thanks :)

@spiro-trikaliotis
Copy link

Hello,

I can confirm this behaviour in my setup (ESP8266 with XPT2046 touchscreen). It happens if you poke very fast on the screen.

The attached patch (in two variants, with and without debugging output over serial) fixes the problem for me.

Note that I moved the setting of isrWake to immediately after it has been used, so I close the time window for any races between ISR and the setting to false.

Can you confirm that it fixes the issue for you?

XPT2046_Touchscreen.cpp.with_output.diff.gz
XPT2046_Touchscreen.cpp.without_output.diff.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants