feat(touch): add press/release detection with touch-down tracking

This commit is contained in:
2026-02-18 13:08:56 -08:00
parent 1961631e2c
commit 9f7a383b38
7 changed files with 166 additions and 41 deletions

View File

@@ -68,16 +68,36 @@ TouchEvent DisplayDriverGFX::readTouch() {
int32_t x, y;
bool pressed = _gfx->getTouch(&x, &y);
// Only report NEW touches (debounce - ignore held touches)
evt.pressed = pressed && !_lastTouch.pressed;
// Detect transitions (press/release)
if(pressed && !_lastTouch.pressed) {
// Press transition: finger just touched down
evt.pressed = true;
evt.downX = static_cast<int>(x);
evt.downY = static_cast<int>(y);
_lastTouch.downX = evt.downX;
_lastTouch.downY = evt.downY;
} else if(!pressed && _lastTouch.pressed) {
// Release transition: finger just lifted
evt.released = true;
evt.downX = _lastTouch.downX;
evt.downY = _lastTouch.downY;
}
// Current position if still touched
if(pressed) {
evt.x = static_cast<int>(x);
evt.y = static_cast<int>(y);
evt.downX = _lastTouch.downX;
evt.downY = _lastTouch.downY;
_pressStartMs = millis();
}
// Track previous state
_lastTouch.pressed = pressed;
if(pressed) {
_lastTouch.x = evt.x;
_lastTouch.y = evt.y;
}
return evt;
}