OpenTX 2.1 Lua Reference Guide
  • OpenTX 2.1 Lua Reference Guide
  • Introduction
    • Acknowledgments
    • Getting Started
  • Part I - Script Type Overview
    • Mix Scripts
    • Telemetry Scripts
    • One-Time Scripts
    • Wizard Script
    • Function Scripts
  • Part II - OpenTX Lua API Programming Guide
    • Input Table Syntax
    • Output Table Syntax
    • Init Function Syntax
    • Run Function Syntax
    • Return Statement Syntax
    • Included Lua Libraries
      • io Library
        • io.open()
        • io.close()
        • io.read()
        • io.write()
        • io.seek()
  • Part III - OpenTX Lua API Reference
    • Constants
      • Key Event Constants
    • General Functions
      • GREY()
      • defaultChannel(stick)
      • defaultStick(channel)
      • getDateTime()
      • getFieldInfo(name)
      • getFlightMode(mode)
      • getGeneralSettings()
      • getTime()
      • getValue(source)
      • getVersion()
      • killEvents(key)
      • playDuration(duration [, hourFormat])
      • playFile(name)
      • playNumber(value, unit [, attributes])
      • playTone(frequency, duration, pause [, flags [, freqIncr]])
      • popupInput(title, event, input, min, max)
    • Model Functions
      • model.defaultInputs()
      • model.deleteInput(input, line)
      • model.deleteInputs()
      • model.deleteMix(channel, line)
      • model.deleteMixes()
      • model.getCurve(curve)
      • model.getCustomFunction(function)
      • model.getGlobalVariable(index [, flight_mode])
      • model.getInfo()
      • model.getInput(input, line)
      • model.getInputsCount(input)
      • model.getLogicalSwitch(switch)
      • model.getMix(channel, line)
      • model.getMixesCount(channel)
      • model.getModule(index)
      • model.getOutput(index)
      • model.getTimer(timer)
      • model.insertInput(input, line, value)
      • model.insertMix(channel, line, value)
      • model.resetTimer(timer)
      • model.setCustomFunction(function, value)
      • model.setGlobalVariable(index, flight_mode, value)
      • model.setInfo(value)
      • model.setLogicalSwitch(switch, value)
      • model.setModule(index, value)
      • model.setOutput(index, value)
      • model.setTimer(timer, value)
    • Lcd Functions
      • Lcd Functions Overview
      • lcd.clear()
      • lcd.drawChannel(x, y, source, flags)
      • lcd.drawCombobox(x, y, w, list, idx [, flags])
      • lcd.drawFilledRectangle(x, y, w, h [, flags])
      • lcd.drawGauge(x, y, w, h, fill, maxfill)
      • lcd.drawLine(x1, y1, x2, y2, pattern, flags)
      • lcd.drawNumber(x, y, value [, flags])
      • lcd.drawPixmap(x, y, name)
      • lcd.drawPoint(x, y)
      • lcd.drawRectangle(x, y, w, h [, flags])
      • lcd.drawScreenTitle(title, page, pages)
      • lcd.drawSource(x, y, source [, flags])
      • lcd.drawSwitch(x, y, switch, flags)
      • lcd.drawText(x, y, text [, flags])
      • lcd.drawTimer(x, y, value [, flags])
      • lcd.getLastPos()
      • lcd.lock()
  • Part IV - Converting OpenTX 2.0 Scripts
    • General Issues
    • Handling GPS Sensor data
    • Handling Lipo Sensor Data
  • Part V - Advanced Topics
    • Lua data sharing across scripts
    • Debugging techniques
Powered by GitBook
On this page
  • Description
  • Typical uses
  • Limitations
  • Location
  • Lifetime
  • Script interface definition
  • Example (interface only):
  • Notes:

Was this helpful?

  1. Part I - Script Type Overview

Mix Scripts

WARNING - Do not use Lua mix scripts for controlling any aspect of your model that could cause a crash if script stops executing.

Description

Each model can have several mix scripts associated with it. These scripts are run periodically for entire time that model is selected. These scripts behave similar to standard OpenTX mixers but at the same time provide much more flexible and powerful tool.

Mix scripts take one or more values as inputs, do some calculation or logic processing based on them and output one or more values. Each run of a script should be as short as possible. Exceeding the script execution runtime limit will result in the script being forcefully stopped and disabled.

Typical uses

  • 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

Limitations

  • cannot update LCD screen or perform user input.

  • should not exceed allowed run-time/ number of instructions.

  • mix scripts are run with less priority than built-in mixes. Their execution period is around 30ms and is not guaranteed!

  • can be disabled/killed anytime due to logic errors in script, not enough free memory, etc...)

Location

Place them on SD card in folder /SCRIPTS/MIXES/

Lifetime

  • script is loaded from SD card when model is selected

  • script init function is called

  • script run function is periodically called (inside GUI thread, period cca 30ms)

  • script is stopped and disabled if it misbehaves (too long runtime, error in code, low memory)

  • all mix scripts are stopped while one-time script is running (see Lua One-time scripts)

Script interface definition

Every script must include a return statement at the end, that defines its interface to the rest of OpenTX code. This statement defines:

Example (interface only):

local input {}

local output {}

local function init_func()
end

local function run_func()
end

return { input=input, output=output, run=run_func, init=init_func }

Notes:

  • init_func() function is called once when script is loaded.

  • run_func() function is called periodically

PreviousPart I - Script Type OverviewNextTelemetry Scripts

Last updated 4 years ago

Was this helpful?

script input table (optional, see )

script output table (optional, see )

script init function (optional, see )

script run function (see )

inputs table defines input parameters (name and source) to run function ()

outputs table defines names for values returned by run function (see )

Input Table Syntax
Output Table Syntax
Init Function Syntax
Run Function Syntax
see Input Table Syntax
Output Table Syntax