From 49a388661f2e244fe8f0163f2cbf780503922b0c Mon Sep 17 00:00:00 2001 From: bug400 Date: Thu, 5 Oct 2023 14:51:08 +0200 Subject: [PATCH 1/7] fixes #3253 clears LUA key event buffer after switching to telemetry view --- radio/src/lua/interface.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index b6073d970d4..2371a0689e7 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -1027,7 +1027,18 @@ static bool resumeLua(bool init, bool allowLcdUsage) bool scriptWasRun = false; bool fullGC = !allowLcdUsage; static uint8_t luaDisplayStatistics = false; + +#if defined(PCBTARANIS) + static MenuHandlerFunc oldMenuHandler= (MenuHandlerFunc) NULL; + + // clear event buffer after switching to telemetry view + if(menuHandlers[menuLevel]== menuViewTelemetry) { + if(oldMenuHandler!= menuViewTelemetry) luaEmptyEventBuffer(); + } + oldMenuHandler= menuHandlers[menuLevel]; +#endif + // Run in the right interactive mode if (lua_status(lsScripts) == LUA_YIELD && allowLcdUsage != luaLcdAllowed) { #if defined(PCBTARANIS) From bea6625ab001b7a5768e1b0d18ea137cfd88a949 Mon Sep 17 00:00:00 2001 From: bug400 Date: Fri, 20 Oct 2023 16:57:17 +0200 Subject: [PATCH 2/7] Revert "fixes #3253 clears LUA key event buffer after switching to telemetry view" This reverts commit 49a388661f2e244fe8f0163f2cbf780503922b0c. --- radio/src/lua/interface.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index 2371a0689e7..b6073d970d4 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -1027,18 +1027,7 @@ static bool resumeLua(bool init, bool allowLcdUsage) bool scriptWasRun = false; bool fullGC = !allowLcdUsage; static uint8_t luaDisplayStatistics = false; - -#if defined(PCBTARANIS) - static MenuHandlerFunc oldMenuHandler= (MenuHandlerFunc) NULL; - - // clear event buffer after switching to telemetry view - if(menuHandlers[menuLevel]== menuViewTelemetry) { - if(oldMenuHandler!= menuViewTelemetry) luaEmptyEventBuffer(); - } - oldMenuHandler= menuHandlers[menuLevel]; -#endif - // Run in the right interactive mode if (lua_status(lsScripts) == LUA_YIELD && allowLcdUsage != luaLcdAllowed) { #if defined(PCBTARANIS) From f99ad9784584ea44fc567c8a6b3c9508edecd8b5 Mon Sep 17 00:00:00 2001 From: bug400 Date: Fri, 20 Oct 2023 17:27:34 +0200 Subject: [PATCH 3/7] Do not send kbd events to luaTask if neiter telemetry nor standalone script screen are active --- radio/src/main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/radio/src/main.cpp b/radio/src/main.cpp index 625f92e8ddc..9a17928a6ea 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -427,14 +427,19 @@ void guiMain(event_t evt) #elif defined(GUI) bool handleGui(event_t event) { - bool refreshNeeded; + bool refreshNeeded; + #if defined(LUA) - refreshNeeded = luaTask(event, true); +// LUA telemetry foreground script active if (menuHandlers[menuLevel] == menuViewTelemetry && TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) { + refreshNeeded = luaTask(event, true); menuHandlers[menuLevel](event); } - else if (scriptInternalData[0].reference != SCRIPT_STANDALONE) +// standalone foreground script active + else if (scriptInternalData[0].reference == SCRIPT_STANDALONE) + refreshNeeded = luaTask(event, true); + else #endif // No foreground Lua script is running - clear the screen show normal menu { From 2962feb6295d2d4f224cd3343480b7b52e89a6cb Mon Sep 17 00:00:00 2001 From: bug400 Date: Sun, 29 Oct 2023 12:11:14 +0100 Subject: [PATCH 4/7] Revert "Do not send kbd events to luaTask if neiter telemetry nor standalone script screen are active" This reverts commit f99ad9784584ea44fc567c8a6b3c9508edecd8b5. --- radio/src/main.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/radio/src/main.cpp b/radio/src/main.cpp index 9a17928a6ea..625f92e8ddc 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -427,19 +427,14 @@ void guiMain(event_t evt) #elif defined(GUI) bool handleGui(event_t event) { - bool refreshNeeded; - + bool refreshNeeded; #if defined(LUA) -// LUA telemetry foreground script active + refreshNeeded = luaTask(event, true); if (menuHandlers[menuLevel] == menuViewTelemetry && TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) { - refreshNeeded = luaTask(event, true); menuHandlers[menuLevel](event); } -// standalone foreground script active - else if (scriptInternalData[0].reference == SCRIPT_STANDALONE) - refreshNeeded = luaTask(event, true); - else + else if (scriptInternalData[0].reference != SCRIPT_STANDALONE) #endif // No foreground Lua script is running - clear the screen show normal menu { From 952f8516d7abde0d4f4c8d14641f1448117aca60 Mon Sep 17 00:00:00 2001 From: bug400 Date: Sun, 29 Oct 2023 13:04:09 +0100 Subject: [PATCH 5/7] Push key event to LUA event buffer only if telemetry or standalone script screens are active --- radio/src/lua/interface.cpp | 5 +---- radio/src/lua/lua_api.h | 2 +- radio/src/main.cpp | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index b6073d970d4..7fa68db68d0 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -1255,14 +1255,11 @@ static bool resumeLua(bool init, bool allowLcdUsage) } //resumeLua(...) -bool luaTask(event_t evt, bool allowLcdUsage) +bool luaTask(bool allowLcdUsage) { bool init = false; bool scriptWasRun = false; - // Add event to buffer - if (evt != 0) { luaPushEvent(evt); } - // For preemption luaCycleStart = get_tmr10ms(); diff --git a/radio/src/lua/lua_api.h b/radio/src/lua/lua_api.h index a80afede465..6cc3a21e404 100644 --- a/radio/src/lua/lua_api.h +++ b/radio/src/lua/lua_api.h @@ -189,7 +189,7 @@ extern ScriptInternalData scriptInternalData[MAX_SCRIPTS]; extern ScriptInputsOutputs scriptInputsOutputs[MAX_SCRIPTS]; void luaClose(lua_State ** L); -bool luaTask(event_t evt, bool allowLcdUsage); +bool luaTask(bool allowLcdUsage); void checkLuaMemoryUsage(); void luaExec(const char * filename); void luaDoGc(lua_State * L, bool full); diff --git a/radio/src/main.cpp b/radio/src/main.cpp index 625f92e8ddc..c2870e9fa7b 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -34,6 +34,10 @@ #include "cli.h" #endif +#if defined(LUA) + #include "lua/lua_event.h" +#endif + uint8_t currentSpeakerVolume = 255; uint8_t requiredSpeakerVolume = 255; uint8_t currentBacklightBright = 0; @@ -394,7 +398,7 @@ void guiMain(event_t evt) } DEBUG_TIMER_START(debugTimerLua); - luaTask(0, false); + luaTask(false); DEBUG_TIMER_STOP(debugTimerLua); t0 = get_tmr10ms() - t0; @@ -429,11 +433,14 @@ void guiMain(event_t evt) bool handleGui(event_t event) { bool refreshNeeded; #if defined(LUA) - refreshNeeded = luaTask(event, true); - if (menuHandlers[menuLevel] == menuViewTelemetry && - TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) { - menuHandlers[menuLevel](event); - } + bool isTelemView = menuHandlers[menuLevel] == menuViewTelemetry && + TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT; + bool isStandalone = scriptInternalData[0].reference == SCRIPT_STANDALONE; + if (isTelemView || isStandalone) + luaPushEvent(event); + refreshNeeded = luaTask(true); + if (isTelemView) + menuHandlers[menuLevel](event); else if (scriptInternalData[0].reference != SCRIPT_STANDALONE) #endif // No foreground Lua script is running - clear the screen show normal menu @@ -460,7 +467,7 @@ void guiMain(event_t evt) } // run Lua scripts that don't use LCD (to use CPU time while LCD DMA is running) - luaTask(0, false); + luaTask(false); t0 = get_tmr10ms() - t0; if (t0 > maxLuaDuration) { From 59c698c31b26b07de1dd3da30385d6d33b11c848 Mon Sep 17 00:00:00 2001 From: bug400 Date: Sun, 29 Oct 2023 16:04:35 +0100 Subject: [PATCH 6/7] fix call of luaTask for color lcd radios --- radio/src/gui/colorlcd/standalone_lua.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/gui/colorlcd/standalone_lua.cpp b/radio/src/gui/colorlcd/standalone_lua.cpp index 5d54816a782..2be86944bcb 100644 --- a/radio/src/gui/colorlcd/standalone_lua.cpp +++ b/radio/src/gui/colorlcd/standalone_lua.cpp @@ -126,7 +126,7 @@ void StandaloneLuaWindow::checkEvents() if (luaState != INTERPRETER_RELOAD_PERMANENT_SCRIPTS) { // if LUA finished a full cycle, // invalidate to display the screen buffer - if (luaTask(0, true)) { invalidate(); } + if (luaTask(true)) { invalidate(); } } if (luaState == INTERPRETER_RELOAD_PERMANENT_SCRIPTS) { From bd38e770c3a719284f516c2f8c3681f257129df2 Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Mon, 6 Nov 2023 10:17:19 +1000 Subject: [PATCH 7/7] chore: Formatting --- radio/src/main.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/radio/src/main.cpp b/radio/src/main.cpp index c2870e9fa7b..d15fcee93a1 100644 --- a/radio/src/main.cpp +++ b/radio/src/main.cpp @@ -433,17 +433,17 @@ void guiMain(event_t evt) bool handleGui(event_t event) { bool refreshNeeded; #if defined(LUA) - bool isTelemView = menuHandlers[menuLevel] == menuViewTelemetry && - TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT; + bool isTelemView = + menuHandlers[menuLevel] == menuViewTelemetry && + TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT; bool isStandalone = scriptInternalData[0].reference == SCRIPT_STANDALONE; - if (isTelemView || isStandalone) - luaPushEvent(event); + if (isTelemView || isStandalone) luaPushEvent(event); refreshNeeded = luaTask(true); if (isTelemView) menuHandlers[menuLevel](event); else if (scriptInternalData[0].reference != SCRIPT_STANDALONE) #endif -// No foreground Lua script is running - clear the screen show normal menu + // No foreground Lua script is running - clear the screen show normal menu { lcdClear(); menuHandlers[menuLevel](event);