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

@@ -173,11 +173,32 @@ TouchEvent DisplayDriverTFT::readTouch() {
TouchEvent evt;
uint16_t tx, ty;
uint8_t touched = _tft.getTouch(&tx, &ty, 100);
if(touched) {
// Detect transitions (press/release)
if(touched && !_touchWasPressed) {
// Press transition: finger just touched down
evt.pressed = true;
_touchDownX = tx;
_touchDownY = ty;
evt.downX = _touchDownX;
evt.downY = _touchDownY;
} else if(!touched && _touchWasPressed) {
// Release transition: finger just lifted
evt.released = true;
evt.downX = _touchDownX;
evt.downY = _touchDownY;
}
// Current position if still touched
if(touched) {
evt.x = tx;
evt.y = ty;
evt.downX = _touchDownX;
evt.downY = _touchDownY;
}
// Track previous state for next call
_touchWasPressed = touched;
return evt;
}

View File

@@ -32,4 +32,9 @@ private:
ScreenID _lastScreen = ScreenID::BOOT;
BootStage _lastBootStage = BootStage::SPLASH;
bool _needsRedraw = true;
// Touch tracking for press/release detection
bool _touchWasPressed = false;
int _touchDownX = -1;
int _touchDownY = -1;
};