feat(display): draw hint animation at touch position instead of center
This commit is contained in:
@@ -136,6 +136,7 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
if (!_holdActive) {
|
||||
_holdActive = true;
|
||||
_holdStartMs = millis();
|
||||
h.started = true;
|
||||
}
|
||||
uint32_t held = millis() - _holdStartMs;
|
||||
h.active = true;
|
||||
@@ -147,8 +148,8 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
_tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
|
||||
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
|
||||
} else {
|
||||
if (_ // Clear theholdActive) {
|
||||
progress bar when released
|
||||
if (_holdActive) {
|
||||
// Clear the progress bar when released
|
||||
_tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY);
|
||||
}
|
||||
_holdActive = false;
|
||||
@@ -156,9 +157,10 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||
return h;
|
||||
}
|
||||
|
||||
void DisplayDriverTFT::updateHint() {
|
||||
void DisplayDriverTFT::updateHint(int x, int y) {
|
||||
float t = (millis() % 2000) / 2000.0f;
|
||||
uint8_t v = (uint8_t)(30.0f + 30.0f * sinf(t * 2 * PI));
|
||||
uint16_t col = _tft.color565(v, v, v);
|
||||
_tft.drawRect(DISPLAY_WIDTH / 2 - 40, DISPLAY_HEIGHT / 2 + 20, 80, 40, col);
|
||||
// Draw at touch position instead of center
|
||||
_tft.drawRect(x - 40, y - 20, 80, 40, col);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
TouchEvent readTouch() override;
|
||||
int dashboardTouch(int x, int y) override;
|
||||
HoldState updateHold(unsigned long holdMs) override;
|
||||
void updateHint() override;
|
||||
void updateHint(int x, int y) override;
|
||||
int width() override { return DISPLAY_WIDTH; }
|
||||
int height() override { return DISPLAY_HEIGHT; }
|
||||
|
||||
|
||||
@@ -28,18 +28,32 @@ void loop() {
|
||||
|
||||
// ── Touch handling ──
|
||||
const ScreenState& st = logic.getScreenState();
|
||||
static int holdStartX = -1;
|
||||
static int holdStartY = -1;
|
||||
|
||||
if (st.deviceState == DeviceState::ALERTING) {
|
||||
HoldState h = display.updateHold(HOLD_TO_SILENCE_MS);
|
||||
if (h.completed) {
|
||||
logic.silenceAlert();
|
||||
holdStartX = -1;
|
||||
holdStartY = -1;
|
||||
}
|
||||
if (!h.active) {
|
||||
display.updateHint();
|
||||
if (h.started) {
|
||||
TouchEvent t = display.readTouch();
|
||||
holdStartX = t.x;
|
||||
holdStartY = t.y;
|
||||
}
|
||||
if (!h.active && holdStartX >= 0) {
|
||||
display.updateHint(holdStartX, holdStartY);
|
||||
}
|
||||
} else {
|
||||
holdStartX = -1;
|
||||
holdStartY = -1;
|
||||
}
|
||||
|
||||
if (st.screen == ScreenID::DASHBOARD) {
|
||||
TouchEvent evt = display.readTouch();
|
||||
if (evt.pressed && st.screen == ScreenID::DASHBOARD) {
|
||||
if (evt.pressed) {
|
||||
int tile = display.dashboardTouch(evt.x, evt.y);
|
||||
if (tile >= 0) Serial.printf("[DASH] Tile %d tapped\n", tile);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user