refactor(lua)!: migrate to the per-feature namespaces
Follows lib/esp32-lua-api: gui -> screen, node -> tree, settings and input split into screen/sys/touch/buttons. Settings is one provider lighter, with timezone on Sys and rotation and theme on Gui, which now applies and persists a rotation in one call. The calibration screen stashes the rotation it borrows rather than relying on a transient setter.
This commit is contained in:
+18
-12
@@ -1,7 +1,3 @@
|
||||
// Board bring-up and the loop. Everything about running a Lua app -- the state,
|
||||
// the bindings, app loading, navigation history -- lives in the shared runtime
|
||||
// behind LuaHost.
|
||||
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
#include <TFT_eSPI.h>
|
||||
@@ -31,10 +27,10 @@ LuaHost host(tft, touch);
|
||||
static bool halted = false;
|
||||
|
||||
static void fallbackScreen(const char* message) {
|
||||
tft.resetViewport(); // no app, no status bar: this message owns the panel
|
||||
tft.resetViewport();
|
||||
tft.setRotation(0);
|
||||
tft.fillScreen(TFT_WHITE);
|
||||
tft.setTextSize(2);
|
||||
tft.setTextSize(1);
|
||||
tft.setTextColor(TFT_RED, TFT_WHITE);
|
||||
tft.drawString(message, 10, 10);
|
||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||
@@ -43,7 +39,7 @@ static void fallbackScreen(const char* message) {
|
||||
halted = true;
|
||||
}
|
||||
|
||||
// ponytail: fixed 10s / 8% dim, no fade. Make it a setting when someone asks.
|
||||
// Auto Dim
|
||||
constexpr uint32_t kDimAfterMs = 10000;
|
||||
constexpr int kBacklightChannel = 0;
|
||||
uint32_t lastTouchMs = 0;
|
||||
@@ -62,8 +58,7 @@ void updateBacklight() {
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
// A failed new otherwise unwinds to terminate() and a bare abort backtrace.
|
||||
// Nothing can be freed at that point, so this only buys a legible cause.
|
||||
// OOM Logging
|
||||
std::set_new_handler([]() {
|
||||
logHeap("oom");
|
||||
Serial.println("[fatal] out of memory");
|
||||
@@ -71,41 +66,52 @@ void setup() {
|
||||
ESP.restart();
|
||||
});
|
||||
|
||||
// Start TFT
|
||||
tft.begin();
|
||||
tft.setRotation(0);
|
||||
tft.fillScreen(TFT_WHITE);
|
||||
touchSpi.begin(14, 12, 13, TOUCH_CS);
|
||||
touch.begin(touchSpi);
|
||||
|
||||
// TFT_eSPI leaves TFT_BL a plain output; LEDC takes it over for dimming.
|
||||
// TFT Dimming
|
||||
ledcSetup(kBacklightChannel, 5000, 8);
|
||||
ledcAttachPin(TFT_BL, kBacklightChannel);
|
||||
ledcWrite(kBacklightChannel, 255);
|
||||
lastTouchMs = millis();
|
||||
|
||||
// SD Card
|
||||
sdSpi.begin(SD_SCK, SD_MISO, SD_MOSI, SD_CS);
|
||||
if (!SD.begin(SD_CS, sdSpi)) {
|
||||
fallbackScreen("SD card mount failed");
|
||||
return;
|
||||
}
|
||||
|
||||
settings.load(); // absent file keeps the built-in defaults
|
||||
// Load Settings & Load Lua
|
||||
settings.load();
|
||||
net::begin();
|
||||
if (!host.begin())
|
||||
fallbackScreen("home failed to start");
|
||||
|
||||
// Start WiFi
|
||||
net::startWifi();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Halted
|
||||
if (halted) {
|
||||
delay(100);
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto Dim & Net / Lua Loop
|
||||
updateBacklight();
|
||||
net::loop();
|
||||
host.loop();
|
||||
// The launcher failing to start is the one error no app can recover from.
|
||||
|
||||
// Failed Lua Main
|
||||
if (!host.running())
|
||||
fallbackScreen("home failed to start");
|
||||
|
||||
// Yield
|
||||
delay(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user