Public Access
The Nano's periodic full redraw blocked for ~0.8 s. A frame that arrived meanwhile overflowed its 64-byte serial buffer; lost bytes in a bitmap shift the rest of the image (picture moved up), and diff frames never repaired it. - Nano: all drawing (frames, effects, the dot refresh) runs from update() in ~1 ms slices; the refresh pauses while a frame is received or shown - New commands: C (reply with the image checksum) and I (refresh minutes, EEPROM) - ESP32: NanoMonitor asks for the checksum after frames and sends the whole image again on a mismatch, missing answer or Nano restart; counts ERR replies. Periodic whole-image resync. - Settings: "Dot refresh" and "Image resync" intervals (settings v5, v4 records are migrated) - System tab: loop timing, free memory, frame check counts - test_driver: the real driver against a simulated panel Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
121 lines
6.1 KiB
C
121 lines
6.1 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 (a read blocks loop() for at most about twice this)
|
|
const uint32_t HA_POLL_INTERVAL = 60000;
|
|
const uint32_t HA_HTTP_TIMEOUT = 1500;
|
|
// After a failed read (Home Assistant down) an entity is read again after this at the soonest
|
|
const uint32_t HA_ERROR_INTERVAL = 60000;
|
|
// 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.8.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
|