This commit is contained in:
2026-02-16 03:36:04 -08:00
parent d3f5a4e3e3
commit 7763aadf51
4 changed files with 171 additions and 49 deletions

View File

@@ -59,8 +59,9 @@ void Dashboard::drawTile(TileID id) {
int tx, ty;
tilePosition(id, tx, ty);
_sprite.fillSprite(t.bgColor);
_sprite.drawRoundRect(0, 0, TILE_W, TILE_H, 8, COL_GRAY);
_sprite.fillSprite(COL_BG); // screen bg in corners
_sprite.fillRoundRect(0, 0, TILE_W, TILE_H, 8, t.bgColor); // rounded tile fill
_sprite.drawRoundRect(0, 0, TILE_W, TILE_H, 8, COL_GRAY); // border
_sprite.setTextColor(t.fgColor, t.bgColor);
_sprite.setTextFont(4);

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);
}
}

View File

@@ -3,13 +3,17 @@
#include "ScreenData.h"
#include "Dashboard.h"
// Hold gesture result
struct HoldState {
bool active = false;
bool completed = false;
uint16_t x = 0;
uint16_t y = 0;
bool active = false; // finger currently down
bool charged = false; // hold duration met, waiting for release
bool completed = false; // finger RELEASED after being charged → act now
bool cancelled = false; // finger released before charge completed
uint16_t x = 0;
uint16_t y = 0;
unsigned long holdMs = 0;
unsigned long targetMs = 0;
float progress = 0.0f; // 0.0 to 1.0
};
class DisplayManager {
@@ -35,7 +39,9 @@ private:
// Hold tracking
bool _holdActive = false;
bool _holdCharged = false; // bar is full, waiting for release
unsigned long _holdStartMs = 0;
unsigned long _holdChargeMs = 0; // when charge completed
uint16_t _holdX = 0;
uint16_t _holdY = 0;
float _holdProgress = 0.0f;
@@ -59,7 +65,7 @@ private:
void drawAlertScreen(const ScreenState& s);
void drawStatusScreen(const ScreenState& s);
void drawDashboard(const ScreenState& s);
void drawSilenceProgress(float progress);
void drawSilenceProgress(float progress, bool charged);
// Helpers
void drawCentered(const char* txt, int y, int sz, uint16_t col);

View File

@@ -1,7 +1,26 @@
/*
* KLUBHAUS ALERT v5.1 — E32R35T Edition
*
* Target: LCDWiki E32R35T (ESP32-WROOM-32E + 3.5" ST7796S + XPT2046)
*
* Hold-and-release interaction model:
* - Hold finger → progress bar fills
* - Bar full → jitter/flash ("RELEASE!")
* - Lift finger → action fires (finger already off screen)
*/
#include <SPI.h>
#include "Config.h"
#include "DoorbellLogic.h"
#include "DisplayManager.h"
#include "DoorbellLogic.h"
#include <TFT_eSPI.h>
#ifndef LOAD_GLCD
#error "LOAD_GLCD is NOT defined — fonts missing!"
#endif
#ifndef ST7796_DRIVER
#error "ST7796_DRIVER is NOT defined — wrong setup!"
#endif
#define HOLD_TO_SILENCE_MS 1000
@@ -10,14 +29,22 @@ DisplayManager display;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n=== KLUBHAUS ALERT v5.1 ===");
unsigned long t = millis();
while (!Serial && millis() - t < 3000) delay(10);
delay(500);
Serial.println("\n========================================");
Serial.println(" KLUBHAUS ALERT v5.1 — E32R35T");
#if DEBUG_MODE
Serial.println(" *** DEBUG MODE — _test topics ***");
#endif
Serial.println("========================================");
display.begin();
logic.begin();
display.render(logic.getScreenState());
delay(2000);
delay(1500);
logic.beginWiFi();
display.render(logic.getScreenState());
@@ -27,7 +54,9 @@ void setup() {
delay(1500);
logic.finishBoot();
display.render(logic.getScreenState());
display.setBacklight(false);
Serial.println("[BOOT] Ready — monitoring ntfy.sh\n");
}
void loop() {
@@ -35,39 +64,53 @@ void loop() {
const ScreenState& state = logic.getScreenState();
// ---- Touch handling (varies by screen) ----
// ---- Touch handling varies by screen ----
if (state.screen == ScreenID::ALERT) {
// Hold-to-silence: progress bar drawn by render()
// Hold-and-release to silence
HoldState hold = display.updateHold(HOLD_TO_SILENCE_MS);
if (hold.completed) {
Serial.println("[HOLD] Silence hold completed");
// Finger lifted after full charge → silence now
// Small delay so user sees the clean transition
delay(80);
logic.onTouch(TouchEvent{true, hold.x, hold.y});
}
// charged/filling states are rendered by drawSilenceProgress()
// cancelled = finger lifted early, no action needed
} else if (state.screen == ScreenID::DASHBOARD) {
// Dashboard: tile taps don't dismiss, outside taps dismiss
TouchEvent evt = display.readTouch();
if (evt.pressed) {
int tile = display.dashboardTouch(evt.x, evt.y);
if (tile >= 0) {
Serial.printf("[DASH] Tile %d tapped\n", tile);
// Tile-specific actions go here later
// Tile-specific actions go here
} else {
// Tap outside tiles — dismiss dashboard
logic.onTouch(evt);
}
delay(300); // debounce
}
} else {
// All other screens (OFF, boot, etc): simple touch
} else if (state.screen == ScreenID::OFF) {
// Any touch wakes
TouchEvent evt = display.readTouch();
if (evt.pressed) {
logic.onTouch(evt);
delay(300);
}
} else {
// Boot/WiFi screens: simple touch passthrough
TouchEvent evt = display.readTouch();
if (evt.pressed) {
logic.onTouch(evt);
delay(300);
}
}
// ---- Render ----
display.setBacklight(state.screen != ScreenID::OFF);
display.render(logic.getScreenState());
// ---- Serial commands ----