feat(Display): Improve touch handling and visual feedback

This commit is contained in:
2026-02-20 04:10:39 -08:00
parent 688b1905e5
commit 72636f9ecf
10 changed files with 43 additions and 18 deletions

View File

@@ -197,9 +197,12 @@ void DisplayDriverTFT::drawAlert(const ScreenState& st) {
uint32_t elapsed = millis() - st.alertStartMs;
bool brightPhase = (elapsed / 2000) % 2 == 0;
// Only redraw when phase changes (timer-based, not every frame)
if(brightPhase != _lastAlertPhase) {
// Redraw when phase changes OR when touch was released (to clear fill)
bool needsRedraw = (brightPhase != _lastAlertPhase) || _alertNeedsRedraw;
if(needsRedraw) {
_lastAlertPhase = brightPhase;
_alertNeedsRedraw = false; // clear the flag
uint16_t bg = brightPhase ? TFT_RED : _tft.color565(180, 0, 0);
_tft.fillScreen(bg);
@@ -218,7 +221,7 @@ void DisplayDriverTFT::drawAlert(const ScreenState& st) {
_tft.print("Hold to silence...");
}
// Progressive fill hint - only redraw when touch state changes
// Progressive fill hint - while touch is held
if(_alertTouchDown) {
uint32_t touchElapsed = millis() - _alertTouchStartMs;
float progress = (float)touchElapsed / (float)ALERT_FILL_DURATION_MS;
@@ -374,6 +377,12 @@ TouchEvent DisplayDriverTFT::readTouch() {
uint16_t tx, ty;
uint8_t touched = _tft.getTouch(&tx, &ty, 100);
// Debug: log touch state changes
if(touched != _touchWasPressed) {
Serial.printf("[TOUCH] raw touched=%d wasPressed=%d (x=%d,y=%d)\n", touched,
_touchWasPressed, tx, ty);
}
// Detect transitions (press/release)
if(touched && !_touchWasPressed) {
// Press transition: finger just touched down
@@ -406,6 +415,7 @@ TouchEvent DisplayDriverTFT::readTouch() {
_alertTouchStartMs = millis();
} else if(evt.released) {
_alertTouchDown = false;
_alertNeedsRedraw = true; // force redraw to clear fill
}
return evt;
@@ -418,11 +428,10 @@ void DisplayDriverTFT::transformTouch(int* x, int* y) {
*y = temp;
}
HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
HoldState DisplayDriverTFT::updateHold(const TouchEvent& evt, unsigned long holdMs) {
HoldState h;
TouchEvent t = readTouch();
if(t.pressed) {
if(evt.pressed) {
if(!_holdActive) {
_holdActive = true;
_holdStartMs = millis();

View File

@@ -11,7 +11,7 @@ public:
void setBacklight(bool on) override;
void render(const ScreenState& state) override;
TouchEvent readTouch() override;
HoldState updateHold(unsigned long holdMs) override;
HoldState updateHold(const TouchEvent& evt, unsigned long holdMs) override;
int width() override {
// Use TFT_eSPI's dimensions after rotation - it's more reliable
return _tft.width();
@@ -43,6 +43,7 @@ private:
// Touch hint for alert - progressive fill from bottom
bool _alertTouchDown = false;
bool _alertNeedsRedraw = false; // force redraw after touch release
uint32_t _alertTouchStartMs = 0;
bool _lastAlertPhase = false; // tracks bright/dark phase for 2-color alert
static constexpr uint32_t ALERT_FILL_DURATION_MS = 3000;

View File

@@ -298,11 +298,10 @@ int DisplayDriverTFT::dashboardTouch(int x, int y) {
return row * 2 + col; // 0, 1, 2, or 3
}
HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
HoldState DisplayDriverTFT::updateHold(const TouchEvent& evt, unsigned long holdMs) {
HoldState h;
TouchEvent t = readTouch();
if(t.pressed) {
if(evt.pressed) {
if(!_holdActive) {
_holdActive = true;
_holdStartMs = millis();

View File

@@ -12,7 +12,7 @@ public:
void render(const ScreenState& state) override;
TouchEvent readTouch() override;
int dashboardTouch(int x, int y);
HoldState updateHold(unsigned long holdMs) override;
HoldState updateHold(const TouchEvent& evt, unsigned long holdMs) override;
int width() override { return DISPLAY_WIDTH; }
int height() override { return DISPLAY_HEIGHT; }

View File

@@ -261,10 +261,10 @@ int DisplayDriverGFX::dashboardTouch(int x, int y) {
return row * cols + col;
}
HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
HoldState DisplayDriverGFX::updateHold(const TouchEvent& evt, unsigned long holdMs) {
HoldState state;
if(!_lastTouch.pressed) {
if(!evt.pressed) {
_isHolding = false;
return state;
}

View File

@@ -13,7 +13,7 @@ public:
void render(const ScreenState& state) override;
TouchEvent readTouch() override;
HoldState updateHold(unsigned long holdMs) override;
HoldState updateHold(const TouchEvent& evt, unsigned long holdMs) override;
void drawDebugTouch(int x, int y) override;
int width() override;