Add persistent script storage + hot-reload, verified live

lua_runtime now loads the running script from a new LittleFS-backed
drivers::storage (joltwallet/littlefs, the project's fifth external
managed component -- mounts the "storage" partition already reserved
in partitions.csv), falling back to the compiled-in default script
only on first boot. transport exposes GET/POST /api/script -- raw Lua
text, not JSON, since json_helpers.h can't round-trip scripts safely
-- relayed to lua_runtime via the same callback-registration pattern
already used for LedColorHandler, keeping transport free of a
dependency on lua_runtime. lua_runtime_reload() persists and hot-swaps
to a fresh Lua state immediately, no reboot.

Verified on real ESP32-C6 hardware: script loads via kvida-sdk, an
edited script hot-reloads within one tick, and the edit survives a
power cycle (proving LittleFS persistence, not just an in-RAM change).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Ronny Eia
2026-07-12 10:27:00 +02:00
parent eae6d3af5a
commit 967fecbf69
12 changed files with 329 additions and 29 deletions

View File

@@ -0,0 +1,21 @@
#pragma once
#include <cstddef>
namespace kvida::drivers {
// Mounts the "storage" partition (see partitions.csv) as a LittleFS
// filesystem at /storage. Safe to call multiple times (no-op if already
// mounted). Formats the partition automatically if it's blank or corrupt.
void storage_init();
// Reads a whole file into buf (cap includes room for the implicit '\0'
// this appends). Returns false if the filesystem isn't mounted, the file
// doesn't exist, or it doesn't fit in cap.
bool storage_read_file(const char *path, char *buf, size_t cap, size_t *out_len);
// Writes/overwrites a whole file. Returns false if the filesystem isn't
// mounted or the write fails.
bool storage_write_file(const char *path, const char *data, size_t len);
} // namespace kvida::drivers