2.1.x implementation of displayLuaScriptError()

This commit is contained in:
David S. Beach
2015-09-26 09:00:36 +02:00
committed by Bertrand Songis
parent 436b5003d9
commit e57361f7e1
3 changed files with 55 additions and 1 deletions
+43 -1
View File
@@ -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
+11
View File
@@ -1784,6 +1784,17 @@ bool luaLoadTelemetryScript(uint8_t index)
return true;
}
uint8_t isTelemetryScriptAvailable(uint8_t index)
{
for (int i=0; i<luaScriptsCount; i++) {
ScriptInternalData & sid = scriptInternalData[i];
if (sid.reference == SCRIPT_TELEMETRY_FIRST+index) {
return sid.state;
}
}
return SCRIPT_NOFILE;
}
void luaLoadPermanentScripts()
{
luaScriptsCount = 0;
+1
View File
@@ -98,6 +98,7 @@
void luaExec(const char *filename);
int luaGetMemUsed();
#define luaGetCpuUsed(idx) scriptInternalData[idx].instructions
uint8_t isTelemetryScriptAvailable(uint8_t index);
#define LUA_LOAD_MODEL_SCRIPTS() luaState |= INTERPRETER_RELOAD_PERMANENT_SCRIPTS
#define LUA_LOAD_MODEL_SCRIPT(idx) luaState |= INTERPRETER_RELOAD_PERMANENT_SCRIPTS
#define LUA_STANDALONE_SCRIPT_RUNNING() (luaState == INTERPRETER_RUNNING_STANDALONE_SCRIPT)