diff --git a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp index a2c9f7742..44b83b27c 100644 --- a/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp +++ b/companion/src/firmwares/opentx/simulator/opentxsimulator.cpp @@ -40,11 +40,11 @@ #define AUTOSWITCH #define GRAPHICS #define CURVES -#if defined(PCBFLAMENCO) || defined(PCBHORUS) -#define RTCLOCK -#define XCURVES -#define VIRTUALINPUTS -#elif defined(PCBTARANIS) +#if defined(PCBFLAMENCO) + #define RTCLOCK + #define XCURVES + #define VIRTUALINPUTS +#elif defined(PCBTARANIS) || defined(PCBHORUS) #define RTCLOCK #define XCURVES #define VIRTUALINPUTS @@ -151,7 +151,7 @@ namespace NAMESPACE { #include "radio/src/gui/Horus/menu_model_curves.cpp" #include "radio/src/gui/Horus/menu_model_logical_switches.cpp" #include "radio/src/gui/Horus/menu_model_custom_functions.cpp" -// #include "radio/src/gui/Horus/menu_model_custom_scripts.cpp" +#include "radio/src/gui/Horus/menu_model_custom_scripts.cpp" #include "radio/src/gui/Horus/menu_model_gvars.cpp" #include "radio/src/gui/Horus/menu_model_limits.cpp" #include "radio/src/gui/Horus/menu_model_telemetry.cpp" diff --git a/radio/src/Makefile b/radio/src/Makefile index ade357f2d..0c251b6ae 100644 --- a/radio/src/Makefile +++ b/radio/src/Makefile @@ -1161,13 +1161,14 @@ ifeq ($(PCB), FLAMENCO) ifneq ($(LUA), NO) ifeq ($(LUA), YES) CPPDEFS += -DLUA_MODEL_SCRIPTS + GUIMODELSRC += gui/$(GUIDIRECTORY)/menu_model_custom_scripts.cpp endif CPPDEFS += -DLUA INCDIRS += $(LUADIR) CPPSRC += lua/interface.cpp lua/api_general.cpp lua/api_lcd.cpp lua/api_model.cpp LUASRC = $(LUADIR)/lapi.c $(LUADIR)/lcode.c $(LUADIR)/lctype.c $(LUADIR)/ldebug.c $(LUADIR)/ldo.c $(LUADIR)/ldump.c $(LUADIR)/lfunc.c $(LUADIR)/lgc.c $(LUADIR)/llex.c $(LUADIR)/lmem.c \ $(LUADIR)/lobject.c $(LUADIR)/lopcodes.c $(LUADIR)/lparser.c $(LUADIR)/lstate.c $(LUADIR)/lstring.c $(LUADIR)/ltable.c $(LUADIR)/lrotable.c $(LUADIR)/ltm.c $(LUADIR)/lundump.c $(LUADIR)/lvm.c $(LUADIR)/lzio.c \ - $(LUADIR)/lbaselib.c $(LUADIR)/linit.c $(LUADIR)/lmathlib.c $(LUADIR)/lbitlib.c $(LUADIR)/loadlib.c $(LUADIR)/lauxlib.c $(LUADIR)/ltablib.c $(LUADIR)/lcorolib.c $(LUADIR)/liolib.c + $(LUADIR)/lbaselib.c $(LUADIR)/linit.c $(LUADIR)/lmathlib.c $(LUADIR)/lbitlib.c $(LUADIR)/loadlib.c $(LUADIR)/lauxlib.c $(LUADIR)/ltablib.c $(LUADIR)/lcorolib.c $(LUADIR)/liolib.c $(LUADIR)/lstrlib.c SRC += $(LUASRC) LUADEP = lua/lua_exports_flamenco.inc endif @@ -1291,13 +1292,14 @@ ifeq ($(PCB), HORUS) ifneq ($(LUA), NO) ifeq ($(LUA), YES) CPPDEFS += -DLUA_MODEL_SCRIPTS + GUIMODELSRC += gui/$(GUIDIRECTORY)/menu_model_custom_scripts.cpp endif CPPDEFS += -DLUA INCDIRS += $(LUADIR) CPPSRC += lua/interface.cpp lua/api_general.cpp lua/api_lcd.cpp lua/api_model.cpp LUASRC = $(LUADIR)/lapi.c $(LUADIR)/lcode.c $(LUADIR)/lctype.c $(LUADIR)/ldebug.c $(LUADIR)/ldo.c $(LUADIR)/ldump.c $(LUADIR)/lfunc.c $(LUADIR)/lgc.c $(LUADIR)/llex.c $(LUADIR)/lmem.c \ $(LUADIR)/lobject.c $(LUADIR)/lopcodes.c $(LUADIR)/lparser.c $(LUADIR)/lstate.c $(LUADIR)/lstring.c $(LUADIR)/ltable.c $(LUADIR)/lrotable.c $(LUADIR)/ltm.c $(LUADIR)/lundump.c $(LUADIR)/lvm.c $(LUADIR)/lzio.c \ - $(LUADIR)/lbaselib.c $(LUADIR)/linit.c $(LUADIR)/lmathlib.c $(LUADIR)/lbitlib.c $(LUADIR)/loadlib.c $(LUADIR)/lauxlib.c $(LUADIR)/ltablib.c $(LUADIR)/lcorolib.c $(LUADIR)/liolib.c + $(LUADIR)/lbaselib.c $(LUADIR)/linit.c $(LUADIR)/lmathlib.c $(LUADIR)/lbitlib.c $(LUADIR)/loadlib.c $(LUADIR)/lauxlib.c $(LUADIR)/ltablib.c $(LUADIR)/lcorolib.c $(LUADIR)/liolib.c $(LUADIR)/lstrlib.c SRC += $(LUASRC) LUADEP = lua/lua_exports_horus.inc endif diff --git a/radio/src/gui/Horus/lcd.cpp b/radio/src/gui/Horus/lcd.cpp index 6c627898f..8d4cc3e31 100644 --- a/radio/src/gui/Horus/lcd.cpp +++ b/radio/src/gui/Horus/lcd.cpp @@ -480,21 +480,17 @@ void putsMixerSource(coord_t x, coord_t y, uint8_t idx, LcdFlags att) } lcdDrawText(x, y, s, att); } - else if (idx <= MIXSRC_LAST_LUA) { +#if defined(LUA_MODEL_SCRIPTS) div_t qr = div(idx-MIXSRC_FIRST_LUA, MAX_SCRIPT_OUTPUTS); -#if defined(LUA_MODEL_SCRIPTS) && !defined(COLORLCD) if (qr.quot < MAX_SCRIPTS && qr.rem < scriptInputsOutputs[qr.quot].outputsCount) { - lcdDrawChar(x+2, y+1, '1'+qr.quot, TINSIZE); - lcdDrawSolidFilledRect(x, y, 7, 7); - lcdDrawSizedText(x+8, y, scriptInputsOutputs[qr.quot].outputs[qr.rem].name, att & STREXPANDED ? 9 : 4, att); + char s[32] = "\322"; + s[1] = '1'+qr.quot; + strncpy(&s[2], scriptInputsOutputs[qr.quot].outputs[qr.rem].name, 32-2); + s[31] = '\0'; + lcdDrawText(x, y, s, att); } - else #endif - { - putsStrIdx(x, y, "LUA", qr.quot+1, att); - lcdDrawChar(x+20, y, 'a'+qr.rem, att); - } } else if (idx <= MIXSRC_LAST_POT) { idx = idx-MIXSRC_Rud; @@ -533,8 +529,9 @@ void putsMixerSource(coord_t x, coord_t y, uint8_t idx, LcdFlags att) else { idx -= MIXSRC_FIRST_TELEM; div_t qr = div(idx, 3); - char s[sizeof(g_model.telemetrySensors[qr.quot].label)+2]; - int pos = zchar2str(s, g_model.telemetrySensors[qr.quot].label, sizeof(g_model.telemetrySensors[qr.quot].label)); + char s[32]; + s[0] = '\321'; + int pos = 1 + zchar2str(&s[1], g_model.telemetrySensors[qr.quot].label, sizeof(g_model.telemetrySensors[qr.quot].label)); if (qr.rem) s[pos++] = (qr.rem==2 ? '+' : '-'); s[pos] = '\0'; lcdDrawText(x, y, s, att); diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 6c329532a..4320cac34 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -609,9 +609,9 @@ TODO table of events/masks static int luaKillEvents(lua_State *L) { uint8_t key = EVT_KEY_MASK(luaL_checkinteger(L, 1)); - // 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) { + // prevent killing maskable keys (only in telemetry scripts) + // TODO add which tpye of script is running before p_call() + if (IS_MASKABLE(key)) { killEvents(key); } return 0; diff --git a/radio/src/lua/api_lcd.cpp b/radio/src/lua/api_lcd.cpp index f7691b330..879d2b5c2 100644 --- a/radio/src/lua/api_lcd.cpp +++ b/radio/src/lua/api_lcd.cpp @@ -40,23 +40,24 @@ #include "lua/lua_api.h" /*luadoc -@function lcd.lock() +@function lcd.refresh() -@status depreciated since 2.1 +Refresh the LCD screen -@notice This function has no effect in OpenTX 2.1 and will be removed in 2.2 +@status current Introduced in 2.2.0 + +@notice This function only works in stand-alone and telemetry scripts. */ -static int luaLcdLock(lua_State *L) +static int luaLcdRefresh(lua_State *L) { - // disabled in opentx 2.1 - // TODO: remove this function completely in opentx 2.2 + if (luaLcdAllowed) lcdRefresh(); return 0; } /*luadoc @function lcd.clear() -Clears the LCD screen +Clear the LCD screen @status current Introduced in 2.0.0 @@ -68,10 +69,11 @@ static int luaLcdClear(lua_State *L) return 0; } + /*luadoc @function lcd.drawPoint(x, y) -Draws a single pixel at (x,y) position +Draw a single pixel at (x,y) position @param x (positive number) x position @@ -95,7 +97,7 @@ static int luaLcdDrawPoint(lua_State *L) /*luadoc @function lcd.drawLine(x1, y1, x2, y2, pattern, flags) -Draws a straight line on LCD +Draw a straight line on LCD @param x1,y1 (positive numbers) starting coordinate @@ -143,7 +145,7 @@ static int luaLcdGetLastPos(lua_State *L) /*luadoc @function lcd.drawText(x, y, text [, flags]) -Draws a text beginning at (x,y) +Draw a text beginning at (x,y) @param x,y (positive numbers) starting coordinate @@ -279,7 +281,7 @@ static int luaLcdDrawChannel(lua_State *L) /*luadoc @function lcd.drawSwitch(x, y, switch, flags) -Draws a text representation of switch at (x,y) +Draw a text representation of switch at (x,y) @param x,y (positive numbers) starting coordinate @@ -329,7 +331,7 @@ static int luaLcdDrawSource(lua_State *L) /*luadoc @function lcd.drawPixmap(x, y, name) -Draws a bitmap at (x,y) +Draw a bitmap at (x,y) @param x,y (positive numbers) starting coordinate @@ -357,7 +359,7 @@ static int luaLcdDrawPixmap(lua_State *L) /*luadoc @function lcd.drawRectangle(x, y, w, h [, flags]) -Draws a rectangle from top left corner (x,y) of specified width and height +Draw a rectangle from top left corner (x,y) of specified width and height @param x,y (positive numbers) top left corner position @@ -384,7 +386,7 @@ static int luaLcdDrawRectangle(lua_State *L) /*luadoc @function lcd.drawFilledRectangle(x, y, w, h [, flags]) -Draws a solid rectangle from top left corner (x,y) of specified width and height +Draw a solid rectangle from top left corner (x,y) of specified width and height @param x,y (positive numbers) top left corner position @@ -412,7 +414,7 @@ static int luaLcdDrawFilledRectangle(lua_State *L) /*luadoc @function lcd.drawGauge(x, y, w, h, fill, maxfill) -Draws a simple gauge that is filled based upon fill value +Draw a simple gauge that is filled based upon fill value @param x,y (positive numbers) top left corner position @@ -449,7 +451,7 @@ static int luaLcdDrawGauge(lua_State *L) /*luadoc @function lcd.drawScreenTitle(title, page, pages) -Draws a title bar +Draw a title bar @param title (string) text for the title @@ -481,7 +483,7 @@ static int luaLcdDrawScreenTitle(lua_State *L) /*luadoc @function lcd.drawCombobox(x, y, w, list, idx [, flags]) -Draws a combo box +Draw a combo box @param x,y (positive numbers) top left corner position @@ -550,7 +552,7 @@ static int luaLcdDrawCombobox(lua_State *L) #endif const luaL_Reg lcdLib[] = { - { "lock", luaLcdLock }, + { "refresh", luaLcdRefresh }, { "clear", luaLcdClear }, { "drawPoint", luaLcdDrawPoint }, { "drawLine", luaLcdDrawLine }, diff --git a/radio/src/lua/lua_api.h b/radio/src/lua/lua_api.h index 9fdc64673..556f2843f 100644 --- a/radio/src/lua/lua_api.h +++ b/radio/src/lua/lua_api.h @@ -144,10 +144,15 @@ extern "C" { extern uint16_t maxLuaInterval; extern uint16_t maxLuaDuration; + #if defined(PCBTARANIS) + #define IS_MASKABLE(key) ((key) != KEY_EXIT && (key) != KEY_ENTER && (key) != KEY_PAGE) + #elif defined(PCBHORUS) + #define IS_MASKABLE(key) ((key) != KEY_EXIT && (key) != KEY_ENTER) + #endif #else // #if defined(LUA) #define LUA_LOAD_MODEL_SCRIPTS() #endif // #if defined(LUA) -#endif // #ifndef lua_api_h \ No newline at end of file +#endif // #ifndef lua_api_h diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index d16550af8..3cde4bdff 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -115,7 +115,7 @@ #define MAX_EXPOS 64 #define NUM_LOGICAL_SWITCH 32 // number of custom switches #define NUM_CFN 64 // number of functions assigned to switches - #define MAX_SCRIPTS 7 + #define MAX_SCRIPTS 9 #define MAX_INPUTS 32 #define NUM_TRAINER 16 #define NUM_POTS 7