feat(Display): Improve touch handling and visual feedback
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#define POLL_INTERVAL_MS 15000
|
||||
#define HEARTBEAT_INTERVAL_MS 300000
|
||||
#define BOOT_GRACE_MS 5000
|
||||
#define HOLD_TO_SILENCE_MS 3000
|
||||
#define HOLD_TO_SILENCE_MS 2000
|
||||
#define ALERT_TIMEOUT_MS 120000
|
||||
#define SILENCE_DISPLAY_MS 10000
|
||||
#define INACTIVITY_TIMEOUT_MS 30000
|
||||
|
||||
@@ -60,6 +60,14 @@ private:
|
||||
/// Calculate optimal grid dimensions based on display and tile constraints
|
||||
static void calculateGrid(
|
||||
int tileCount, int displayW, int contentH, int* outCols, int* outRows) {
|
||||
// Use 2x2 grid for 4 tiles regardless of aspect ratio
|
||||
// This provides better visual balance than a single row
|
||||
if(tileCount == 4) {
|
||||
*outCols = 2;
|
||||
*outRows = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate aspect ratio to determine preferred layout
|
||||
float aspectRatio = (float)displayW / contentH;
|
||||
|
||||
@@ -138,7 +146,9 @@ public:
|
||||
|
||||
TouchEvent readTouch() { return _drv ? _drv->readTouch() : TouchEvent {}; }
|
||||
|
||||
HoldState updateHold(unsigned long ms) { return _drv ? _drv->updateHold(ms) : HoldState {}; }
|
||||
HoldState updateHold(const TouchEvent& evt, unsigned long ms) {
|
||||
return _drv ? _drv->updateHold(evt, ms) : HoldState {};
|
||||
}
|
||||
|
||||
void drawDebugTouch(int x, int y) {
|
||||
if(_drv)
|
||||
|
||||
@@ -338,6 +338,7 @@ int DoorbellLogic::handleTouch(const TouchEvent& evt) {
|
||||
// Check hold completion FIRST - before any release handling
|
||||
// This ensures hold-to-silence works on ALERT screen
|
||||
if(evt.released && _state.deviceState == DeviceState::ALERTING) {
|
||||
Serial.printf("[TOUCH] checking hold: deviceState=ALERTING\n");
|
||||
if(updateHold(evt)) {
|
||||
return (int)TileAction::SILENCE;
|
||||
}
|
||||
@@ -345,6 +346,8 @@ int DoorbellLogic::handleTouch(const TouchEvent& evt) {
|
||||
|
||||
// Handle press - show visual feedback
|
||||
if(evt.pressed) {
|
||||
Serial.printf("[TOUCH] pressed screen=%d deviceState=%d\n", (int)_state.screen,
|
||||
(int)_state.deviceState);
|
||||
// Reset inactivity timer on any touch
|
||||
_lastActivityMs = millis();
|
||||
|
||||
@@ -377,6 +380,9 @@ int DoorbellLogic::handleTouch(const TouchEvent& evt) {
|
||||
|
||||
// Handle release - fire action if same tile
|
||||
if(evt.released) {
|
||||
Serial.printf("[TOUCH] released screen=%d deviceState=%d\n", (int)_state.screen,
|
||||
(int)_state.deviceState);
|
||||
|
||||
if(_state.screen == ScreenID::DASHBOARD) {
|
||||
// Only fire action if finger stayed on same tile
|
||||
if(evt.downX >= 0 && _display->isSameTile(evt.downX, evt.downY, evt.x, evt.y)) {
|
||||
@@ -426,7 +432,7 @@ bool DoorbellLogic::updateHold(const TouchEvent& evt) {
|
||||
static int holdStartX = -1;
|
||||
static int holdStartY = -1;
|
||||
|
||||
HoldState h = _display->updateHold(HOLD_TO_SILENCE_MS);
|
||||
HoldState h = _display->updateHold(evt, HOLD_TO_SILENCE_MS);
|
||||
|
||||
if(h.completed) {
|
||||
silenceAlert();
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
|
||||
// ── Touch ──
|
||||
virtual TouchEvent readTouch() = 0;
|
||||
virtual HoldState updateHold(unsigned long holdMs) = 0;
|
||||
virtual HoldState updateHold(const TouchEvent& evt, unsigned long holdMs) = 0;
|
||||
virtual void drawDebugTouch(int x, int y) { /* default: no-op */ }
|
||||
virtual int width() = 0;
|
||||
virtual int height() = 0;
|
||||
|
||||
Reference in New Issue
Block a user