Fix standalone Lua script screen flicker and improve error messages (#982)

* Relax assumptions about when Lua is called in foreground and background

* Start Lua cycle timer both in foreground and background
Do not assume that background/foreground alternates

* Lua is called at every Standalone GUI cycle instead of 5 Hz
Since Lua preempts every 50 ms or so, the GUI should remain responsive.

* In standalone script, only call Lua once per GUI cycle, to avoid messing up buffer handling.

* Revamped error reporting for Standalone and Telemetry Lua scripts

* Font size for Lua error is reduced from XL to L on color if LCD_W < LCD_H

* In drawTextLines, also possible linebreaks for opening brackets.

* Smaller font for error message on tall color screen

* Make titlebar height match font size on narrow LCD
This commit is contained in:
Jesper Frickmann
2021-11-15 12:57:14 +11:00
committed by GitHub
parent 7298f0ff00
commit f1baa383ae
12 changed files with 175 additions and 208 deletions
+6 -6
View File
@@ -24,17 +24,17 @@
#include <keys.h>
#define MESSAGEBOX_X 10
#define MESSAGEBOX_Y 16
#define MESSAGEBOX_W (LCD_W - 19)
#define MESSAGEBOX_X 8
#define MESSAGEBOX_Y 8
#define MESSAGEBOX_W (LCD_W - 15)
#define MENU_X MESSAGEBOX_X
#define MENU_Y MESSAGEBOX_Y
#define MENU_W MESSAGEBOX_W
#define WARNING_LINE_LEN 20
#define WARNING_LINE_X 16
#define WARNING_LINE_Y 3*FH
#define WARNING_LINE_LEN 24
#define WARNING_LINE_X 12
#define WARNING_LINE_Y MESSAGEBOX_Y + 2
#define POPUP_MENU_MAX_LINES 12
#define MENU_MAX_DISPLAY_LINES 6
+1 -14
View File
@@ -170,18 +170,7 @@ bool displayTelemetryScreen()
{
#if defined(LUA)
if (TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) {
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:
luaError(lsScripts, state, false);
return true;
}
return false;
return isTelemetryScriptAvailable(); // contents will be drawn by Lua Task
}
#endif
@@ -195,7 +184,5 @@ bool displayTelemetryScreen()
return displayCustomTelemetryScreen(s_frsky_view);
}
return true;
}
+3 -3
View File
@@ -23,16 +23,16 @@
#define _POPUPS_H_
#define MESSAGEBOX_X 10
#define MESSAGEBOX_Y 16
#define MESSAGEBOX_Y 8
#define MESSAGEBOX_W LCD_W - (2 * MESSAGEBOX_X)
#define MENU_X 30
#define MENU_Y 16
#define MENU_W LCD_W - (2 * MENU_X)
#define WARNING_LINE_LEN 32
#define WARNING_LINE_LEN 40
#define WARNING_LINE_X 16
#define WARNING_LINE_Y 3*FH
#define WARNING_LINE_Y MESSAGEBOX_Y + 2
#define POPUP_MENU_MAX_LINES 12
#define MENU_MAX_DISPLAY_LINES 6
+1 -12
View File
@@ -172,18 +172,7 @@ bool displayTelemetryScreen()
{
#if defined(LUA)
if (TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) {
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:
luaError(lsScripts, state, false);
return true;
}
return false;
return isTelemetryScriptAvailable(); // contents will be drawn by Lua Task
}
#endif
@@ -517,6 +517,9 @@ void drawTextLines(BitmapBuffer * dc, coord_t left, coord_t top, coord_t width,
case '-':
case '/':
case ':':
case '(':
case '{':
case '[':
nxt++;
case ' ':
case '\n':
+1 -2
View File
@@ -334,8 +334,7 @@ void RadioSdManagerPage::build(FormWindow * window)
std::string fullpath = currentPath + "/" + name;
menu->addLine(STR_EXECUTE_FILE, [=]() {
luaExec(fullpath.c_str());
if (luaState != INTERPRETER_RELOAD_PERMANENT_SCRIPTS)
StandaloneLuaWindow::instance()->attach(window);
StandaloneLuaWindow::instance()->attach(window);
});
}
#endif
+1 -2
View File
@@ -127,8 +127,7 @@ void RadioToolsPage::rebuild(FormWindow * window)
f_chdir(toolPath);
luaExec(path_str.c_str());
if (luaState != INTERPRETER_RELOAD_PERMANENT_SCRIPTS)
StandaloneLuaWindow::instance()->attach(window);
StandaloneLuaWindow::instance()->attach(window);
return 0;
},
+3 -14
View File
@@ -25,8 +25,6 @@
using std::string;
constexpr uint32_t STANDALONE_LUA_REFRESH = 1000 / 50; // 5Hz
void LuaPopup::paint(BitmapBuffer* dc, uint8_t type, const char* text, const char* info)
{
// popup background
@@ -104,22 +102,15 @@ void StandaloneLuaWindow::paint(BitmapBuffer* dc)
void StandaloneLuaWindow::checkEvents()
{
// Execute first in case onEvent() is called.
// (would trigger refresh)
Window::checkEvents();
uint32_t now = RTOS_GET_MS();
if (now - lastRefresh >= STANDALONE_LUA_REFRESH) {
lastRefresh = now;
runLua(0);
}
runLua(event);
event = 0;
}
#if defined(HARDWARE_KEYS)
void StandaloneLuaWindow::onEvent(event_t evt)
{
lastRefresh = RTOS_GET_MS(); // mark as 'refreshed'
runLua(evt);
event = evt;
}
#endif
@@ -162,8 +153,6 @@ void StandaloneLuaWindow::runLua(event_t evt)
TRACE("# StandaloneLuaWindow::invalidate()");
#endif
invalidate();
} else {
// The script was preempted, and the LCD should not be updated yet
}
}
+1 -1
View File
@@ -58,11 +58,11 @@ public:
protected:
// GFX
BitmapBuffer lcdBuffer;
uint32_t lastRefresh = 0;
// pop-ups
LuaPopup popup;
// run LUA code
void runLua(event_t evt);
event_t event = 0;
};
+1 -1
View File
@@ -50,7 +50,7 @@ void drawMessageBoxBackground(coord_t top, coord_t height)
void drawMessageBox(const char * title)
{
// background + border
drawMessageBoxBackground(MESSAGEBOX_Y, 40);
drawMessageBoxBackground(MESSAGEBOX_Y, 48);
// title
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y, title, WARNING_LINE_LEN);