mirror of
https://github.com/opentx/opentx.git
synced 2025-07-15 12:25:12 +03:00
Re #2469: part2: keys accesible to Lua telemetry scripts (Taranis only) (ported #3087 from master commits 3186a5d99..94d8b8b0e8d)
This commit is contained in:
parent
cbe244fc6c
commit
f184e9bed3
3 changed files with 90 additions and 38 deletions
|
@ -230,6 +230,7 @@ void menuTelemetryFrsky(uint8_t event)
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVT_KEY_FIRST(KEY_EXIT):
|
case EVT_KEY_FIRST(KEY_EXIT):
|
||||||
|
case EVT_KEY_LONG(KEY_EXIT):
|
||||||
killEvents(event);
|
killEvents(event);
|
||||||
chainMenu(menuMainView);
|
chainMenu(menuMainView);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -541,8 +541,12 @@ TODO table of events/masks
|
||||||
*/
|
*/
|
||||||
static int luaKillEvents(lua_State *L)
|
static int luaKillEvents(lua_State *L)
|
||||||
{
|
{
|
||||||
int event = luaL_checkinteger(L, 1);
|
uint8_t key = EVT_KEY_MASK(luaL_checkinteger(L, 1));
|
||||||
killEvents(event);
|
// prevent killing PAGE, ENT and EXIT (only in telemetry scripts)
|
||||||
|
// todo add which tpye of script is running before p_call()
|
||||||
|
if (key != KEY_EXIT && key != KEY_ENTER && key != KEY_PAGE) {
|
||||||
|
killEvents(key);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -212,9 +212,45 @@ void guiMain(evt_t evt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined(GUI)
|
#elif defined(GUI)
|
||||||
|
|
||||||
|
void handleGui(uint8_t event) {
|
||||||
|
// if Lua standalone, run it and don't clear the screen (Lua will do it)
|
||||||
|
// else if Lua telemetry view, run it and don't clear the screen
|
||||||
|
// else clear scren and show normal menus
|
||||||
|
#if defined(LUA)
|
||||||
|
if (luaTask(event, RUN_STNDAL_SCRIPT, true)) {
|
||||||
|
// standalone script is active
|
||||||
|
}
|
||||||
|
else if (luaTask(event, RUN_TELEM_FG_SCRIPT, true)) {
|
||||||
|
// the telemetry screen is active
|
||||||
|
// prevent events from keys MENU, UP, DOWN, ENT(short) and EXIT(short) from reaching the normal menus,
|
||||||
|
// so Lua telemetry script can fully use them
|
||||||
|
if (event) {
|
||||||
|
uint8_t key = EVT_KEY_MASK(event);
|
||||||
|
// no need to filter out MENU and ENT(short), because they are not used by menuTelemetryFrsky()
|
||||||
|
if (key == KEY_PLUS || key == KEY_MINUS || (!IS_KEY_LONG(event) && key == KEY_EXIT)) {
|
||||||
|
// TRACE("Telemetry script event 0x%02x killed", event);
|
||||||
|
event = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
menuHandlers[menuLevel](event);
|
||||||
|
// todo drawStatusLine(); here???
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
lcdClear();
|
||||||
|
menuHandlers[menuLevel](event);
|
||||||
|
drawStatusLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool inPopupMenu = false;
|
||||||
|
|
||||||
void guiMain(evt_t evt)
|
void guiMain(evt_t evt)
|
||||||
{
|
{
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
|
// TODO better lua stopwatch
|
||||||
uint32_t t0 = get_tmr10ms();
|
uint32_t t0 = get_tmr10ms();
|
||||||
static uint32_t lastLuaTime = 0;
|
static uint32_t lastLuaTime = 0;
|
||||||
uint16_t interval = (lastLuaTime == 0 ? 0 : (t0 - lastLuaTime));
|
uint16_t interval = (lastLuaTime == 0 ? 0 : (t0 - lastLuaTime));
|
||||||
|
@ -226,6 +262,12 @@ void guiMain(evt_t evt)
|
||||||
// run Lua scripts that don't use LCD (to use CPU time while LCD DMA is running)
|
// run Lua scripts that don't use LCD (to use CPU time while LCD DMA is running)
|
||||||
luaTask(0, RUN_MIX_SCRIPT | RUN_FUNC_SCRIPT | RUN_TELEM_BG_SCRIPT, false);
|
luaTask(0, RUN_MIX_SCRIPT | RUN_FUNC_SCRIPT | RUN_TELEM_BG_SCRIPT, false);
|
||||||
|
|
||||||
|
t0 = get_tmr10ms() - t0;
|
||||||
|
if (t0 > maxLuaDuration) {
|
||||||
|
maxLuaDuration = t0;
|
||||||
|
}
|
||||||
|
#endif //#if defined(LUA)
|
||||||
|
|
||||||
// wait for LCD DMA to finish before continuing, because code from this point
|
// wait for LCD DMA to finish before continuing, because code from this point
|
||||||
// is allowed to change the contents of LCD buffer
|
// is allowed to change the contents of LCD buffer
|
||||||
//
|
//
|
||||||
|
@ -233,47 +275,52 @@ void guiMain(evt_t evt)
|
||||||
//
|
//
|
||||||
lcdRefreshWait();
|
lcdRefreshWait();
|
||||||
|
|
||||||
// draw LCD from menus or from Lua script
|
if (menuEvent) {
|
||||||
// run Lua scripts that use LCD
|
// we have a popupMenuActive entry or exit event
|
||||||
|
menuVerticalPosition = (menuEvent == EVT_ENTRY_UP) ? menuVerticalPositions[menuLevel] : 0;
|
||||||
bool standaloneScriptWasRun = luaTask(evt, RUN_STNDAL_SCRIPT, true);
|
menuHorizontalPosition = 0;
|
||||||
if (!standaloneScriptWasRun) {
|
evt = menuEvent;
|
||||||
luaTask(evt, RUN_TELEM_FG_SCRIPT, true);
|
if (menuEvent == EVT_ENTRY_UP) {
|
||||||
|
TRACE("menuEvent EVT_ENTRY_UP");
|
||||||
|
}
|
||||||
|
// else if (menuEvent == EVT_MENU_UP) {
|
||||||
|
// TRACE("menuEvent EVT_MENU_UP");
|
||||||
|
// }
|
||||||
|
else if (menuEvent == EVT_ENTRY) {
|
||||||
|
TRACE("menuEvent EVT_ENTRY");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
TRACE("menuEvent 0x%02x", menuEvent);
|
||||||
|
}
|
||||||
|
menuEvent = 0;
|
||||||
|
AUDIO_MENUS();
|
||||||
}
|
}
|
||||||
|
|
||||||
t0 = get_tmr10ms() - t0;
|
if (warningText) {
|
||||||
if (t0 > maxLuaDuration) {
|
// show warning on top of the normal menus
|
||||||
maxLuaDuration = t0;
|
handleGui(0); // suppress events, they are handled by the warning
|
||||||
|
DISPLAY_WARNING(evt);
|
||||||
}
|
}
|
||||||
#else
|
else if (popupMenuNoItems > 0) {
|
||||||
lcdRefreshWait(); // WARNING: make sure no code above this line does any change to the LCD display buffer!
|
// popup menu is active display it on top of normal menus
|
||||||
const bool standaloneScriptWasRun = false;
|
handleGui(0); // suppress events, they are handled by the popup
|
||||||
#endif
|
if (!inPopupMenu) {
|
||||||
|
TRACE("Popup Menu started");
|
||||||
if (!standaloneScriptWasRun) {
|
inPopupMenu = true;
|
||||||
lcdClear();
|
|
||||||
|
|
||||||
// normal GUI from menus
|
|
||||||
const char * warn = warningText;
|
|
||||||
uint8_t menu = popupMenuNoItems;
|
|
||||||
if (menuEvent) {
|
|
||||||
menuVerticalPosition = menuEvent == EVT_ENTRY_UP ? menuVerticalPositions[menuLevel] : 0;
|
|
||||||
menuHorizontalPosition = 0;
|
|
||||||
evt = menuEvent;
|
|
||||||
menuEvent = 0;
|
|
||||||
AUDIO_MENUS();
|
|
||||||
}
|
}
|
||||||
|
const char * result = displayPopupMenu(evt);
|
||||||
menuHandlers[menuLevel]((warn || menu) ? 0 : evt);
|
if (result) {
|
||||||
if (warn) DISPLAY_WARNING(evt);
|
TRACE("popupMenuHandler(%s)", result);
|
||||||
if (menu) {
|
popupMenuHandler(result);
|
||||||
const char * result = displayPopupMenu(evt);
|
|
||||||
if (result) {
|
|
||||||
popupMenuHandler(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
drawStatusLine();
|
else {
|
||||||
|
// normal menus
|
||||||
|
if (inPopupMenu) {
|
||||||
|
TRACE("Popup Menu ended");
|
||||||
|
inPopupMenu = false;
|
||||||
|
}
|
||||||
|
handleGui(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
lcdRefresh();
|
lcdRefresh();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue