feat(Display): Improve touch handling and visual feedback
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user