feat(touch): add press/release detection with touch-down tracking
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ private:
|
||||
void drawDashboard(const ScreenState& state);
|
||||
|
||||
// Touch handling
|
||||
TouchEvent _lastTouch = { false, 0, 0 };
|
||||
TouchEvent _lastTouch = { false, false, 0, 0, -1, -1 };
|
||||
unsigned long _pressStartMs = 0;
|
||||
bool _isHolding = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user