2026-10-13 00:56:32 +02:00
|
|
|
#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;
|
|
|
|
|
// Power off this long after the display is no longer needed (night, standby, logo)
|
|
|
|
|
const uint32_t POWER_OFF_DELAY = 30000;
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// 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"
|
|
|
|
|
|
2026-10-13 01:05:06 +02:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
// 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
|
2026-10-13 00:56:32 +02:00
|
|
|
const uint32_t OTA_PANIC_WINDOW = 15000;
|
2026-10-13 01:05:06 +02:00
|
|
|
// 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;
|
|
|
|
|
// 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.1.0"
|
2026-10-13 00:56:32 +02:00
|
|
|
|
|
|
|
|
// 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"
|
2026-10-13 01:05:06 +02:00
|
|
|
#define HA_SOFTWARE_VERSION FIRMWARE_VERSION
|