1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 12:25:12 +03:00

[Horus] Lua model scripts added

This commit is contained in:
Bertrand Songis 2015-12-06 22:54:13 +01:00
parent 9d29b483c5
commit 1e2130de53
7 changed files with 49 additions and 43 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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
#endif // #ifndef lua_api_h

View file

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