Data Exchange with the EdgeTX Model Setup
An EdgeTX model has several data components that can be exchanged with Lua scripts. This section gives an overview.
In general terms, there are two different types of data that can be exchanged with EdgeTX:
Values, which generally fall on a scale between -1024 and 1024, also sometimes reported as -100% to 100%, e.g. for mixer values and channel outputs.
Switches, which are either
true
orfalse.
A specific data source type, e.g. Global Variables, can be indexed directly with an index that starts with 0 for the first one. This can be a little confusing, as e.g. GV1 for FM0 is read with model.getGlobalVariable(0, 0)
, because GV1 is the first global variable, and FM0 is the first flight mode. But as long as you remember that all direct indices start with 0 for the first one, you should be fine!
Global Variables is a value data source that can return a value between -1024 and 1024. Examples of value sources are:
Global Variables
Sticks, sliders and knobs
Trim values
Input lines
Channel outputs
Trainer channel inputs
Telemetry sensors
There is a way to access a value of any such type with a meta-index. You use the function getFieldInfo(name)
where name
can be any of the valid source names listed here. It returns a table with a description of the value source, including the field id,
which is the meta-index.
You can use id
with the function getValue(id)
to read the current value. You can also use name
directly, but this is less efficient, as EdgeTX does a linear search for the name every time it is called. Therefore, the procedure of first extracting the meta-index from getFieldInfo(name).id
, and then using that, is recommended.
For switches, getLogicalSwitchValue(index)
uses a direct index to read this specific type of switch sources, again using the index
0 for LS1 etc. But there are also several types of switch sources, such as:
Logical switches
Switch positions, testing if a physical switch is in a particular position, e.g.
SA↑
.Trim buttons
Transmitter and telemetry activity
You can find the meta-index of a particular switch source with getSwitchIndex(name)
, where name
is exactly the name that you see in the radio menus where you can select a switch source.
You can read the current value of a switch source with getSwitchValue(index)
as a true
/false
value.
It can be very confusing that some source can be read both as a value and as a switch. As an example, elevator trim can be read as the current value of the trim:
Or it can be read as the current value of the trim button position:
These are really two different things, as the elevator trim is an internal value stored by the radio, which is changed with the trim button, and the button is a physical button.
But it can also be a more direct comparison, e.g. the 3-position switch B, which can be read as a value source with:
Or the current position of switch B can be read with:
Hopefully, these examples illustrated the differences between values and switches, and showed how these can be retrieved in a Lua script.
You can also send data the other way: from Lua to the EdgeTX model setup.
To send a value, use a global variable: model.setGlobalVariable(index, fm, value)
. If you use the default GV setting, where all other flight modes use the value of FM0, then you can use 0 for fm
.
To send a switch, setup a STICKY
type logical switch, and then use setStickySwitch(index, true/false)
. Notice that a blank sticky switch STICKY(---, ---)
is ON when the model is first loaded. If you want a sticky switch to be OFF by default then use the value of the switch itself as V1
, i.e. L01 = STICKY(L01, ---)
will be off by default.
The following table gives an overview of the Lua API functions that can be used to exchange data with the EdgeTX model setup.
Last updated