From e57361f7e15fd3d61ca40a372d8161ca58914ab5 Mon Sep 17 00:00:00 2001 From: "David S. Beach" Date: Fri, 11 Sep 2015 11:12:10 -0400 Subject: [PATCH] 2.1.x implementation of displayLuaScriptError() --- radio/src/gui/Taranis/view_telemetry.cpp | 44 +++++++++++++++++++++++- radio/src/lua_api.cpp | 11 ++++++ radio/src/lua_api.h | 1 + 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/Taranis/view_telemetry.cpp b/radio/src/gui/Taranis/view_telemetry.cpp index 674f77da2..1b97dc763 100644 --- a/radio/src/gui/Taranis/view_telemetry.cpp +++ b/radio/src/gui/Taranis/view_telemetry.cpp @@ -182,11 +182,53 @@ void displayCustomTelemetryScreen(uint8_t index) displayNumbersTelemetryScreen(screen); } +#if defined(LUA) + +#define LUA_SCRIPT_ERROR_Y 3*FH +// TODO more visual appealing implementation and text translations +void displayLuaScriptError(uint8_t state, int index) +{ + TelemetryScriptData & script = g_model.frsky.screens[index].script; + char filename[sizeof(script.file)+1]; + strncpy(filename, script.file, sizeof(script.file)); + filename[sizeof(script.file)] = '\0'; + + lcd_putsAtt(0, LUA_SCRIPT_ERROR_Y, filename, 0); + lcd_putsAtt(lcdLastPos, LUA_SCRIPT_ERROR_Y, ": ", 0); + switch (state) { + case SCRIPT_SYNTAX_ERROR: + lcd_putsAtt(lcdLastPos, LUA_SCRIPT_ERROR_Y, "Script syntax error", 0); + break; + case SCRIPT_PANIC: + lcd_putsAtt(lcdLastPos, LUA_SCRIPT_ERROR_Y, "Script panic", 0); + break; + case SCRIPT_KILLED: + lcd_putsAtt(lcdLastPos, LUA_SCRIPT_ERROR_Y, "Script killed", 0); + break; + default: + lcd_putsAtt(lcdLastPos, LUA_SCRIPT_ERROR_Y, "Unknown error", 0); + } +} +#endif + bool displayTelemetryScreen() { #if defined(LUA) if (TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) { - return true; + uint8_t state = isTelemetryScriptAvailable(s_frsky_view); + switch (state) { + case SCRIPT_OK: + return true; //contents will be drawed by Lua Task + case SCRIPT_NOFILE: + return false; //requested lua telemetry screen not available + case SCRIPT_SYNTAX_ERROR: + case SCRIPT_PANIC: + case SCRIPT_KILLED: + //display script error + displayLuaScriptError(state, s_frsky_view+1); + return true; + } + return false; } #endif diff --git a/radio/src/lua_api.cpp b/radio/src/lua_api.cpp index 246d69a1d..42710d60a 100644 --- a/radio/src/lua_api.cpp +++ b/radio/src/lua_api.cpp @@ -1784,6 +1784,17 @@ bool luaLoadTelemetryScript(uint8_t index) return true; } +uint8_t isTelemetryScriptAvailable(uint8_t index) +{ + for (int i=0; i