From 483ba4ea02fb61d15211a1978669a14258cb8a16 Mon Sep 17 00:00:00 2001 From: philmoz Date: Wed, 27 Sep 2023 14:50:39 +1000 Subject: [PATCH] Disable all model Special Functions when the feature is turned off. Fix issue where GF that runs a Lua script is not disabled when GF feature is turned off. --- radio/src/lua/interface.cpp | 10 ++++++++-- radio/src/mixer.cpp | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/radio/src/lua/interface.cpp b/radio/src/lua/interface.cpp index 07028156eff..aee0aee505d 100644 --- a/radio/src/lua/interface.cpp +++ b/radio/src/lua/interface.cpp @@ -631,8 +631,12 @@ static bool luaLoadFunctionScript(uint8_t ref) CustomFunctionData * fn; if (ref <= SCRIPT_FUNC_LAST) { - idx = ref - SCRIPT_FUNC_FIRST; - fn = &g_model.customFn[idx]; + if (modelSFEnabled()) { + idx = ref - SCRIPT_FUNC_FIRST; + fn = &g_model.customFn[idx]; + } else { + return false; + } } else if (radioGFEnabled()) { idx = ref - SCRIPT_GFUNC_FIRST; @@ -1101,10 +1105,12 @@ static bool resumeLua(bool init, bool allowLcdUsage) CustomFunctionsContext * functionsContext; if (ref <= SCRIPT_FUNC_LAST) { + if (!modelSFEnabled()) continue; idx = ref - SCRIPT_FUNC_FIRST; fn = &g_model.customFn[idx]; functionsContext = &modelFunctionsContext; } else { + if (!radioGFEnabled()) continue; idx = ref - SCRIPT_GFUNC_FIRST; fn = &g_eeGeneral.customFn[idx]; functionsContext = &globalFunctionsContext; diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index 2cb608e86b6..95446962f43 100644 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -1079,7 +1079,11 @@ void evalMixes(uint8_t tick10ms) } else { globalFunctionsContext.reset(); } - evalFunctions(g_model.customFn, modelFunctionsContext); + if (modelSFEnabled()) { + evalFunctions(g_model.customFn, modelFunctionsContext); + } else { + modelFunctionsContext.reset(); + } } //========== LIMITS ===============