Power-cycle-friendly Nano boot and ESP relay handling

Nano / driver:
- No full on/off flip at boot; the first display() after boot is a forced
  full redraw instead, since the physical dot state is unknown
- Send READY when booted

ESP32:
- relayOn() only switches and waits when the relay was off, and waits for
  the Nano's READY (3 s timeout) instead of a fixed 3 s on every frame
- relayOff() ends Serial and releases the TX pin so the idle-high line no
  longer back-powers the Nano through its RX pin
- No display commands are sent while the relay is off
- Switching the relay on cancels a pending power-off countdown

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-10-13 00:12:28 +02:00
1 parent f7ffcf4ab3
commit 6e4d5e152b
8 files changed
+158 -68

No files matched your search

+11 -5
View File
@@ -30,9 +30,14 @@ See README.md for the overview.
- `src/esp32/secrets.h` holds the real credentials and is gitignored. Never commit it.
Add new secrets to `secrets.example.h` as placeholders.
- The relay (ESP32 GPIO 13, `LOW` = on) powers both the panels and the Nano. Each time it
switches on, the Nano cold-boots: bootloader, then `begin()` flips every dot on and off.
Any data the ESP sends during that time is lost. The Nano keeps no state over a power
cycle except the flip time in EEPROM.
switches on, the Nano cold-boots and then sends `READY`. The ESP's `relayOn()` waits for
that message, at most `NANO_BOOT_TIMEOUT`. The timeout also covers the case where the
Nano's TX isn't wired to the ESP's RX.
- `relayOff()` ends `Serial` and sets the TX pin to input. Otherwise the idle-high TX line
powers the Nano through its RX pin. Never send display commands while `relay_on` is
false.
- The Nano keeps no state over a power cycle except the flip time in EEPROM. The driver
forces a full redraw on the first `display()` after boot (`_force_next`).
- Hardware is not available here. Builds can be checked, but runtime behaviour can't.
## Nano serial parser (`src/nano/main.cpp`)
@@ -45,8 +50,9 @@ See README.md for the overview.
2 s with no serial data. The ESP sends one frame per second, ending with `D`.
- Flip time is stored in EEPROM as a magic word at address 0 and a `uint16_t` at
address 2. Values outside 50–2000 µs are rejected.
- The Nano doesn't send an acknowledgement. Whether the Nano's TX is wired to the ESP's RX
is unknown, so don't make the ESP wait for replies.
- The Nano only replies `READY` (at boot) and `ERR: ...`. There is no per-frame
acknowledgement. Whether the Nano's TX is wired to the ESP's RX is unconfirmed, so every
wait for a reply needs a timeout.
- To test the parser without hardware, compile `main.cpp` with g++ (Strawberry Perl
provides it at `C:\Strawberry\c\bin`) and mock headers for `Arduino.h`, `EEPROM.h` and
`BROSE9323.h`.