mirror of
https://github.com/opentx/opentx.git
synced 2025-07-14 20:10:08 +03:00
2.1.x implementation of displayLuaScriptError()
This commit is contained in:
parent
436b5003d9
commit
e57361f7e1
3 changed files with 55 additions and 1 deletions
|
@ -182,11 +182,53 @@ void displayCustomTelemetryScreen(uint8_t index)
|
||||||
displayNumbersTelemetryScreen(screen);
|
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()
|
bool displayTelemetryScreen()
|
||||||
{
|
{
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
if (TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) {
|
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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1784,6 +1784,17 @@ bool luaLoadTelemetryScript(uint8_t index)
|
||||||
return true;
|
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()
|
void luaLoadPermanentScripts()
|
||||||
{
|
{
|
||||||
luaScriptsCount = 0;
|
luaScriptsCount = 0;
|
||||||
|
|
|
@ -98,6 +98,7 @@
|
||||||
void luaExec(const char *filename);
|
void luaExec(const char *filename);
|
||||||
int luaGetMemUsed();
|
int luaGetMemUsed();
|
||||||
#define luaGetCpuUsed(idx) scriptInternalData[idx].instructions
|
#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_SCRIPTS() luaState |= INTERPRETER_RELOAD_PERMANENT_SCRIPTS
|
||||||
#define LUA_LOAD_MODEL_SCRIPT(idx) 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)
|
#define LUA_STANDALONE_SCRIPT_RUNNING() (luaState == INTERPRETER_RUNNING_STANDALONE_SCRIPT)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue