refactor(doorbell): unify 2x2 grid touch logic and add progress bar
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user