refactor(doorbell): unify 2x2 grid touch logic and add progress bar

This commit is contained in:
2026-02-16 22:11:40 -08:00
parent b47993b29a
commit 257bc9aa82
3 changed files with 29 additions and 15 deletions

View File

@@ -110,31 +110,35 @@ TouchEvent DisplayDriverGFX::readTouch() {
}
int DisplayDriverGFX::dashboardTouch(int x, int y) {
// Simple 2x2 grid: 4 tiles
int col = (x < DISPLAY_WIDTH / 2) ? 0 : 1;
int row = (y < DISPLAY_HEIGHT / 2) ? 0 : 1;
return row * 2 + col;
// Unified 2x2 grid
int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1
int row = (y * 2) / DISPLAY_HEIGHT; // 0 or 1
return row * 2 + col; // 0, 1, 2, or 3
}
HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
TouchEvent ev = readTouch();
if (ev.pressed) {
if (!_lastTouched) {
_holdStart = millis();
_lastTouched = true;
}
unsigned long elapsed = millis() - _holdStart;
float progress = constrain((float)elapsed / holdMs, 0.0f, 1.0f);
if (elapsed >= holdMs) {
return {false, true};
_lastTouched = false;
_holdStart = 0;
return {false, true, 1.0f};
}
return {true, false};
return {true, false, progress};
} else {
_lastTouched = false;
_holdStart = 0;
return {false, false};
return {false, false, 0.0f};
}
}
void DisplayDriverGFX::updateHint() {
// placeholder for idle hint animation
}
@@ -240,7 +244,8 @@ void DisplayDriverGFX::drawAlert(const ScreenState& state) {
_gfx->println("DOORBELL!");
_gfx->setTextSize(3);
_gfx->setCursor(100, 280);
_gfx->println(state.alertBody ? state.alertBody : "Someone is at the door");
const char* body = state.alertBody.c_str();
_gfx->println(state.alertBody.length() ? body : "Someone is at the door");
}
void DisplayDriverGFX::drawOff() {

View File

@@ -31,7 +31,7 @@
#define LCD_B4 10
// ── I2C bus (shared: CH422G + GT911) ──
#define I2C_MASTER_NUM 0
#define I2C_MASTER_NUM ((i2c_port_t)0)
#define I2C_MASTER_SDA 8
#define I2C_MASTER_SCL 9