refactor(doorbell): unify 2x2 grid touch logic and add progress bar
This commit is contained in:
@@ -116,11 +116,16 @@ TouchEvent DisplayDriverTFT::readTouch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DisplayDriverTFT::dashboardTouch(int x, int y) {
|
int DisplayDriverTFT::dashboardTouch(int x, int y) {
|
||||||
// 2-column, 4-row
|
// Unified 2x2 grid (matching GFX)
|
||||||
int col = x / (DISPLAY_WIDTH / 2);
|
int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1
|
||||||
int row = (y - 30) / 40;
|
int row = (y * 2) / DISPLAY_HEIGHT; // 0 or 1
|
||||||
if (row < 0 || row > 3) return -1;
|
|
||||||
return row * 2 + col;
|
// Adjust for header offset (y starts at 30 in drawDashboard)
|
||||||
|
if (y < 30) return -1;
|
||||||
|
row = ((y - 30) * 2) / (DISPLAY_HEIGHT - 30);
|
||||||
|
if (row < 0 || row > 1) return -1;
|
||||||
|
|
||||||
|
return row * 2 + col; // 0, 1, 2, or 3
|
||||||
}
|
}
|
||||||
|
|
||||||
HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
||||||
@@ -142,6 +147,10 @@ HoldState DisplayDriverTFT::updateHold(unsigned long holdMs) {
|
|||||||
_tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
|
_tft.fillRect(0, DISPLAY_HEIGHT - 8, barW, 8, TFT_WHITE);
|
||||||
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
|
_tft.fillRect(barW, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH - barW, 8, TFT_DARKGREY);
|
||||||
} else {
|
} else {
|
||||||
|
if (_ // Clear theholdActive) {
|
||||||
|
progress bar when released
|
||||||
|
_tft.fillRect(0, DISPLAY_HEIGHT - 8, DISPLAY_WIDTH, 8, TFT_DARKGREY);
|
||||||
|
}
|
||||||
_holdActive = false;
|
_holdActive = false;
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
|
|||||||
@@ -110,31 +110,35 @@ TouchEvent DisplayDriverGFX::readTouch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int DisplayDriverGFX::dashboardTouch(int x, int y) {
|
int DisplayDriverGFX::dashboardTouch(int x, int y) {
|
||||||
// Simple 2x2 grid: 4 tiles
|
// Unified 2x2 grid
|
||||||
int col = (x < DISPLAY_WIDTH / 2) ? 0 : 1;
|
int col = (x * 2) / DISPLAY_WIDTH; // 0 or 1
|
||||||
int row = (y < DISPLAY_HEIGHT / 2) ? 0 : 1;
|
int row = (y * 2) / DISPLAY_HEIGHT; // 0 or 1
|
||||||
return row * 2 + col;
|
return row * 2 + col; // 0, 1, 2, or 3
|
||||||
}
|
}
|
||||||
|
|
||||||
HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
|
HoldState DisplayDriverGFX::updateHold(unsigned long holdMs) {
|
||||||
TouchEvent ev = readTouch();
|
TouchEvent ev = readTouch();
|
||||||
|
|
||||||
if (ev.pressed) {
|
if (ev.pressed) {
|
||||||
if (!_lastTouched) {
|
if (!_lastTouched) {
|
||||||
_holdStart = millis();
|
_holdStart = millis();
|
||||||
_lastTouched = true;
|
_lastTouched = true;
|
||||||
}
|
}
|
||||||
unsigned long elapsed = millis() - _holdStart;
|
unsigned long elapsed = millis() - _holdStart;
|
||||||
|
float progress = constrain((float)elapsed / holdMs, 0.0f, 1.0f);
|
||||||
|
|
||||||
if (elapsed >= holdMs) {
|
if (elapsed >= holdMs) {
|
||||||
return {false, true};
|
_lastTouched = false;
|
||||||
|
_holdStart = 0;
|
||||||
|
return {false, true, 1.0f};
|
||||||
}
|
}
|
||||||
return {true, false};
|
return {true, false, progress};
|
||||||
} else {
|
} else {
|
||||||
_lastTouched = false;
|
_lastTouched = false;
|
||||||
_holdStart = 0;
|
_holdStart = 0;
|
||||||
return {false, false};
|
return {false, false, 0.0f};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayDriverGFX::updateHint() {
|
void DisplayDriverGFX::updateHint() {
|
||||||
// placeholder for idle hint animation
|
// placeholder for idle hint animation
|
||||||
}
|
}
|
||||||
@@ -240,7 +244,8 @@ void DisplayDriverGFX::drawAlert(const ScreenState& state) {
|
|||||||
_gfx->println("DOORBELL!");
|
_gfx->println("DOORBELL!");
|
||||||
_gfx->setTextSize(3);
|
_gfx->setTextSize(3);
|
||||||
_gfx->setCursor(100, 280);
|
_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() {
|
void DisplayDriverGFX::drawOff() {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#define LCD_B4 10
|
#define LCD_B4 10
|
||||||
|
|
||||||
// ── I2C bus (shared: CH422G + GT911) ──
|
// ── 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_SDA 8
|
||||||
#define I2C_MASTER_SCL 9
|
#define I2C_MASTER_SCL 9
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user