From 3fb7eb6ac3bc42843e55ff8ffaa9ff2a42d83edc Mon Sep 17 00:00:00 2001 From: Matt Edholm Date: Wed, 6 May 2026 13:41:22 -0400 Subject: [PATCH] test: add sim-yellow and sim-red envs for visual border verification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two pio envs that build a tiny sketch reading /img.bin from LittleFS and calling epd_draw_image_with_border with the chosen color. Lets us verify the actual on-device pixel composition of the sync-fail (yellow) and no-WiFi (red) borders without standing up a server failure or pulling the WiFi cable. Each sim sets NVS err_border=1 before halting, so flashing back to the normal env afterwards exercises the 304 → clean repaint recovery path end-to-end. Co-Authored-By: Claude Opus 4.7 (1M context) --- platformio.ini | 33 ++++++++++++++++++++++ src/sim_border.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 src/sim_border.cpp diff --git a/platformio.ini b/platformio.ini index c4f8b96..4952afc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -31,3 +31,36 @@ lib_deps = throwtheswitch/Unity@^2.6 build_flags = -DUNIT_TEST -std=c++17 -iquote test/mocks -iquote test -Itest/mocks -Itest test_build_src = no + +; Visual hardware tests for the sync-fail / no-WiFi border. Reads the cached +; /img.bin from LittleFS and draws it with a yellow / red border. Sets +; NVS err_border=1 so the next normal-firmware boot exercises the recovery +; redraw via 304. Flow: +; 1. pio run -e sim-yellow --target upload (see yellow border on hardware) +; 2. pio run -e sim-red --target upload (see red border on hardware) +; 3. pio run -e esp32dev --target upload (back to normal; verifies 304 recovery) +[env:sim-yellow] +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = 115200 +upload_port = /dev/ttyUSB0 +monitor_port = /dev/ttyUSB0 +board_build.filesystem = littlefs +build_flags = -DSIM_BORDER -DSIM_BORDER_COLOR=COLOR_YELLOW +build_src_filter = + + +lib_deps = + ricmoo/QRCode@^0.0.1 + +[env:sim-red] +platform = espressif32 +board = esp32dev +framework = arduino +monitor_speed = 115200 +upload_port = /dev/ttyUSB0 +monitor_port = /dev/ttyUSB0 +board_build.filesystem = littlefs +build_flags = -DSIM_BORDER -DSIM_BORDER_COLOR=COLOR_RED +build_src_filter = + + +lib_deps = + ricmoo/QRCode@^0.0.1 diff --git a/src/sim_border.cpp b/src/sim_border.cpp new file mode 100644 index 0000000..ecadd0d --- /dev/null +++ b/src/sim_border.cpp @@ -0,0 +1,69 @@ +// Visual hardware test for sync-fail / no-WiFi border rendering. +// +// Built only by env:sim-yellow and env:sim-red in platformio.ini. Reads the +// last cached image from LittleFS, draws it through epd_draw_image_with_border +// with the configured color, and sets NVS_KEY_ERR_BORDER=1 so that flashing +// the normal firmware afterwards exercises the recovery path (next 304 +// repaints the image clean). +// +// Usage: +// pio run -e sim-yellow --target upload +// pio run -e sim-red --target upload +// pio run -e esp32dev --target upload # back to normal — verifies recovery + +#ifdef SIM_BORDER + +#include +#include +#include +#include +#include "config.h" +#include "epd.h" + +#ifndef SIM_BORDER_COLOR +#error "sim_border.cpp built without SIM_BORDER_COLOR — set it in platformio.ini" +#endif + +void setup() { + Serial.begin(115200); + Serial.println("[sim_border] boot"); + + pinMode(PIN_CS, OUTPUT); + pinMode(PIN_DC, OUTPUT); + pinMode(PIN_RST, OUTPUT); + pinMode(PIN_BUSY, INPUT); + pinMode(PIN_BTN_RESET, INPUT_PULLUP); + + SPI.begin(PIN_SCK, -1, PIN_MOSI, PIN_CS); + SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0)); + LittleFS.begin(true); + + epd_init(); + + File f = LittleFS.open(IMAGE_PATH, "r"); + if (f) { + Serial.printf("[sim_border] /img.bin %u bytes — drawing with border color 0x%X\n", + (unsigned)f.size(), (unsigned)SIM_BORDER_COLOR); + epd_draw_image_with_border(f, SIM_BORDER_COLOR, BORDER_THICKNESS_PX); + f.close(); + } else { + Serial.println("[sim_border] no /img.bin — falling back to full fill"); + epd_fill(SIM_BORDER_COLOR); + } + + epd_sleep(); + + // Mark err_border so the next normal-firmware boot will trigger the + // 304-based clean repaint and we can confirm recovery end-to-end. + Preferences prefs; + prefs.begin(NVS_NAMESPACE, false); + prefs.putInt(NVS_KEY_ERR_BORDER, 1); + prefs.end(); + + Serial.println("[sim_border] done — halting (deep sleep, button-reset to wake)"); + esp_deep_sleep_start(); +} + +void loop() {} + +#endif // SIM_BORDER