Skip to content

Commit

Permalink
fix(lua): Do not pass key event that triggered telemetry view to lua (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bug400 authored and pfeerick committed Nov 6, 2023
1 parent 6bc9318 commit 3fd0c35
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/standalone_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions radio/src/lua/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1223,14 +1223,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();

Expand Down
2 changes: 1 addition & 1 deletion radio/src/lua/lua_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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);
Expand Down
22 changes: 15 additions & 7 deletions radio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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;
Expand Down Expand Up @@ -365,7 +369,7 @@ void guiMain(event_t evt)
}

DEBUG_TIMER_START(debugTimerLua);
luaTask(0, false);
luaTask(false);
DEBUG_TIMER_STOP(debugTimerLua);

t0 = get_tmr10ms() - t0;
Expand Down Expand Up @@ -400,13 +404,17 @@ 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
// No foreground Lua script is running - clear the screen show normal menu
{
lcdClear();
menuHandlers[menuLevel](event);
Expand All @@ -430,7 +438,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) {
Expand Down

0 comments on commit 3fd0c35

Please sign in to comment.