This commit is contained in:
2026-02-12 02:56:59 -08:00
parent 61739b13db
commit e537d9c918

View File

@@ -18,34 +18,41 @@ const unsigned long BLINK_PERIOD = 1000;
#define BACKLIGHT_PIN 22 #define BACKLIGHT_PIN 22
#define BUTTON_PIN 9 #define BUTTON_PIN 9
// Display colors // ============== COCAINE CHIC PALETTE ==============
#define COLOR_BLACK 0x0000 // Miami Vice meets gallery minimal — neon pastels on stark grounds
#define COLOR_RED 0xF800
#define COLOR_GREEN 0x07E0
#define COLOR_BLUE 0x001F
#define COLOR_WHITE 0xFFFF
#define COLOR_YELLOW 0xFFE0
// Screen dimensions #define COLOR_BLACK 0x0000 // Midnight void
#define SCREEN_WIDTH 172 #define COLOR_COCAINE 0xFFFE // #fff8fa — warm white, almost pink
#define SCREEN_HEIGHT 320 #define COLOR_TEAL 0x05F5 // #0bd3d3 — electric neon teal
#define COLOR_FUCHSIA 0xFC6E // #f890e7 — hot pink neon
#define COLOR_MINT 0x674D // #64e8ba — mint confirmation
// Alert alternates between these two states:
#define ALERT_BG_1 COLOR_TEAL // Teal background
#define ALERT_TEXT_1 COLOR_COCAINE // White text
#define ALERT_BG_2 COLOR_FUCHSIA // Fuchsia background
#define ALERT_TEXT_2 COLOR_COCAINE // White text (or try COLOR_BLACK for contrast)
// Screen dimensions (LANDSCAPE: 320x172)
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 172
// =========================================== // ===========================================
// Arduino_GFX for Waveshare ESP32-C6-LCD-1.47 // Arduino_GFX for Waveshare ESP32-C6-LCD-1.47 — LANDSCAPE mode
Arduino_DataBus *bus = new Arduino_HWSPI( Arduino_DataBus *bus = new Arduino_HWSPI(
15 /* DC */, 14 /* CS */, 15 /* DC */, 14 /* CS */,
7 /* SCK */, 6 /* MOSI */, -1 /* MISO */); 7 /* SCK */, 6 /* MOSI */, -1 /* MISO */);
Arduino_GFX *gfx = new Arduino_ST7789( Arduino_GFX *gfx = new Arduino_ST7789(
bus, 21 /* RST */, 0 /* rotation */, true /* IPS */, bus, 21 /* RST */, 1 /* rotation: LANDSCAPE */, true /* IPS */,
SCREEN_WIDTH, SCREEN_HEIGHT, 172 /* native width */, 320 /* native height */,
34 /* col offset 1 */, 0 /* row offset 1 */, 34 /* col offset 1 */, 0 /* row offset 1 */,
34 /* col offset 2 */, 0 /* row offset 2 */); 34 /* col offset 2 */, 0 /* row offset 2 */);
// =========================================== // ===========================================
enum State { STATE_SILENT, STATE_ALARM }; enum State { STATE_SILENT, STATE_ALERT };
State currentState = STATE_SILENT; State currentState = STATE_SILENT;
@@ -58,15 +65,15 @@ String lastAlertId = "";
String lastSilenceId = ""; String lastSilenceId = "";
bool lastButtonState = false; bool lastButtonState = false;
// Store the triggering message for display String alertMessage = "";
String alarmMessage = "";
// =========================================== // ===========================================
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
delay(3000); delay(3000);
Serial.println("\n=== MESSAGE DOORBELL ==="); Serial.println("\n=== COCAINE CHIC DOORBELL ===");
Serial.println("Aesthetic: Miami Vice minimal, gallery alert");
pinMode(BACKLIGHT_PIN, OUTPUT); pinMode(BACKLIGHT_PIN, OUTPUT);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
@@ -77,7 +84,7 @@ void setup() {
Serial.println("Init GFX..."); Serial.println("Init GFX...");
gfx->begin(); gfx->begin();
Serial.println("GFX begin OK"); Serial.println("GFX begin OK — LANDSCAPE 320x172");
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
testDisplay(); testDisplay();
@@ -100,18 +107,16 @@ void setup() {
Serial.println("\nWiFi FAILED"); Serial.println("\nWiFi FAILED");
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
// FIXED: Added yPos parameter (140 = center vertically) drawCenteredText("OFFLINE", 3, COLOR_FUCHSIA, COLOR_BLACK, 70);
drawCenteredText("NO WIFI", 2, COLOR_RED, COLOR_BLACK, 140);
delay(3000); delay(3000);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
} else { } else {
Serial.println("\nWiFi OK: " + WiFi.localIP().toString()); Serial.println("\nWiFi OK: " + WiFi.localIP().toString());
// Brief status flash
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
// FIXED: Added yPos parameter (10 = near top) drawCenteredText("CONNECTED", 2, COLOR_MINT, COLOR_BLACK, 50);
drawCenteredText("WiFi OK", 2, COLOR_GREEN, COLOR_BLACK, 10); gfx->setTextSize(1);
gfx->setCursor(10, 50); gfx->setCursor(80, 90);
gfx->println(WiFi.localIP().toString()); gfx->println(WiFi.localIP().toString());
delay(800); delay(800);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
@@ -120,6 +125,7 @@ void setup() {
Serial.println("=== SETUP COMPLETE ==="); Serial.println("=== SETUP COMPLETE ===");
Serial.println(String("State: ") + getStateName(currentState)); Serial.println(String("State: ") + getStateName(currentState));
Serial.println("Silent: screen dark, gallery-ready");
} }
void loop() { void loop() {
@@ -138,14 +144,14 @@ void loop() {
} }
break; break;
case STATE_ALARM: case STATE_ALERT:
if (now - lastSilencePoll >= SILENCE_POLL_INTERVAL) { if (now - lastSilencePoll >= SILENCE_POLL_INTERVAL) {
lastSilencePoll = now; lastSilencePoll = now;
checkSilenceTopic(); checkSilenceTopic();
} }
updateBlink(now); updateBlink(now);
if (now - blinkStartTime >= BLINK_DURATION) { if (now - blinkStartTime >= BLINK_DURATION) {
Serial.println("ALARM TIMEOUT"); Serial.println("ALERT TIMEOUT");
transitionTo(STATE_SILENT); transitionTo(STATE_SILENT);
} }
break; break;
@@ -168,55 +174,53 @@ void transitionTo(State newState) {
switch (currentState) { switch (currentState) {
case STATE_SILENT: case STATE_SILENT:
alarmMessage = ""; alertMessage = "";
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
Serial.println("Silent: screen off, message cleared"); Serial.println("Silent: cocaine white standby, screen dark");
break; break;
case STATE_ALARM: case STATE_ALERT:
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
blinkStartTime = millis(); blinkStartTime = millis();
blinkState = false; blinkState = false;
drawAlarmScreen(COLOR_RED, COLOR_WHITE); drawAlertScreen(ALERT_BG_1, ALERT_TEXT_1);
Serial.println("ALARM: message displayed"); Serial.println("ALERT: neon pulse activated");
break; break;
} }
} }
const char* getStateName(State s) { const char* getStateName(State s) {
return (s == STATE_SILENT) ? "SILENT" : "ALARM"; return (s == STATE_SILENT) ? "SILENT" : "ALERT";
} }
// ============== ALARM SCREEN WITH MESSAGE ============== // ============== ALERT SCREEN ==============
void drawAlarmScreen(uint16_t bgColor, uint16_t textColor) { void drawAlertScreen(uint16_t bgColor, uint16_t textColor) {
gfx->fillScreen(bgColor); gfx->fillScreen(bgColor);
// Draw "ALARM!" header at top // "ALERT" header — bold, centered top
gfx->setTextSize(2); drawCenteredText("ALERT", 3, textColor, bgColor, 20);
gfx->setTextColor(textColor, bgColor);
drawCenteredText("ALARM!", 2, textColor, bgColor, 30);
// Draw the triggering message below, auto-sized // The message auto-sized, centered below
if (alarmMessage.length() > 0) { if (alertMessage.length() > 0) {
drawAutoSizedMessage(alarmMessage, textColor, bgColor, 80); drawAutoSizedMessage(alertMessage, textColor, bgColor, 70);
} }
} }
void drawAutoSizedMessage(String message, uint16_t textColor, uint16_t bgColor, int yPos) { void drawAutoSizedMessage(String message, uint16_t textColor, uint16_t bgColor, int yPos) {
int textSize = calculateOptimalTextSize(message, SCREEN_WIDTH - 20, SCREEN_HEIGHT - yPos - 20); int textSize = calculateOptimalTextSize(message, SCREEN_WIDTH - 40, SCREEN_HEIGHT - yPos - 20);
gfx->setTextSize(textSize); gfx->setTextSize(textSize);
gfx->setTextColor(textColor, bgColor); gfx->setTextColor(textColor, bgColor);
gfx->setTextBound(10, yPos, SCREEN_WIDTH - 10, SCREEN_HEIGHT - 10); gfx->setTextBound(20, yPos, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 10);
gfx->setCursor(10, yPos); gfx->setCursor(20, yPos);
gfx->println(message); gfx->println(message);
} }
int calculateOptimalTextSize(String message, int maxWidth, int maxHeight) { int calculateOptimalTextSize(String message, int maxWidth, int maxHeight) {
for (int size = 4; size >= 1; size--) { for (int size = 5; size >= 1; size--) {
gfx->setTextSize(size); gfx->setTextSize(size);
int charWidth = 6 * size; int charWidth = 6 * size;
int lineHeight = 8 * size; int lineHeight = 8 * size;
@@ -224,7 +228,7 @@ int calculateOptimalTextSize(String message, int maxWidth, int maxHeight) {
int numLines = (message.length() + charsPerLine - 1) / charsPerLine; int numLines = (message.length() + charsPerLine - 1) / charsPerLine;
int totalHeight = numLines * lineHeight; int totalHeight = numLines * lineHeight;
if (totalHeight <= maxHeight && charsPerLine >= 5) { if (totalHeight <= maxHeight && charsPerLine >= 4) {
return size; return size;
} }
} }
@@ -237,7 +241,7 @@ void drawCenteredText(const char* text, int textSize, uint16_t textColor, uint16
int textWidth = strlen(text) * 6 * textSize; int textWidth = strlen(text) * 6 * textSize;
int xPos = (SCREEN_WIDTH - textWidth) / 2; int xPos = (SCREEN_WIDTH - textWidth) / 2;
if (xPos < 0) xPos = 0; if (xPos < 20) xPos = 20;
gfx->setCursor(xPos, yPos); gfx->setCursor(xPos, yPos);
gfx->println(text); gfx->println(text);
@@ -251,26 +255,27 @@ void handleButton() {
if (pressed && !lastButtonState) { if (pressed && !lastButtonState) {
Serial.println("BUTTON PRESSED"); Serial.println("BUTTON PRESSED");
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
gfx->fillScreen(COLOR_WHITE); gfx->fillScreen(COLOR_COCAINE);
drawCenteredText("TEST MODE", 2, COLOR_BLACK, COLOR_WHITE, 140); drawCenteredText("TEST", 3, COLOR_BLACK, COLOR_COCAINE, 70);
Serial.println("Screen WHITE (held)"); Serial.println("Screen COCAINE WHITE (held)");
} }
else if (!pressed && lastButtonState) { else if (!pressed && lastButtonState) {
Serial.println("BUTTON RELEASED"); Serial.println("BUTTON RELEASED");
if (currentState == STATE_ALARM) { if (currentState == STATE_ALERT) {
Serial.println("Reset ALARM -> SILENT"); Serial.println("Reset ALERT -> SILENT");
transitionTo(STATE_SILENT); transitionTo(STATE_SILENT);
// Mint confirmation flash
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
gfx->fillScreen(COLOR_GREEN); gfx->fillScreen(COLOR_MINT);
drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_GREEN, 140); drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_MINT, 70);
delay(500); delay(400);
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
} else { } else {
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
Serial.println("Screen BLACK, backlight OFF"); Serial.println("Screen BLACK, silent");
} }
} }
@@ -311,15 +316,15 @@ void checkAlertTopic() {
Serial.println(" -> SILENCE command"); Serial.println(" -> SILENCE command");
transitionTo(STATE_SILENT); transitionTo(STATE_SILENT);
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
gfx->fillScreen(COLOR_GREEN); gfx->fillScreen(COLOR_MINT);
drawCenteredText("SILENCE", 3, COLOR_BLACK, COLOR_GREEN, 140); drawCenteredText("SILENCE", 3, COLOR_BLACK, COLOR_MINT, 70);
delay(800); delay(800);
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
} else { } else {
Serial.println(" -> TRIGGER ALARM"); Serial.println(" -> TRIGGER ALERT");
alarmMessage = message; alertMessage = message;
transitionTo(STATE_ALARM); transitionTo(STATE_ALERT);
} }
} }
@@ -338,12 +343,12 @@ void checkSilenceTopic() {
Serial.print("Silence: "); Serial.print("Silence: ");
Serial.println((const char*)doc["message"]); Serial.println((const char*)doc["message"]);
if (currentState == STATE_ALARM) { if (currentState == STATE_ALERT) {
Serial.println(" -> Stop alarm via silence topic"); Serial.println(" -> Stop alert via silence topic");
transitionTo(STATE_SILENT); transitionTo(STATE_SILENT);
digitalWrite(BACKLIGHT_PIN, HIGH); digitalWrite(BACKLIGHT_PIN, HIGH);
gfx->fillScreen(COLOR_GREEN); gfx->fillScreen(COLOR_MINT);
drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_GREEN, 140); drawCenteredText("SILENCED", 3, COLOR_BLACK, COLOR_MINT, 70);
delay(800); delay(800);
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
digitalWrite(BACKLIGHT_PIN, LOW); digitalWrite(BACKLIGHT_PIN, LOW);
@@ -381,41 +386,44 @@ void updateBlink(unsigned long now) {
if (newState != blinkState) { if (newState != blinkState) {
blinkState = newState; blinkState = newState;
uint16_t bgColor = blinkState ? COLOR_WHITE : COLOR_RED;
uint16_t textColor = blinkState ? COLOR_RED : COLOR_WHITE; // Cocaine chic alternation: TEAL ↔ FUCHSIA
drawAlarmScreen(bgColor, textColor); uint16_t bgColor = blinkState ? ALERT_BG_2 : ALERT_BG_1;
Serial.println(blinkState ? "WHITE bg / RED text" : "RED bg / WHITE text"); uint16_t textColor = blinkState ? ALERT_TEXT_2 : ALERT_TEXT_1;
drawAlertScreen(bgColor, textColor);
Serial.println(blinkState ? "FUCHSIA flash" : "TEAL flash");
} }
} }
// ============== DISPLAY TEST ============== // ============== DISPLAY TEST ==============
void testDisplay() { void testDisplay() {
Serial.println(" RED"); Serial.println(" TEAL");
gfx->fillScreen(COLOR_RED); gfx->fillScreen(COLOR_TEAL);
delay(100); delay(150);
Serial.println(" GREEN"); Serial.println(" FUCHSIA");
gfx->fillScreen(COLOR_GREEN); gfx->fillScreen(COLOR_FUCHSIA);
delay(100); delay(150);
Serial.println(" BLUE"); Serial.println(" COCAINE WHITE");
gfx->fillScreen(COLOR_BLUE); gfx->fillScreen(COLOR_COCAINE);
delay(100); delay(150);
Serial.println(" WHITE"); Serial.println(" MINT");
gfx->fillScreen(COLOR_WHITE); gfx->fillScreen(COLOR_MINT);
delay(100); delay(150);
Serial.println(" BLACK"); Serial.println(" BLACK");
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
delay(100); delay(100);
Serial.println(" TEXT TEST"); Serial.println(" LANDSCAPE TEXT TEST");
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
drawCenteredText("GFX OK!", 2, COLOR_WHITE, COLOR_BLACK, 50); drawCenteredText("COCAINE", 3, COLOR_COCAINE, COLOR_BLACK, 50);
drawCenteredText("Text works!", 2, COLOR_WHITE, COLOR_BLACK, 80); drawCenteredText("CHIC", 3, COLOR_TEAL, COLOR_BLACK, 90);
delay(500); delay(400);
gfx->fillScreen(COLOR_BLACK); gfx->fillScreen(COLOR_BLACK);
Serial.println("Test complete"); Serial.println("Test complete");