From 49850514909addaa5f4cb5f3df286f65532f5fc9 Mon Sep 17 00:00:00 2001 From: Yevhen Boichuk Date: Thu, 8 Oct 2026 16:20:00 +0300 Subject: [PATCH 1/2] add: add more modules for wallpaper --- src/apps/lua/luawallpaper.cpp | 40 +++++++++++++++++++++++++++++++++++ src/apps/lua/luawallpaper.h | 3 ++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/apps/lua/luawallpaper.cpp b/src/apps/lua/luawallpaper.cpp index b06621d7..8bddf967 100644 --- a/src/apps/lua/luawallpaper.cpp +++ b/src/apps/lua/luawallpaper.cpp @@ -1,12 +1,22 @@ #include "luawallpaper.h" #include +#include #include #include "luarunner.h" #include "lualilka_display.h" #include "lualilka_resources.h" #include "lualilka_math.h" #include "lualilka_geometry.h" +#include "lualilka_ws2812.h" +#include "lualilka_sdcard.h" +#include "lualilka_fs.h" +#include "lualilka_wifi.h" +#include "lualilka_http.h" +#include "lualilka_audio.h" +#include "lualilka_mqtt.h" +#include "lualilka_socket.h" +#include "lualilka_state.h" #include "keira/ksound/sound.h" LuaWallpaper::~LuaWallpaper() { @@ -46,6 +56,15 @@ bool LuaWallpaper::open(const char* path, App* app) { lualilka_resources_register(L); lualilka_math_register(L); lualilka_geometry_register(L); + lualilka_ws2812_register(L); + lualilka_sdcard_register(L); + lualilka_fs_register(L); + lualilka_wifi_register(L); + lualilka_http_register(L); + lualilka_audio_register(L); + lualilka_mqtt_register(L); + lualilka_socket_register(L); + lualilka_state_register(L); lua_newtable(L); lua_setfield(L, LUA_REGISTRYINDEX, "images"); @@ -55,6 +74,14 @@ bool LuaWallpaper::open(const char* path, App* app) { lua_newtable(L); lua_setglobal(L, "lilka"); + // State is kept next to the script, same as for Lua apps + String statePath = String(path).substring(0, String(path).lastIndexOf('.')) + ".state"; + lua_pushstring(L, statePath.c_str()); + lua_setfield(L, LUA_REGISTRYINDEX, "state_path"); + if (access(statePath.c_str(), F_OK) != -1) { + lualilka_state_load(L, statePath.c_str()); + } + if (luaL_loadfile(L, path) != LUA_OK || lua_pcall(L, 0, 0, 0) != LUA_OK) { lilka::serial.err("Lua wallpaper: %s", lua_tostring(L, -1)); close(); @@ -75,6 +102,17 @@ bool LuaWallpaper::open(const char* path, App* app) { void LuaWallpaper::close() { if (L == nullptr) return; + // Save state table if the script has one + lua_getglobal(L, "state"); + bool hasState = lua_istable(L, -1); + lua_pop(L, 1); + if (hasState) { + lua_getfield(L, LUA_REGISTRYINDEX, "state_path"); + String statePath = lua_tostring(L, -1); + lua_pop(L, 1); + lualilka_state_save(L, statePath.c_str()); + } + // Free images and sounds loaded by the script lua_getfield(L, LUA_REGISTRYINDEX, "images"); lua_pushnil(L); @@ -84,6 +122,8 @@ void LuaWallpaper::close() { } lua_pop(L, 1); + // Stop audio playback before freeing sounds + lualilka_audio_cleanup(); lua_getfield(L, LUA_REGISTRYINDEX, "sounds"); lua_pushnil(L); while (lua_next(L, -2) != 0) { diff --git a/src/apps/lua/luawallpaper.h b/src/apps/lua/luawallpaper.h index 6829e99a..3652fc9f 100644 --- a/src/apps/lua/luawallpaper.h +++ b/src/apps/lua/luawallpaper.h @@ -5,7 +5,8 @@ // Home screen wallpaper driven by a Lua script. // Script uses the same lilka.init() / lilka.update(delta) / lilka.draw() callbacks as regular Lua apps, -// but only has access to display, resources, math and geometry modules. +// but only has access to display, resources, math, geometry, ws2812, sdcard, fs, wifi, http, audio, mqtt, +// socket and state modules. State is loaded on open and saved on close, same as for Lua apps. // Buttons are not available to the script - they are handled by the launcher. class LuaWallpaper { public: From 7bf396339712e209df244452c762dbe0e3c743a0 Mon Sep 17 00:00:00 2001 From: Yevhen Boichuk Date: Thu, 8 Oct 2026 21:20:05 +0300 Subject: [PATCH 2/2] fix: increase stack for launcher for wallpaper --- src/apps/launcher/launcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/apps/launcher/launcher.cpp b/src/apps/launcher/launcher.cpp index eadedeb7..35052db8 100644 --- a/src/apps/launcher/launcher.cpp +++ b/src/apps/launcher/launcher.cpp @@ -73,7 +73,7 @@ static const char* const WALLPAPER_PATHS[] = {"/sd/wallpaper.gif", "/sd/wallpaper.png", "/sd/wallpaper.jpg", "/sd/wallpaper.jpeg", "/sd/wallpaper.bmp"}; LauncherApp::LauncherApp() : App("Launcher"), autorunEnabled(ScriptService::getAutorunEnabled()) { - setktStackSize(8192); // Yeah, this one is heavy as fuck + setktStackSize(16384); // Heavy run() frame plus Lua wallpaper modules (http, fs, socket) } void LauncherApp::run() {