1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 20:35:17 +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:
Damjan Adamic 2015-11-26 19:32:28 +01:00
parent cbe244fc6c
commit f184e9bed3
3 changed files with 90 additions and 38 deletions

View file

@ -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;

View file

@ -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;
} }

View file

@ -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
// run Lua scripts that use LCD
bool standaloneScriptWasRun = luaTask(evt, RUN_STNDAL_SCRIPT, true);
if (!standaloneScriptWasRun) {
luaTask(evt, RUN_TELEM_FG_SCRIPT, true);
}
t0 = get_tmr10ms() - t0;
if (t0 > maxLuaDuration) {
maxLuaDuration = t0;
}
#else
lcdRefreshWait(); // WARNING: make sure no code above this line does any change to the LCD display buffer!
const bool standaloneScriptWasRun = false;
#endif
if (!standaloneScriptWasRun) {
lcdClear();
// normal GUI from menus
const char * warn = warningText;
uint8_t menu = popupMenuNoItems;
if (menuEvent) { if (menuEvent) {
menuVerticalPosition = menuEvent == EVT_ENTRY_UP ? menuVerticalPositions[menuLevel] : 0; // we have a popupMenuActive entry or exit event
menuVerticalPosition = (menuEvent == EVT_ENTRY_UP) ? menuVerticalPositions[menuLevel] : 0;
menuHorizontalPosition = 0; menuHorizontalPosition = 0;
evt = menuEvent; evt = menuEvent;
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; menuEvent = 0;
AUDIO_MENUS(); AUDIO_MENUS();
} }
menuHandlers[menuLevel]((warn || menu) ? 0 : evt); if (warningText) {
if (warn) DISPLAY_WARNING(evt); // show warning on top of the normal menus
if (menu) { handleGui(0); // suppress events, they are handled by the warning
DISPLAY_WARNING(evt);
}
else if (popupMenuNoItems > 0) {
// popup menu is active display it on top of normal menus
handleGui(0); // suppress events, they are handled by the popup
if (!inPopupMenu) {
TRACE("Popup Menu started");
inPopupMenu = true;
}
const char * result = displayPopupMenu(evt); const char * result = displayPopupMenu(evt);
if (result) { if (result) {
TRACE("popupMenuHandler(%s)", result);
popupMenuHandler(result); popupMenuHandler(result);
} }
} }
else {
drawStatusLine(); // normal menus
if (inPopupMenu) {
TRACE("Popup Menu ended");
inPopupMenu = false;
}
handleGui(evt);
} }
lcdRefresh(); lcdRefresh();