feat(touch): add press/release detection with touch-down tracking
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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