This commit is contained in:
2026-02-16 03:36:04 -08:00
parent 893c50dbc0
commit 9e285e07a2
4 changed files with 171 additions and 49 deletions

View File

@@ -38,7 +38,7 @@ int DisplayManager::dashboardTouch(uint16_t x, uint16_t y) {
}
// =====================================================================
// Hold detection
// Hold detection — two-phase: charge up, then release to confirm
// =====================================================================
HoldState DisplayManager::updateHold(unsigned long requiredMs) {
HoldState h;
@@ -49,25 +49,48 @@ HoldState DisplayManager::updateHold(unsigned long requiredMs) {
if (touching) {
if (!_holdActive) {
_holdActive = true;
_holdStartMs = millis();
// New press begins
_holdActive = true;
_holdCharged = false;
_holdStartMs = millis();
_holdChargeMs = 0;
_holdX = tx;
_holdY = ty;
}
h.active = true;
h.x = _holdX;
h.y = _holdY;
h.holdMs = millis() - _holdStartMs;
_holdProgress = min((float)h.holdMs / (float)requiredMs, 1.0f);
h.progress = min((float)h.holdMs / (float)requiredMs, 1.0f);
_holdProgress = h.progress;
if (h.holdMs >= requiredMs) {
h.completed = true;
_holdActive = false;
_holdProgress = 0.0f;
// Charged! But don't fire yet — wait for release
_holdCharged = true;
if (_holdChargeMs == 0) _holdChargeMs = millis();
h.charged = true;
}
} else {
// Finger lifted
if (_holdActive) {
if (_holdCharged) {
// Released after full charge → FIRE
h.completed = true;
h.x = _holdX;
h.y = _holdY;
Serial.println("[HOLD] Charged + released → completed!");
} else {
// Released too early → cancelled
h.cancelled = true;
Serial.println("[HOLD] Released early → cancelled");
}
}
_holdActive = false;
_holdCharged = false;
_holdProgress = 0.0f;
_holdChargeMs = 0;
}
return h;
@@ -105,8 +128,9 @@ void DisplayManager::render(const ScreenState& state) {
drawAlertScreen(state);
_lastBlink = state.blinkPhase;
}
if (_holdProgress > 0.0f) {
drawSilenceProgress(_holdProgress);
// Overlay progress bar when holding
if (_holdProgress > 0.0f || _holdCharged) {
drawSilenceProgress(_holdProgress, _holdCharged);
}
break;
case ScreenID::STATUS:
@@ -145,30 +169,78 @@ void DisplayManager::drawDashboard(const ScreenState& s) {
}
// =====================================================================
// Silence progress bar
// Silence progress bar — with jitter/flash when charged
// =====================================================================
void DisplayManager::drawSilenceProgress(float progress) {
void DisplayManager::drawSilenceProgress(float progress, bool charged) {
int barX = 10;
int barY = SCREEN_HEIGHT - 35;
int barY = SCREEN_HEIGHT - 40;
int barW = SCREEN_WIDTH - 20;
int barH = 25;
int fillW = (int)(barW * progress);
int barH = 30;
_tft.fillRect(barX, barY, barW, barH, COL_BLACK);
if (fillW > 0) {
_tft.fillRect(barX, barY, fillW, barH, COL_GREEN);
}
_tft.drawRect(barX, barY, barW, barH, COL_WHITE);
if (charged) {
// ---- CHARGED: jitter + flash effect ----
unsigned long elapsed = millis() - _holdChargeMs;
int cycle = (elapsed / 60) % 6; // fast 60ms cycle, 6 frames
// Jitter: offset bar position by ±2-3px
int jitterX = 0;
int jitterY = 0;
switch (cycle) {
case 0: jitterX = -3; jitterY = 1; break;
case 1: jitterX = 2; jitterY = -2; break;
case 2: jitterX = -1; jitterY = 2; break;
case 3: jitterX = 3; jitterY = -1; break;
case 4: jitterX = -2; jitterY = -1; break;
case 5: jitterX = 1; jitterY = 2; break;
}
// Clear slightly larger area to avoid jitter artifacts
_tft.fillRect(barX - 4, barY - 4, barW + 8, barH + 8, COL_BLACK);
// Flash between green and white
uint16_t flashCol = (cycle % 2 == 0) ? COL_GREEN : COL_WHITE;
uint16_t textCol = (cycle % 2 == 0) ? COL_BLACK : COL_BLACK;
_tft.fillRoundRect(barX + jitterX, barY + jitterY, barW, barH, 6, flashCol);
_tft.drawRoundRect(barX + jitterX, barY + jitterY, barW, barH, 6, COL_YELLOW);
// ">> RELEASE! <<" text
_tft.setTextFont(1);
_tft.setTextSize(2);
_tft.setTextDatum(MC_DATUM);
_tft.setTextColor(textCol, flashCol);
const char* labels[] = { ">> RELEASE! <<", "<< RELEASE! >>",
">> RELEASE! <<", "<< RELEASE! >>" };
_tft.drawString(labels[cycle % 4],
SCREEN_WIDTH / 2 + jitterX,
barY + barH / 2 + jitterY);
_tft.setTextFont(1);
_tft.setTextSize(2);
_tft.setTextDatum(MC_DATUM);
if (progress >= 1.0f) {
_tft.setTextColor(COL_BLACK);
_tft.drawString("SILENCED", SCREEN_WIDTH / 2, barY + barH / 2);
} else {
_tft.setTextColor(COL_WHITE);
_tft.drawString("HOLD TO SILENCE", SCREEN_WIDTH / 2, barY + barH / 2);
// ---- FILLING: normal progress bar ----
int fillW = (int)(barW * progress);
_tft.fillRect(barX, barY, barW, barH, COL_BLACK);
if (fillW > 0) {
// Gradient: dark green (left) → bright green (right)
for (int i = 0; i < fillW; i++) {
uint8_t g = map(i, 0, barW, 20, 63); // 6-bit green channel (RGB565)
uint16_t col = (g << 5); // pure green in RGB565
_tft.drawFastVLine(barX + i, barY, barH, col);
}
// Redraw rounded border on top since the slices are square
_tft.drawRoundRect(barX, barY, fillW, barH, 6, COL_WHITE);
}
_tft.drawRoundRect(barX, barY, barW, barH, 6, COL_WHITE);
// Percentage indicator inside bar
_tft.setTextFont(1);
_tft.setTextSize(2);
_tft.setTextDatum(MC_DATUM);
_tft.setTextColor(COL_WHITE, COL_BLACK);
_tft.drawString("HOLD TO SILENCE",
SCREEN_WIDTH / 2, barY + barH / 2);
}
}
@@ -262,8 +334,8 @@ void DisplayManager::drawAlertScreen(const ScreenState& s) {
drawCentered(s.alertMessage, (SCREEN_HEIGHT - 8 * sz) / 2, sz, fg);
}
// Only show hint text if not currently holding
if (_holdProgress == 0.0f) {
// Show hint text only when NOT interacting
if (_holdProgress == 0.0f && !_holdCharged) {
drawCentered("HOLD TO SILENCE", SCREEN_HEIGHT - 25, 2, fg);
}
}