adafruit / Adafruit_LvGL_Glue

“Glue” library between LittlevGL and Adafruit GFX (SPITFT)
Other
35 stars 14 forks source link

STMPE610 needs debouncing #4

Open mcantureinhard opened 4 years ago

mcantureinhard commented 4 years ago

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 commented 4 years ago

nice, can you submit a PR for the fix?

mcantureinhard commented 4 years ago

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 commented 4 years ago

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

mcantureinhard commented 4 years ago

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

JRTax commented 2 years ago

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 commented 1 year ago

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
}