diff --git a/assets/epaper.lua b/assets/epaper.lua new file mode 100644 index 0000000..4bcb9dd --- /dev/null +++ b/assets/epaper.lua @@ -0,0 +1,6 @@ +local paper = require('paper') +paper.init() +print( + 'width: ' .. paper.get_width(), + 'height: ' .. paper.get_height() +) diff --git a/main/inkpot.c b/main/inkpot.c index 02890c5..f476218 100644 --- a/main/inkpot.c +++ b/main/inkpot.c @@ -72,6 +72,11 @@ void run_lua_file(const char *file_name, const char *test_name) { log_memory_usage("After luaL_openlibs"); + // load `paper` library and expose it globally + luaL_requiref(L, "paper", luaopen_paper, 1); + lua_pop(L, 1); + log_memory_usage("After adding paper"); + // Construct the full file path char full_path[128]; snprintf(full_path, sizeof(full_path), LUA_FILE_PATH"/%s", file_name); @@ -106,8 +111,10 @@ void run_embedded_lua_test(const char *lua_script, const char *test_name) { luaL_openlibs(L); log_memory_usage("After luaL_openlibs"); - luaopen_paper(L); - log_memory_usage("After luaopen_paper"); + // load `paper` library and expose it globally + luaL_requiref(L, "paper", luaopen_paper, 1); + lua_pop(L, 1); + log_memory_usage("After adding paper"); if (luaL_dostring(L, lua_script) == LUA_OK) { lua_pop(L, lua_gettop(L)); @@ -224,24 +231,12 @@ void app_main(void) { epd_hl_update_screen(&hl, MODE_GC16, temperature); epd_poweroff(); */ + // Initialize and mount the filesystem init_filesystem(); - // Test 1: Simple embedded Lua script - const char *simple_script = "answer = 42; print('The answer is: '..answer)"; - run_embedded_lua_test(simple_script, "Simple Embedded Script"); - - //const char *paper_script = "local paper = require('paper'); paper.init(); print('width: '..paper.get_width(), 'height: '..paper.get_height())"; - //run_embedded_lua_test(paper_script, "Paper Script"); - - // Test 2: Run Lua script from a file (e.g., fibonacci.lua) - run_lua_file("fibonacci.lua", "Fibonacci Script from File"); - - // Test 3: Run Lua script to generate QR code (e.g., qr_code.lua) - run_lua_file("qr_code.lua", "QR Code Script from File"); - - // Perform Wi-Fi scan - // scan_wifi_networks(); + // Run script in assets/epaper.lua + run_lua_file("epaper.lua", "E-Paper Script"); ESP_LOGI(TAG, "End of testing application.");