Mixes Scripts take one or more values as inputs, do some processing in Lua code, and output one or more values. Each model can have several Mixes Scripts associated with it, and these scripts are run periodically. They behave similarly to standard EdgeTX mixers, but at the same time they provide a much more flexible and powerful tool.
Typical use cases:
replacement for complex mixes that are not critical to model function
complex processing of inputs and reaction to their current state and/or their history
filtering of telemetry values
Mixes script is loded when model is selected. Script executes until
it misbehaves (e.g. run-time error or low memory)
One-time Script is running. When One-time script finishes execution, Wigdet Script resumes execution.
If the script output is used as a mixer source
, and the script is killed for whatever reason, then the whole mixer line is disabled!
Mixes Scripts should be as short as possible, to avoid delays. It is also important to keep in mind that other loaded Telemetry and Function scripts can add to the response time, or worse: hang the system!
To enable Mixes Scripts, firmware must be compiled with the option LUA_MIXER=Y
.
Mixes scripts are located on SD card in folder /SCRIPTS/MIXES/
File name length (without extension) must be 6 characters or less
Every Mixes Script must include a return
statement at the end, defining its interface to EdgeTX. This statement returns a table with the following fields:
This function is called periodicaly when script is running.
Parameters
Variables matching those used in input
table
Return values
Variables matching those used in output
table\
This function is called once when Mixes Script is loaded and executed for the first time
Parameters none Return values none\
The input table defines what values are available as input(s) to custom scripts.
There are two forms of input table entries
SOURCE
SOURCE inputs provide the current value of a selected OpenTX variable. The source must be selected by the user when the script is configured. Source can be any value that EdgeTX knows about (inputs, channels, telemetry values, switches, custom functions etc.). Note: the typical input range is -1024 thru +1024. Simply divide the input value by 10.24 to convert to a percentage from -100% to +100%.
VALUE
VALUE inputs provide a constant value that is set by the user when the script is configured.
name - maximum length of 8 characters
min - minimum value of -128
max - maximum value of 127
default - must be within the valid range specified
Maximum of 6 inputs per script
The output table defines only name(s), as the actual values are returned by the script's run function.
Above names are only visible as source values on the radio screen when the script is running. If the model is edited in Companion, then the values show as LUA1a
and LUA1b
etc.
Example of <decribe what it does>.
Example where Lua mix script is used to drive ailerons in some clever way, but control falls back to the standard aileron mix if script is killed. Second mixer line replaces the first one when the script is alive:
table item | type | required |
---|---|---|
table item | type | required |
---|---|---|
table item | type | required |
---|---|---|
table item | type | required |
---|---|---|
run
function
yes
init
function
no
input
table
yes
output
table
yes