Files
Flipdot-display/src/esp32/config.h
T
mangavalkandClaude Opus 5.5 968492ca35 Slow mode replaces the late-evening quarter hours
Slow mode (Home Assistant switch "FlipDot Display Slow mode", dropdown
"FlipDot Display Slow mode interval", web UI Settings) makes the display
change only every 1, 2, 5, 10, 15, 20, 30 or 60 minutes, on the clock, and
powers it off in between: less noise. Nothing else is drawn meanwhile, also
no page changes. It updates at once after boot, the night, the Power switch
and live mode, and when it is switched off. Rules can override it ("show at
once in slow mode"): while their page is shown the display works normally.

Settings layout 7 and schedule layout 4 (older records are converted; they
are stored again once the firmware is marked good, so a rollback still
finds the old ones). Pages in older formats are rewritten in the current
one, in time-boxed steps. /api/status reports old_data_left.

Version 2.15.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 21:16:41 +02:00

127 lines
6.4 KiB
C

#pragma once
// All ESP32 settings. Credentials are in secrets.h (see secrets.example.h).
// Kept free of Arduino types so the logic modules can be tested on the PC.
#include <stdint.h>
// ---------------------------------------------------------------------------
// Pins
// ---------------------------------------------------------------------------
const int LED_PIN = 2; // built-in LED of the ESP32 DevKit v1
const int RELAY_PIN = 13; // powers the panels and the Nano (LOW = on)
// Link to the Nano on UART2. Serial (UART0) stays free for USB / debug output.
const int NANO_RX_PIN = 16; // wired to the Nano TX (through a 5V -> 3.3V divider)
const int NANO_TX_PIN = 17; // wired to the Nano RX
// Optional: GPIO that resets the Nano through an NPN transistor (HIGH = reset), -1 = not wired.
// Needed to flash a Nano with the Optiboot bootloader, which doesn't start after a power cycle.
const int NANO_RESET_PIN = -1;
// ---------------------------------------------------------------------------
// Display and Nano
// ---------------------------------------------------------------------------
const uint8_t DISPLAY_WIDTH = 84;
const uint8_t DISPLAY_HEIGHT = 19;
const uint8_t PANEL_WIDTH = 28;
const uint16_t FLIP_TIME = 225; // flip pulse length in us, sent to the Nano at boot
const uint32_t NANO_BAUD = 115200;
// Max wait for the Nano's READY after power on (also the wait when Nano TX is not wired to our RX)
const uint32_t NANO_BOOT_TIMEOUT = 3000;
// After a frame is cleared, wait this long before cutting the power, so the dots can flip
const uint32_t CLEAR_BEFORE_OFF_TIME = 1000;
// Status messages (boot, crash, recovery): time for the Nano to flip all dots before the
// power is cut again. The message stays visible without power.
const uint32_t STATUS_FLIP_TIME = 2000;
// WiFi down this long while the clock runs: show "No WiFi" with the time instead
const uint32_t NO_WIFI_SHOW_TIME = 60000;
// Live mode of the web UI ends this long after the last image was sent
const uint32_t LIVE_TIMEOUT = 30UL * 60 * 1000;
// Power off this long after the display is no longer needed (night, standby)
const uint32_t POWER_OFF_DELAY = 30000;
// Home Assistant values on dynamic pages (net/ha_api): read this often, and the HTTP
// timeout (connect, then the answer; the requests run in their own task, loop() doesn't wait)
const uint32_t HA_POLL_INTERVAL = 60000;
const uint32_t HA_HTTP_TIMEOUT = 5000;
// After a failed read (Home Assistant down) an entity is read again after this at the soonest
const uint32_t HA_ERROR_INTERVAL = 60000;
// The task that does the requests (net/ha_api): core 0 runs WiFi and the network stack,
// loop() runs on core 1. Stack in bytes.
const int HA_TASK_CORE = 0;
const uint32_t HA_TASK_STACK = 8192;
// A value of the web UI's test button is kept this long for the page to pick it up (ms)
const uint32_t HA_PREVIEW_KEEP = 10000;
// Moving dynamic pages (scrolling, seconds): the next frame waits until the Nano received
// this one (characters per ms at NANO_BAUD) and flipped its changed dots, plus a margin
const uint32_t NANO_CHARS_PER_MS = NANO_BAUD / 10000;
const uint32_t FRAME_MARGIN = 20;
// Frame check (logic/frame_check.h): after a frame the Nano is asked for the checksum of
// its image (C), at most this often (moving pages send many frames)
const uint32_t FRAME_CHECK_INTERVAL = 3000;
// No answer this long: counted as lost (the C or the frame before it got garbled)
const uint32_t FRAME_CHECK_TIMEOUT = 2000;
// A wrong image is repaired by sending the whole image again, at most this often
const uint32_t FRAME_REPAIR_MIN_GAP = 10000;
// ---------------------------------------------------------------------------
// Flashing the Nano over WiFi (see README.md, pio run -e nano_ota -t upload)
// ---------------------------------------------------------------------------
const uint16_t NANO_FLASH_PORT = 2323;
// The bootloader baud rate is chosen by the uploader (57600 old bootloader, 115200 Optiboot)
const uint32_t NANO_POWER_OFF_TIME = 1000; // relay off time to make sure the Nano resets
const uint32_t NANO_RESET_DELAY = 200; // after power on, before the reset pulse
const uint32_t NANO_RESET_PULSE = 50;
// ---------------------------------------------------------------------------
// Network, time and Home Assistant
// ---------------------------------------------------------------------------
#define HOSTNAME "FlipDotDisplay"
// Europe/Amsterdam
#define TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3"
#define NTP_SERVER "pool.ntp.org"
// ---------------------------------------------------------------------------
// Keeping OTA alive (see logic/boot_policy.h and system/firmware_guard.h)
// ---------------------------------------------------------------------------
// After a crash, only run OTA for this long before starting the main code
const uint32_t OTA_PANIC_WINDOW = 15000;
// This many crashes in a row: safe mode (only WiFi and OTA) for SAFE_MODE_TIME
const uint8_t SAFE_MODE_CRASHES = 3;
const uint32_t SAFE_MODE_TIME = 10UL * 60 * 1000;
// A new OTA firmware must run this long with WiFi, or the previous firmware comes back
const uint32_t FIRMWARE_VALID_TIME = 60UL * 1000;
// Running this long without a crash clears the crash counter
const uint32_t CRASH_FREE_TIME = 5UL * 60 * 1000;
// loop() must not block longer than this, or the ESP32 restarts (counts as a crash)
const uint32_t WATCHDOG_TIMEOUT_S = 30;
// Recovery app (src/recovery): started by the triggers in logic/boot_policy.h
const uint8_t POWER_CYCLES_FOR_RECOVERY = 3; // power ons in a row ...
const uint32_t POWER_CYCLE_WINDOW = 10000; // ... each switched off within this time
const uint32_t RECOVERY_TIME = 10UL * 60 * 1000; // then back to the clock firmware
// Stay at least this long, also when the WiFi works right away (limits switching back and
// forth, which wears the otadata flash sector)
const uint32_t RECOVERY_MIN_TIME = 60UL * 1000;
#define SETUP_AP_SSID "FlipDot-Setup" // password: SETUP_AP_PASSWORD in secrets.h
const uint32_t SETUP_AP_DELAY = 20000; // open the AP when WiFi fails this long
// WiFi: first connection at boot, and restart when WiFi stays down this long
const uint32_t WIFI_CONNECT_TIMEOUT = 30000;
const uint32_t WIFI_RESTART_TIME = 10UL * 60 * 1000;
#define FIRMWARE_VERSION "2.15.0"
// Home Assistant device id (do not change: Home Assistant's entities are linked to it)
const uint8_t HA_DEVICE_ID[] = {0x34, 0x86, 0x5d, 0x3a, 0x08, 0x28};
#define HA_DEVICE_NAME "FlipDotDisplay"
#define HA_SOFTWARE_VERSION FIRMWARE_VERSION