Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This section describes the Lua libraries, functions and constants that are provided by EdgeTX.
On radios with color display, a color may be added to the flags described above.
There are two types of color constants: one that is an index into a table holding a palette of theme colors, and one that is just a color.
These are the theme colors plus CUSTOM_COLOR, and they can be changed with the function lcd.setColor(color_index, color). Please note: if an indexed color is changed, then it changes everywhere that it is used. For the theme colors, this is not only in other widgets, but everywhere throughout the radio's user interface!
COLOR_THEME_PRIMARY1
COLOR_THEME_PRIMARY2
COLOR_THEME_PRIMARY3
COLOR_THEME_SECONDARY1
COLOR_THEME_SECONDARY2
COLOR_THEME_SECONDARY3
COLOR_THEME_FOCUS
COLOR_THEME_EDIT
COLOR_THEME_ACTIVE
COLOR_THEME_WARNING
COLOR_THEME_DISABLED
CUSTOM_COLOR
These color constants cannot be changed:
BLACK
WHITE
LIGHTWHITE
YELLOW
BLUE
DARKBLUE
GREY
DARKGREY
LIGHTGREY
RED
DARKRED
GREEN
DARKGREEN
LIGHTBROWN
DARKBROWN
BRIGHTGREEN
ORANGE
These should no longer be used, but they are included for backwards compatibility. The old OpenTX API had a large number of indexed theme colors, and these have been mapped to the new theme colors as follows:
ALARM_COLOR -> COLOR_THEME_WARNING
BARGRAPH_BGCOLOR -> COLOR_THEME_SECONDARY3
BARGRAPH1_COLOR -> COLOR_THEME_SECONDARY1
BARGRAPH2_COLOR -> COLOR_THEME_SECONDARY2
CURVE_AXIS_COLOR -> COLOR_THEME_SECONDARY2
CURVE_COLOR -> COLOR_THEME_SECONDARY1
CURVE_CURSOR_COLOR -> COLOR_THEME_WARNING
HEADER_BGCOLOR -> COLOR_THEME_FOCUS
HEADER_COLOR -> COLOR_THEME_SECONDARY1
HEADER_CURRENT_BGCOLOR -> COLOR_THEME_FOCUS
HEADER_ICON_BGCOLOR -> COLOR_THEME_SECONDARY1
LINE_COLOR -> COLOR_THEME_PRIMARY3
MAINVIEW_GRAPHICS_COLOR -> COLOR_THEME_SECONDARY1
MAINVIEW_PANES_COLOR -> COLOR_THEME_PRIMARY2
MENU_TITLE_BGCOLOR -> COLOR_THEME_SECONDARY1
MENU_TITLE_COLOR -> COLOR_THEME_PRIMARY2
MENU_TITLE_DISABLE_COLOR -> COLOR_THEME_PRIMARY3
OVERLAY_COLOR -> COLOR_THEME_PRIMARY1
SCROLLBOX_COLOR -> COLOR_THEME_SECONDARY3
TEXT_BGCOLOR -> COLOR_THEME_SECONDARY3
TEXT_COLOR -> COLOR_THEME_SECONDARY1
TEXT_DISABLE_COLOR -> COLOR_THEME_DISABLED
TEXT_INVERTED_BGCOLOR -> COLOR_THEME_FOCUS
TEXT_INVERTED_COLOR -> COLOR_THEME_PRIMARY2
TITLE_BGCOLOR -> COLOR_THEME_SECONDARY1
TRIM_BGCOLOR -> COLOR_THEME_FOCUS
TRIM_SHADOW_COLOR -> COLOR_THEME_PRIMARY1
WARNING_COLOR -> COLOR_THEME_WARNING
The radio's special characters can be used with the following text constants.
CHAR_RIGHT
CHAR_LEFT
CHAR_UP
CHAR_DOWN
CHAR_DELTA
CHAR_STICK
CHAR_POT
CHAR_SLIDER
CHAR_SWITCH
CHAR_TRIM
CHAR_INPUT
CHAR_FUNCTION
CHAR_CYC
CHAR_TRAINER
CHAR_CHANNEL
CHAR_TELEMETRY
CHAR_LUA
These constants determine the type of a Special Function
FUNC_OVERRIDE_CHANNEL
FUNC_TRAINER
FUNC_INSTANT_TRIM
FUNC_RESET
FUNC_SET_TIMER
FUNC_ADJUST_GVAR
FUNC_VOLUME
FUNC_SET_FAILSAFE
FUNC_RANGECHECK
FUNC_BIND
FUNC_PLAY_SOUND
FUNC_PLAY_TRACK
FUNC_PLAY_VALUE
FUNC_PLAY_SCRIPT
FUNC_RESERVE5
FUNC_BACKGND_MUSIC
FUNC_BACKGND_MUSIC_PAUSE
FUNC_VARIO
FUNC_HAPTIC
FUNC_LOGS
FUNC_BACKLIGHT
FUNC_SCREENSHOT
FUNC_RACING_MODE
FUNC_DISABLE_TOUCH
In addition to the key events described in the previous section, radios with a color touch screen also provide touch events to the widget scripts.
The following touch events are passed in the event
argument to the widget script refresh
function (when in full screen mode), just like the key events. The following touch events are provided:
Touch Event Name | Description |
---|---|
In addition to the above touch events a touchState
table is passed to refresh
with the following addional data fields:
touchState fields | Description |
---|---|
touchState
is nil
if event
is not a touch event. This can be used to test if we have a touch event or a key event.
Since Lua evaluates a nil
value to false
and everything else to true
:
if touchState then
we have a touch event.
x, y
are present for all touch events.
startX, startY, slideX, slideY
are only present with EVT_TOUCH_SLIDE
.
swipeUp
/ swipeDown
/ swipeLeft
/ swipeRight
may be present only withEVT_TOUCH_SLIDE
.
tapCount
is zero for anything but EVT_TOUCH_TAP
.
There are several option types that can be specified in the widget options table, which are exposed to the user via the Widget Settings menu. For example:
Type | Description |
---|---|
This section describes various constants that are provided for Lua by EdgeTX.
Name | Description |
---|
EVT_TOUCH_FIRST
When the finger touches down on the screen
EVT_TOUCH_TAP
If the finger leaves the screen after a quick tap
EVT_TOUCH_BREAK
If the finger leaves the screen without tap or slide
EVT_TOUCH_SLIDE
Repeats while the finger is sliding on the screen
x, y
Current touch point
startX, startY
Point where slide started
slideX, SlideY
Movement since previous SLIDE event (or start of slide)
swipeUp / swipeDown / swipeLeft / swipeRight
The field is present and equal to true
if a swipe event occurred in that direction
tapCount
Counts the number of consecutive taps
COLOR
Displays a color picker, returns a color flag value
BOOL
Displays a toggle/checkbox, value toggles between 0 and 1
STRING
Text input option, limited to 8 characters
TIMER
Choice option, lets you pick from available timers
SOURCE
Choice option, lets you pick from available sources (i.e. sticks, switches, LS)
VALUE
Numerical input option, can specify default, min and max value
TEXT_SIZE
Choice option, lets you pick from the available text sizes (i.e. small, large)
ALIGNMENT
Choice option, lets you pick from available alignment options (i.e. left, center, right)
0 | normal font, default precision for numeric |
XXLSIZE | jumbo font | 2.0.6 |
DBLSIZE | double size font |
MIDSIZE | mid sized font |
SMLSIZE | small font |
BOLD | bold font | Only color displays. This is a font size on its own - cannot be combined with other font size flags. |
SHADOWED | shadow font | Only color displays |
INVERS | inverted display |
BLINK | blinking text |
LEFT | left justify | 2.0.6 | Default for most functions not related to bitmaps |
RIGHT | right justify |
CENTER | center justify | Only color displays |
VCENTER | center vertically | 2.5.0 | Only color displays |
PREC1 | single decimal place |
PREC2 | two decimal places |
GREY_DEFAULT | grey fill |
TIMEHOUR | display hours | Only for drawTimer |
FORCE | pixels will be black |
ERASE | pixels will be white |
DOTTED | lines will appear dotted |
These constants give the type of logical switch function.
LS_FUNC_NONE
LS_FUNC_VEQUAL
LS_FUNC_VALMOSTEQUAL
LS_FUNC_VPOS
LS_FUNC_VNEG
LS_FUNC_RANGE
LS_FUNC_APOS
LS_FUNC_ANEG
LS_FUNC_AND
LS_FUNC_OR
LS_FUNC_XOR
LS_FUNC_EDGE
LS_FUNC_EQUAL
LS_FUNC_GREATER
LS_FUNC_LESS
LS_FUNC_DIFFEGREATER
LS_FUNC_ADIFFEGREATER
LS_FUNC_TIMER
LS_FUNC_STICKY
This functions allows for sending SPORT / ACCESS telemetry data toward the receiver, and more generally, to anything connected SPORT bus on the receiver or transmitter.
When called without parameters, it will only return the status of the output buffer without sending anything.
@status current Introduced in 2.3
module
module index (0 = internal, 1 = external)
rxUid
receiver index
sensorId
physical sensor ID
frameId
frame ID
dataId
data ID
value
value
boolean
data queued in output buffer or not.
This functions allows for sending telemetry data toward the TBS Crossfire link.
When called without parameters, it will only return the status of the output buffer without sending anything.
@status current Introduced in 2.2.0, retval nil added in 2.3.4
command
command
data
table of data bytes
boolean
data queued in output buffer or not.
nil
incorrect telemetry protocol.
Return current system date and time that is kept by the RTC unit
none
table
current date and time, table elements:
year
(number) year
mon
(number) month
day
(number) day of month
hour
(number) hours
hour12
(number) hours in US format
min
(number) minutes
sec
(number) seconds
suffix
(text) am or pm
Flushes audio queue
@status experimental, Introduced in 2.8.0
Parameters
none
Return value
none
This page describes the value that is passed to scripts in the event parameter. It is used in Telemetry and One-Time scripts, as well as widget scripts in full screen mode.
Each time a key is pressed, held and released a number of events get generated. Here is a typical flow:
when a key is pressed a FIRST
event is generated
if the key continues to be pressed, then after a while a LONG
event is generated
if the key continues to be pressed, then a REPEAT
events are being generated
when the key is released a BREAK
event is generated
Couple of examples:
a short press on key would generate: FIRST
, BREAK
a longer pres on key would generate: FIRST
, LONG
, BREAK
even longer press: FIRST
, LONG
, REPEAT,
REPEAT, ..., BREAK
This normal key event sequence can be altered with the killEvents(key) function. Any time this function is called (after the FIRST
event) all further key events for this key will be suppressed until the next key press of this key. Examples:
kill immediately after the key press would generate: FIRST
kill after the long key press would generate: FIRST
, LONG
The event
parameter in the Telemetry and One-Time scripts run function actually carries two pieces of information:
key number
type of event
The two fields are combined into one single number. Some of these combinations are defined as constants and are available to Lua scripts:
Radios with rotary encoder (X7 and Horus) have also:
Given the large number of radios supported by OpenTX, and the large difference in keys available on those, a set of VIRTUAL KEYS has been defined and are mapped to best fit available hardware
Name | Description |
---|---|
Return detailed information about field (source)
The list of valid sources is available:
OpenTX Version | Radio |
---|
@status current Introduced in 2.0.8, 'unit' field added in 2.2.0
source
can be an identifier (number) or a name (string) of the source.
table
information about requested field, table elements:
id
(number) field identifier
name
(string) field name
desc
(string) field description
'unit' (number) unit identifier
nil
the requested field was not found
Key Event Name | Comments |
---|---|
Key Event Name | Comments |
---|---|
Virtual Key Event Name | Comments |
---|---|
LCD_W
width in pixels
LCD_H
height in pixels
EVT_MENU_BREAK
MENU key release
EVT_PAGE_BREAK
PAGE key release
EVT_PAGE_LONG
MENU key long press
EVT_ENTER_BREAK
ENT key release
EVT_ENTER_LONG
ENT key long press
EVT_EXIT_BREAK
EXIT key release
EVT_PLUS_BREAK
+ key release
EVT_MINUS_BREAK
- key release
EVT_PLUS_FIRST
+ key press
EVT_MINUS_FIRST
- key press
EVT_PLUS_REPT
+ key repeat
EVT_MINUS_REPT
- key repeat
EVT_ROT_BREAK
rotary encoder release
EVT_ROT_LONG
rotary encoder long press
EVT_ROT_LEFT
rotary encoder rotated left
EVT_ROT_RIGHT
rotary encoder rotated right
EVT_VIRTUAL_NEXT_PAGE
for PAGE navigation
EVT_VIRTUAL_PREV_PAGE
for PAGE navigation
EVT_VIRTUAL_ENTER
EVT_VIRTUAL_ENTER_LONG
EVT_VIRTUAL_MENU
EVT_VIRTUAL_MENU_LONG
EVT_VIRTUAL_NEXT
for FIELDS navigation
EVT_VIRTUAL_NEXT_REPT
for FIELDS navigation
EVT_VIRTUAL_PREV
for FIELDS navigation
EVT_VIRTUAL_PREV_REPT
for FIELDS navigation
EVT_VIRTUAL_INC
for VALUES navigation
EVT_VIRTUAL_INC_REPT
for VALUES navigation
EVT_VIRTUAL_DEC
for VALUES navigation
EVT_VIRTUAL_DEC_REPT
for VALUES navigation
Return flight mode data.
@status current Introduced in 2.1.7
mode
(number) flight mode number to return (0 - 8). If mode parameter
is not specified (or contains invalid value), then the current flight mode data is returned.
multiple
returns 2 values:
(number) (current) flight mode number (0 - 8)
(string) (current) flight mode name
Return the RAS value or nil if no valid hardware found
@status current Introduced in 2.2.0
none
number
representing RAS value. Value bellow 0x33 (51 decimal) are all ok, value above 0x33 indicate a hardware antenna issue.
This is just a hardware pass/fail measure and does not represent the quality of the radio link
RAS was called SWR in the past
@status current Introduced in 2.8.0
Parameters
outputIndex:
integer identifying the output channel number 0 for CH1, up to MAX_OUTPUT_CHANNELS - 1.
Return value
value
current output value (number). Zero is returned for:
non-existing outputs
Gets the value of a shared memory variable that can be used for passing data between Lua widgets and other Lua scripts.
@status current Introduced in 2.6
Parameters
id:
integer between 1 and 16 identifying the shared memory variable.
Return value
value:
integer. The value of the shared memory variable.
Notice
Only available on radios with color display
Returns (some of) the general radio settings
@status current Introduced in 2.0.6, imperial
added in TODO, language
and voice
added in 2.2.0, gtimer added in 2.2.2.
none
table
with elements:
battWarn
(number) radio battery range - warning value
battMin
(number) radio battery range - minimum value
battMax
(number) radio battery range - maximum value
imperial
(number) set to a value different from 0 if the radio is set to the
IMPERIAL units
language
(string) radio language (used for menus)
voice
(string) voice language (used for speech)
gtimer
(number) radio global timer in seconds (does not include current session)
Return rotary encoder mode
@status current Introduced in 2.8.0
Parameters
none
Return value
number
in list: Normal = 0, Both V and H inverted = 1, V-N = 2, V-A = 3
return 0
on radio without rotary encoder
2.0 |
2.1 |
2.2 |
2.3 |
sourceName
: string naming a value source as it is shown on radio menus where you can select it. Notice that many names have in them.
Return value
sourceIndex
: integer. The source index, which can be used as input for getSourceName(sourceIndex)
, getValue(sourceIndex)
, and getFieldInfo(sourceIndex)
.
The source names shown on the screen are not the same as the names used by getFieldInfo
and getValue
. But the indices are the same, so e.g. getValue(index)
will work with the indices obtained here.
This function is rather time consuming, and should not be used repeatedly in a script, if it can be avoided.
Current Introduced in 2.6
,
, ,
, , ,
sourceIndex
: integer identifying a value source as returned by getSourceIndex(sourceName)
or the id
field in the table returned by getFieldInfo
.
sourceName
: string naming the value source as it is shown on radio menus where a source can be chosen.
The source names shown on the screen are not the same as the names used by getFieldInfo
and getValue
. But the indices are the same, so e.g. getValue(index)
will work with the indices used here.
Current Introduced in 2.6
Return the internal GPS position or nil if no valid hardware found
@status current Introduced in 2.2.2
none
table
representing the current radio position
lat
(number) internal GPS latitude, positive is North
lon
(number) internal GPS longitude, positive is East
'numsat' (number) current number of sats locked in by the GPS sensor
'fix' (boolean) fix status
'alt' (number) internal GPS altitude in 0.1m
'speed' (number) internal GPSspeed in 0.1m/s
'heading' (number) internal GPS ground course estimation in degrees * 10
'hdop' (number) internal GPS horizontal dilution of precision
@status current Introduced in 2.6
switchIndex
: integer identifying a switch as returned by getSwitchIndex(positionName)
or fields in the table returned by model.getLogicalSwitch(switch)
identifying switches.
value: string naming the switch position as it is shown on radio menus where a switch can be chosen.
Return the time since the radio was started in multiple of 10ms
The timer internally uses a 32-bit counter which is enough for 497 days so overflows will not happen.
@status current Introduced in 2.0.0
none
number
Number of 10ms ticks since the radio was started Example:
run time: 12.54 seconds, return value: 1254
Generate haptic feedback
@status current Introduced in 2.2.0
duration
(number) length of the haptic feedback in milliseconds
pause
(number) length of the silence after haptic feedback in milliseconds
flags
(number):
0 or not present
play with normal priority
PLAY_NOW
play immediately
none
Returns the value of a source.
The list of fixed sources:
OpenTX Version | Radio |
---|---|
In OpenTX 2.1.x the telemetry sources no longer have a predefined name. To get a telemetry value simply use it's sensor name. For example:
Altitude sensor has a name "Alt"
to get the current altitude use the source "Alt"
to get the minimum altitude use the source "Alt-", to get the maximum use "Alt+"
@status current Introduced in 2.0.0, changed in 2.1.0, Cels+
and Cels-
added in 2.1.9
source
can be an identifier (number) (which was obtained by the getFieldInfo())
or a name (string) of the source.
value
current source value (number). Zero is returned for:
non-existing sources
for all telemetry source when the telemetry stream is not received
far all non allowed sensors while FAI MODE is active
table
GPS position is returned in a table:
lat
(number) latitude, positive is North
lon
(number) longitude, positive is East
pilot-lat
(number) pilot latitude, positive is North
pilot-lon
(number) pilot longitude, positive is East
table
GPS date/time, see getDateTime()
table
Cells are returned in a table (except where no cells were detected in which case the returned value is 0):
table has one item for each detected cell:
key (number) cell number (1 to number of cells)
value (number) current cell voltage
Getting a value by its numerical identifier is faster then by its name. While Cels
sensor returns current values of all cells in a table, a Cels+
or Cels-
will return a single value - the maximum or minimum Cels value.
Returns the value of a source. Supersedes getValue
.
The list of fixed sources:
OpenTX Version | Radio |
---|---|
In OpenTX 2.1.x the telemetry sources no longer have a predefined name. To get a telemetry value simply use it's sensor name. For example:
Altitude sensor has a name "Alt"
to get the current altitude use the source "Alt"
to get the minimum altitude use the source "Alt-", to get the maximum use "Alt+"
value is nil for non-existing sources. all non-allowed sensors while FAI MODE is active, or if a telemetry item value has never been received
value is a table for GPS position:
lat
(number) latitude, positive is North
lon
(number) longitude, positive is East
pilot-lat
(number) pilot latitude, positive is North
pilot-lon
(number) pilot longitude, positive is East
value is a table for date/time, see getDateTime()
value is a table for battery cells(except where no cells were detected in which case the returned value is 0):
table has one item for each detected cell:
key (number) cell number (1 to number of cells)
value (number) current cell voltage
@status current Introduced in 2.8.0
source
can be an index (number) (which was obtained by getFieldInfo
or getSourceIndex
) or a name (string) of the source.
value
current source value (number), or last known telemetry item value.
isCurrent
is true for telemetry sources that are within the "Sensor Lost" duration and telemetry is streaming . Always true for non-telemetry items.
isFresh
is true for telemetry sources which have been recently updated and telemetry is streaming. Always true for non-telemetry items.
Getting a value by its numerical identifier is much faster than by its name. While Cels
sensor returns current values of all cells in a table, a Cels+
or Cels-
will return a single value - the maximum or minimum Cels value.
Return OpenTX version
@status current Introduced in 2.0.0, expanded in 2.1.7, radio type strings changed in 2.2.0, os name added in EdgeTX 2.4.0
This example also runs in OpenTX versions where the function returned only one value:
Output of the above script in simulator:
none
string
OpenTX version (ie "2.1.5")
multiple
values (available since 2.1.7):
(string) OpenTX version (ie "2.1.5")
(string) radio type: x12s
, x10
, x9e
, x9d+
, x9d
or x7
.
If running in simulator the "-simu" is added
(number) major version (ie 2 if version 2.1.5)
(number) minor version (ie 1 if version 2.1.5)
(number) revision number (ie 5 if version 2.1.5)
Since EdgeTX 2.4.0, sixth value added
(string) OS name (i.e. EdgeTX or nil if OpenTX)
2.0
2.1
2.2
2.3
X9D and X9D+, X9E, X7, Horus
2.0
2.1
2.2
2.3
X9D and X9D+, X9E, X7, Horus
Pops a received Ghost Telemetry packet from the queue.
@status current Introduced in 2.7.0
Parameters
none
Return value
nil
queue does not contain any (or enough) bytes to form a whole packet
multiple
returns 2 values:
type (number)
packet (table) data bytes
Play a numerical value (text to speech)
@status current Introduced in 2.0.0
value
(number) number to play. Value is interpreted as integer.
unit
(number) unit identifier [Full list]((../appendix/units.html))
attributes
(unsigned number) possible values:
0 or not present
plays integral part of the number (for a number 123 it plays 123)
PREC1
plays a number with one decimal place (for a number 123 it plays 12.3)
PREC2
plays a number with two decimal places (for a number 123 it plays 1.23)
none
This functions allows for sending telemetry data toward the Ghost link.
When called without parameters, it will only return the status of the output buffer without sending anything.
@status current Introduced in 2.7.0
Parameters
command
command
data
table of data bytes
Return value
boolean
data queued in output buffer or not.
nil
incorrect telemetry protocol.
Load a Lua script file. This is similar to Lua's own loadfile() API method, but it uses OpenTx's optional pre-compilation feature to save memory and time during load.
Return values are same as from Lua API loadfile() method: If the script was loaded w/out errors then the loaded script (or "chunk") is returned as a function. Otherwise, returns nil plus the error message.
@status current Introduced in 2.2.0
file
(string) Full path and file name of script. The file extension is optional and ignored (see mode
param to control which extension will be used). However, if an extension is specified, it should be ".lua" (or ".luac"), otherwise it is treated as part of the file name and the .lua/.luac will be appended to that.
mode
(string) (optional) Controls whether to force loading the text (.lua) or pre-compiled binary (.luac) version of the script. By default OTx will load the newest version and compile a new binary if necessary (overwriting any existing .luac version of the same script, and stripping some debug info like line numbers). You can use mode
to control the loading behavior more specifically. Possible values are:
b
only binary.
t
only text.
T
(default on simulator) prefer text but load binary if that is the only version available.
bt
(default on radio) either binary or text, whichever is newer (binary preferred when timestamps are equal).
Add x
to avoid automatic compilation of source file to .luac version.
Eg: "tx", "bx", or "btx".
Add c
to force compilation of source file to .luac version (even if existing version is newer than source file).
Eg: "tc" or "btc" (forces "t", overrides "x").
Add d
to keep extra debug info in the compiled binary.
Eg: "td", "btd", or "tcd" (no effect with just "b" or with "x").
env
(integer) See documentation for Lua function loadfile().
function
The loaded script, or nil
if there was an error (e.g. file not found or syntax error).
string
Error message(s), if any. Blank if no error occurred.
Note that you will get an error if you specify mode
as "b" or "t" and that specific version of the file does not exist (eg. no .luac file when "b" is used). Also note that mode
is NOT passed on to Lua's loader function, so unlike with loadfile() the actual file content is not checked (as if no mode or "bt" were passed to loadfile()).
Raises a pop-up on screen that allows uses input
@status current Introduced in 2.0.0
title
(string) text to display
event
(number) the event variable that is passed in from the Run function (key pressed)
input
(number) value that can be adjusted by the +/- keys
min
(number) min value that input can reach (by pressing the - key)
max
(number) max value that input can reach
number
result of the input adjustment
"OK"
user pushed ENT key
"CANCEL"
user pushed EXIT key
Use only from stand-alone and telemetry scripts.
Play a file from the SD card
@status current Introduced in 2.0.0, changed in 2.1.0
path
(string) full path to wav file (i.e. “/SOUNDS/en/system/tada.wav”)
Introduced in 2.1.0: If you use a relative path, the current language is appended
to the path (example: for English language: /SOUNDS/en
is appended)
none
Raises a pop-up on screen that asks for confirmation
@status current Introduced in 2.2.0, changed from (title, event) to (title, message, event) in 2.3.8
title
(string) title to display
message
(string) text to display
event
(number) the event variable that is passed in from the Run function (key pressed)
"CANCEL"
user pushed EXIT key
Use only from stand-alone and telemetry scripts.
Play a tone
@status current Introduced in 2.1.0
frequency
(number) tone frequency in Hz (from 150 to 15000)
duration
(number) length of the tone in milliseconds
pause
(number) length of the silence after the tone in milliseconds
flags
(number):
0 or not present
play with normal priority.
PLAY_BACKGROUND
play in background (built in vario function uses this context)
PLAY_NOW
play immediately
freqIncr
(number) positive number increases the tone pitch (frequency with time), negative number decreases it. The frequency changes every 10 milliseconds, the change is freqIncr * 10Hz
. The valid range is from -127 to 127.
none
Raises a pop-up on screen that shows a warning
@status current Introduced in 2.2.0
title
(string) text to display
event
(number) the event variable that is passed in from the Run function (key pressed)
"CANCEL"
user pushed EXIT key
Use only from stand-alone and telemetry scripts.
Sets the value of a shared memory variable that can be used for passing data between Lua widgets and other Lua scripts.
@status current Introduced in 2.6
Parameters
id:
integer between 1 and 16 identifying the shared memory variable.
value:
integer. The value of the shared memory variable.
Return value
none
Notice
Only available on radios with color display
This is an iterator function over value sources.
for sourceIndex, sourceName in sources() do ...
will iterate over all available value sources.
first
: the first source index. If nil
or omitted, the first available source is used.
last
: the last soure index. If nil
or omitted, the last available source is used.
current Introduced in 2.6
Get model timer parameters
@status current Introduced in 2.0.0, name added in 2.3.6
timer
(number) timer index (0 for Timer 1)
nil
requested timer does not exist
table
timer parameters:
mode
(number) timer trigger source: off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw
start
(number) start value [seconds], 0 for up timer, 0> down timer
value
(number) current value [seconds]
countdownBeep
(number) countdown beep (0 = silent, 1 = beeps, 2 = voice)
minuteBeep
(boolean) minute beep
persistent
(number) persistent timer
name
(string) timer name
@status current Introduced in 2.2.0
id
Id of the sensor, valid range is from 0 to 0xFFFF
subID
subID of the sensor, usually 0, valid range is from 0 to 7
instance
instance of the sensor (SensorID), valid range is from 0 to 0xFF
value
fed to the sensor
unit
unit of the sensor Full list
precision
the precision of the sensor
0 or not present
no decimal precision.
!= 0
value is divided by 10^precision, e.g. value=1000, prec=2 => 10.00.
name
(string) Name of the sensor if it does not yet exist (4 chars).
not present
Name defaults to the Id.
present
Sensor takes name of the argument. Argument must have name surrounded by quotes: e.g., "Name"
true,
if the sensor was just added. In this case the value is ignored (subsequent call will set the value)
All three parameters id
, subID
and instance
can't be zero at the same time. At least one of them must be different from zero.
@param num (optional): maximum number of bytes to read. If non-zero, serialRead will read up to num characters from the buffer. If 0 or left out, serialRead will read up to and including the first newline character or the end of the buffer. Note that the returned string may not end in a newline if this character is not present in the buffer.
Reads characters from the serial port. The string is allowed to contain any character, including 0.
@status current Introduced in 2.3.8
none
str
string. Empty if no new characters were available.
@status current Introduced in 2.9.0
port_nr:
valid values are only 0 and 1 on radios that have SWSERIALPOWER defined
0 - first serial port, e.g. on TX16S AUX1
1 - second serial port, e.g. on TX16S AUX2
value:
true for power enabled, false for power disabled.
nil
serial port power control not available
Sets the value of a sticky logical switch.
@status current Introduced in 2.6
id: integer identifying the sticky logical switch (zero for LS1 etc.).
value: true/false. The new value of the sticky logical switch.
bufferFull: true/false. This function sends a message from Lua to the logical switch processor via a buffer with eight slots that are read 10 times per second. If the buffer is full, then a true value is returned, and no message was sent (i.e. the switch was not changed).
Pops a received SPORT packet from the queue. Please note that only packets using a data ID within 0x5000 to 0x50FF (frame ID == 0x10), as well as packets with a frame ID equal 0x32 (regardless of the data ID) will be passed to the LUA telemetry receive queue.
@status current Introduced in 2.2.0
none
nil
queue does not contain any (or enough) bytes to form a whole packet
multiple
returns 4 values:
sensor ID (number)
frame ID (number)
data ID (number)
value (number)
Get Curve parameters
Note this function uses Lua's usual index starting with 1 since version 2.9.0.
@status current Introduced in 2.0.12, uses Lua's normal indexing as of 2.9.0
curve
(unsigned number) curve number (use 0 for Curve1)
nil
requested curve does not exist
table
curve data:
name
(string) name
type
(number) type
smooth
(boolean) smooth
points
(number) number of points
y
(table) table of Y values:
key
is point number (zero based)
value
is y value
x
(table) only included for custom curve type:
key
is point number (zero based)
value
is x value
Get Custom Function parameters
@status current Introduced in 2.0.0, TODO rename function
function
(unsigned number) custom function number (use 0 for CF1)
nil
requested custom function does not exist
table
custom function data:
switch
(number) switch index
func
(number) function index
name
(string) Name of track to play (only returned only returned if action is play track, sound or script)
value
(number) value (only returned only returned if action is not play track, sound or script)
mode
(number) mode (only returned only returned if action is not play track, sound or script)
param
(number) parameter (only returned only returned if action is not play track, sound or script)
active
(number) 0 = disabled, 1 = enabled
This is an iterator function over switch positions.
for switchIndex, switchName in switches() do ...
will iterate over all available switch positions.
first
: the first switch index. If nil
or omitted, the first available switch is used.
last
: the last switch index. If nil
or omitted, the last available switch is used.
Current Introduced in 2.6
Get current Model information
@status current Introduced in 2.0.6, changed in 2.2.0, filename added in 2.6.0, extendedLimits, jitterFilter, and labels added in 2.8.0
none
table
model information:
name
(string) model name
extendedLimits
(boolean) extended limits enabled
jitterFilter
(number) model level ADC filter
bitmap
(string) bitmap name (not present on X7)
filename
(string) model filename
This functions allows for sending SPORT telemetry data toward the receiver, and more generally, to anything connected SPORT bus on the receiver or transmitter.
When called without parameters, it will only return the status of the output buffer without sending anything.
@status current Introduced in 2.2.0, retval nil added in 2.3.4
sensorId
physical sensor ID
frameId
frame ID
dataId
data ID
value
value
boolean
data queued in output buffer or not.
nil
incorrect telemetry protocol.
Get configuration for specified Mix
@status current Introduced in 2.0.0, parameters below multiplex
added in 2.0.13
channel
(unsigned number) channel number (use 0 for CH1)
line
(unsigned number) mix number (use 0 for first line(mix))
nil
requested channel or line does not exist
table
mix data:
name
(string) mix line name
source
(number) source index
weight
(number) weight (1024 == 100%) value or GVAR1..9 = 4096..4011, -GVAR1..9 = 4095..4087
offset
(number) offset value or GVAR1..9 = 4096..4011, -GVAR1..9 = 4095..4087
switch
(number) switch index
multiplex
(number) multiplex (0 = ADD, 1 = MULTIPLY, 2 = REPLACE)
curveType
(number) curve type (function, expo, custom curve)
curveValue
(number) curve index
flightModes
(number) bit-mask of active flight modes
carryTrim
(boolean) carry trim
mixWarn
(number) warning (0 = off, 1 = 1 beep, .. 3 = 3 beeps)
delayUp
(number) delay up (time in 1/10 s)
delayDown
(number) delay down
speedUp
(number) speed up
speedDown
(number) speed down
Get Logical Switch parameters
@status current Introduced in 2.0.0
switch
(unsigned number) logical switch number (use 0 for LS1)
nil
requested logical switch does not exist
table
logical switch data:
func
(number) function index, see Logical Switch Function Constants.
v1
(number) V1 value (index)
v2
(number) V2 value (index or value)
v3
(number) V3 value (index or value)
and
(number) AND switch index
delay
(number) delay (time in 1/10 s)
duration
(number) duration (time in 1/10 s)
Get servo parameters
@status current Introduced in 2.0.0
index
(unsigned number) output number (use 0 for CH1)
nil
requested output does not exist
table
output parameters:
name
(string) name
min
(number) Minimum % * 10
max
(number) Maximum % * 10
offset
(number) Subtrim * 10
ppmCenter
(number) offset from PPM Center. 0 = 1500
symetrical
(number) linear Subtrim 0 = Off, 1 = On
revert
(number) irection 0 = ---, 1 = INV
curve
(number) Curve number (0 for Curve1)
or nil
if no curve set
Return input data for given input and line number
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10, flighmode reworked in 2.3.11
input
(unsigned number) input number (use 0 for Input1)
line
(unsigned number) input line (use 0 for first line)
nil
requested input or line does not exist
table
input data:
name
(string) input line name
inputName
(string) input input name
source
(number) input source index
weight
(number) input weight
offset
(number) input offset
switch
(number) input switch index
curveType
(number) curve type (function, expo, custom curve)
curveValue
(number) curve index
carryTrim
(boolean) input trims applied
'flightModes' (number) bit-mask of active flight modes
Get RF module parameters
Type
values:
0 NONE
1 PPM
2 XJT_PXX1
3 ISRM_PXX2
4 DSM2
5 CROSSFIRE
6 MULTIMODULE
7 R9M_PXX1
8 R9M_PXX2
9 R9M_LITE_PXX1
10 R9M_LITE_PXX2
11 R9M_LITE_PRO_PXX1
12 R9M_LITE_PRO_PXX2
13 SBUS
14 XJT_LITE_PXX2
subType
values for XJT_PXX1:
-1 OFF
0 D16
1 D8
2 LR12
@status current Introduced in 2.2.0
index
(number) module index (0 for internal, 1 for external)
nil
requested module does not exist
table
module parameters:
subType
(number) protocol index
modelId
(number) receiver number
firstChannel
(number) start channel (0 is CH1)
channelsCount
(number) number of channels sent to module
Type
(number) module type
if the module type is Multi additional information are available
protocol
(number) protocol number (Multi only)
subProtocol
(number) sub-protocol number (Multi only)
channelsOrder
(number) first 4 channels expected order (Multi only)
Insert a mixer line into Channel
@status current Introduced in 2.0.0, parameters below multiplex
added in 2.0.13
channel
(unsigned number) channel number (use 0 for CH1)
line
(unsigned number) mix number (use 0 for first line(mix))
value
(table) see model.getMix() for table format
none
Get heli swash parameters
@status current Introduced in 2.8.0
Parameters
none
Return value
table
with heli swash parameters:
type
(number) 0=---, 1=120, 2=120X, 3=140, 4=90
value
(number) swash ring value (normally 0)
'collectiveSource' (number) source index
'aileronSource' (number) source index
'elevatorSource' (number) source index
'collectiveWeight'(value) -100 to 100
'aileronWeight' (value) -100 to 100
'elevatorWeight' (value) -100 to 100
Set Custom Function parameters
@status current Introduced in 2.0.0, TODO rename function
function
(unsigned number) custom function number (use 0 for CF1).
value
(table) custom function parameters, see model.getCustomFunction() for table format
none
If a parameter is missing from the value, then that parameter remains unchanged.
Insert an Input at specified line
@status current Introduced in 2.0.0, curveType/curveValue/carryTrim added in 2.3, inputName added 2.3.10
input
(unsigned number) input number (use 0 for Input1)
line
(unsigned number) input line (use 0 for first line)
value
(table) input data, see model.getInput()
none
@status current Introduced in 2.6
positionName
: string naming a switch position as it is shown on radio menus where you can select a switch. Notice that many names have special characters in them like arrow up/down etc. (see ).
value: integer. The switchIndex, which can be used as input for `getSwitchName(switchIndex)` and `getSwitchValue(switchIndex)`. Also corresponds to the fields in the table returned by `model.getLogicalSwitch(switch)` identifying switches.
Get Telemetry Sensor parameters
@status current Introduced in 2.3.0
sensor
(unsigned number) sensor number (use 0 for sensor 1)
nil
requested sensor does not exist
table
with sensor data:
type
(number) 0 = custom, 1 = calculated
name
(string) Name
unit
(number) See list of units in the appendix of the OpenTX Lua Reference Guide
prec
(number) Number of decimals
id
(number) Only custom sensors
instance
(number) Only custom sensors
formula
(number) Only calculated sensors. 0 = Add etc. see list of formula choices in Companion popup
Return input data for given input and line number
@status current Introduced in 2.3.10
index
(unsigned number) flight mode number (use 0 for FM0)
nil
requested input or line does not exist
table
input data:
name
(string) input line name
switch
(number) input switch index
fadeIn
(number) fade in value (in 0.1s)
fadeOut
(number) fade out value (in 0.1s)
trimsValues
(table) table of trim values:
key
is trim number (zero based)
value
is trim value
trimsModes
(table) table of trim mode:
key
is trim number (zero based)
value
is trim mode
Set Curve parameters
The first and last x value must -100 and 100 and x values must be monotonically increasing
@status current Introduced in 2.2.0
Example setting a 4-point custom curve:
setting a 6-point standard smoothed curve
curve
(unsigned number) curve number (use 0 for Curve1)
params
see model.getCurve return format for table format. setCurve uses standard lua array indexing and arrays start at index 1
`` 0 - Everything okay