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

STMPE610 needs debouncing #4

Open
mcantureinhard opened this issue Sep 14, 2020 · 6 comments
Open

STMPE610 needs debouncing #4

mcantureinhard opened this issue Sep 14, 2020 · 6 comments

Comments

@mcantureinhard
Copy link

I got the esp32 feather and tft featherwing last weekend. As I was working with this library I noticed that the STMPE610 is bouncing. When pressing continuously there is always an intermediate LV_INDEV_STATE_REL returned. This results in issues with the event_handler (i.e. event LV_EVENT_RELEASED is triggered intermittently).
The fix that worked for me was to add debouncing the same way as it is implemented for the other chip, although with a lower threshold.
if ((fifo = touch->bufferSize())) { // 1 or more points await release_count = 0; ... } else { // FIFO empty release_count += (release_count < 255); if (release_count >= 2) { data->state = LV_INDEV_STATE_REL; // Is REALLY RELEASED } else { data->state = LV_INDEV_STATE_PR; // Is STILL PRESSED } }

@ladyada
Copy link
Member

ladyada commented Sep 14, 2020

nice, can you submit a PR for the fix?

@mcantureinhard
Copy link
Author

Sure, I tried to create a branch and submit the PR before creating this issue, but I seem to need write access. Could I get it, so I can push my branch and create the PR? Thanks!

@ladyada
Copy link
Member

ladyada commented Sep 15, 2020

hi you would fork to your account, then submit a PR from your branch/fork

@mcantureinhard
Copy link
Author

I see, thanks for letting me know. I haven't contributed to any open source project before. Will send the PR after dinner :)

@JRTax
Copy link

JRTax commented Apr 20, 2022

Is there any update on adding an debounce feature? I'm having this issue currently and I still didn't find an way to get it to work

@JYMellen
Copy link

I been having the same issue, although I have a different solution, I added a while loop inside the "if ((fifo = touch->bufferSize())) {" and then had the system delay(25); at the bottom of the loop before checking for more data. If there was more data then it ran through that too. Seems like just an extension of what was already done for the nRF. The whole loop is below... not sure which fix is more functional, just hoping one of them gets into the code soon:

if ((fifo = touch->bufferSize())) { // 1 or more points await
    while ((fifo = touch->bufferSize())) { // loop through with a wait at the end to make sure there are no more coming - Added by JYM 3-17-23
        data->state = LV_INDEV_STATE_PR;  // Is PRESSED
        TS_Point p = touch->getPoint();
        // Serial.printf("%d %d %d\r\n", p.x, p.y, p.z);
        // On big TFT FeatherWing, raw X axis is flipped??
        if ((glue->display->width() == 480) || (glue->display->height() == 480)) {
            p.x = (TS_MINX + TS_MAXX) - p.x;
        }
        switch (glue->display->getRotation()) {
            case 0:
                last_x = map(p.x, TS_MAXX, TS_MINX, 0, disp->width() - 1);
                last_y = map(p.y, TS_MINY, TS_MAXY, 0, disp->height() - 1);
                break;
            case 1:
                last_x = map(p.y, TS_MINY, TS_MAXY, 0, disp->width() - 1);
                last_y = map(p.x, TS_MINX, TS_MAXX, 0, disp->height() - 1);
                break;
            case 2:
                last_x = map(p.x, TS_MINX, TS_MAXX, 0, disp->width() - 1);
                last_y = map(p.y, TS_MAXY, TS_MINY, 0, disp->height() - 1);
                break;
            case 3:
                last_x = map(p.y, TS_MAXY, TS_MINY, 0, disp->width() - 1);
                last_y = map(p.x, TS_MAXX, TS_MINX, 0, disp->height() - 1);
                break;
        }
        more = (fifo > 1); // true if more in FIFO, false if last point

#if defined(NRF52_SERIES)
// Not sure what's up here, but nRF doesn't seem to always poll
// the FIFO size correctly, causing false release events. If it
// looks like we've read the last point from the FIFO, pause
// briefly to allow any more FIFO events to pile up. This
// doesn't seem to be necessary on SAMD or ESP32. ???
if (!more) {
delay(50);
}
#endif
delay(25); // Added by JYM 3-17-23
} // Added by JYM 3-17-23
} else { // FIFO empty
data->state = LV_INDEV_STATE_REL; // Is RELEASED
}

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

4 participants