Lua Scripting in OpenTX

Reference Guide

Contents

Contents

Introduction

Model Scripts

General description

Limitations of model scripts

Anatomy of model script

Location of model scripts

Lifetime of model script

Script interface definition

Script initialization

Script execution

One-Time Scripts

General description

Anatomy of one-time script

Location of one-time scripts

Lifetime of a one-time script

Script interface definition

Script initialization

Script execution

Function Scripts

Telemetry Scripts

General description

Anatomy of telemetry script

Location of telemetry scripts

Lifetime of telemetry script

Script interface definition

Script initialization

Script execution

Lua Script Reference

General Syntax

Local vs. Global

Local Variables

Local Functions

Inputs Syntax

Number Format

Types of Inputs

Outputs Syntax

Number Format

Lua General Functions

getTime()

getVersion()

getValue(source)

playFile(path)

popupInput(title, event, input, min, max)

getGeneralSettings()

playNumber(number, unit, att)

defaultStick(channel)

defaultChannel(stick)

killEvents(key-event)

getFieldInfo(fieldname)

playDuration(duration,playtime)

playTone(frequency, length, pause, attr, frequnecyInc)

Lua Model Functions

model.getTimer(timer)

model.setTimer(timer, data)

model.getInputsCount(input)

model.getInput(input, line)

model.insertInput(input, line, value)

model.deleteInput(input, line)

model.deleteInputs()

model.defaultInputs()

model.getMixesCount(channel)

model.getMix(channel, line)

model.insertMix(channel, mix, value)

model.deleteMix(channel, mix)

model.deleteMixes()

model.getLogicalSwitch(switch)

model.setLogicalSwitch(switch, value)

model.getCustomFunction(function)

model.setCustomFunction()

model.getOutput(index)

model.setOutput(index, value)

model.getInfo()

model.setInfo

model.getGlobalVariable(gvar, flightmode)

model.setGlobalVariable(gvar, flightmode, value)

model.getTelemetryChannel(idx)

model.setTelemetryChannel(idx, value)

Lua Display Functions

lcd.lock()

lcd.clear()

lcd.drawPoint(x, y)

lcd.drawLine(x1, y1, x2, y2)

lcd.drawRectangle(x, y, width, height)

lcd.drawText(x, y, text, att)

lcd.drawSwitch(x, y, switch, att)

lcd.drawPixmap(x, y, path)

lcd.drawScreenTitle(title, idx, cnt)

lcd.drawGauge(x1, y1, w, h, fill, maxfill)

lcd.drawChannel(x, y, source, att)

lcd.drawNumber(x, y, number ,att)

lcd.drawTimer(x, y, value, att)

lcd.getLastPos()

lcd.drawFilledRectangle(x, y, w, h, att)

lcd.drawSource(x, y, source, att)

lcd.drawCombobox(x, y, w, list, idx, flag)

Script Examples

One-Time Script Example: Hello World

One-Time Script Example: Generic Template

Model Script Example: Delta Mixer

Telemetry Script Example: Screen #1

Telemetry Script Example: Screen #2

Model Script Example: Automatic Battery Cell Detection

Appendix

LUA Source List

Character Maps

SMLSIZE

default

MIDSIZE

DBLSIZE

XXLSIZE

Links to external documentation:

Document Style

Acknowledgments


Introduction

OpenTX 2.0 added support for Lua (current version 5.2.2) user scripts.

Lua is a lightweight multi-paradigm programming language designed as a scripting language. More at Wikipedia

There are several types of Lua scripts used in openTX. More general information about Lua scripts can be found on page http://www.open-tx.org/lua-instructions.html

Lua scripts must be placed on SD card in correct folders and have an extension .lua. Maximum Lua script file name length is TODO characters. The script folders have been reorganized in OpenTX 2.0.3. The folder structure looks like this:

  • /SCRIPTS/WIZARD/ - For the Wizard script
  • /SCRIPTS/MIXES/ - For model scripts
  • /SCRIPTS/FUNCTIONS/ - For function scripts
  • /SCRIPTS/«modelname»/telemXX.lua - For telemetry scripts
  • /SCRIPTS/TEMPLATES/ - For template scripts

Lua Standard Libraries

Included

package

no

coroutine

no

table

no

io

no

os

no

string

no

bit

Future 2.1.0?

math

Available from 2.0.0

debug

no


Model Scripts

WARNING

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

General description

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

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

See also:

Examples of typical use of model scripts

  • 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
  • automatic detection of number of battery cells and setting of low battery threshold
  • automatic announcing of maximum altitude for each DLG throw
  • see also Lua Script Examples

Limitations of model scripts

  • Should not display anything on LCD screen.
  • Can't wait for user input via dialog.
  • Should not exceed maximum allowed runtime/ number of instructions.
  • Standard OpenTX mixes are run every XX milliseconds in a very deterministic way (guaranteed execution) while model scripts are run from another thread with less priority. Their execution period is around 30ms and is not guaranteed!
  • A script could be disabled/killed anytime due to several causes like (error in script, not enough free memory, etc...)

Anatomy of model script

Location of model scripts

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

Lifetime of model script

  • 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 model 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:

  • script inputs (optional)
  • script outputs (optional)
  • script init function (optional)
  • script run function

For example:

-- script body would be here

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

This example defines:

  • inputs table (array) as input values to model script
  • outputs table as output of model script
  • run_func() function as periodic execution function that takes inputs as parameters and returns outputs table
  • init_func() function as function that is called one time when script is loaded and begins execution.

Parameters init, input and output are optional. If model script doesn't use them, they can be omitted from return statement. Example without init and output:

local inputs = { { "Aileron", SOURCE }, { "Ail. ratio", VALUE, -100, 100, 0 } }

local function run_func(ail, ratio)
   
-- do some stuff
   
if (ail > 50) and ( ratio < 40) then
       playFile
("foo.wav")   
   
end
end

-- script that only uses input and run
return { run=run_func, input=inputs }

Script initialization

If defined, init function is called right after the script is loaded from SD card and begins execution. Init is called only once before the run function is called for the first time.

local <init_function_name>()

called once before first call to run function

Parameters:

none

Returns:

none

Script execution

The run function is the function that is periodically called for the entire lifetime of script. Syntax of run function is different between model scripts and one-time scripts.

local <run_function_name>([first input, [second input], …])

Parameters:

<>

zero or more input values, their names are arbitrary, their meaning and order is defined by the input table

Returns:

none

if output table is empty (i.e. script has no output)

values

(comma separated list of values) list of output values,                         their order and meaning is defined by the output table


One-Time Scripts

General description

These scripts start when called upon by a specific radio function or when the user selects them from a contextual menu. They do their task and are then terminated and unloaded. Please note that all persistent scripts are halted during the execution of one time scripts. They are automatically restarted once the one time script is finished. This is done to provide enough system resources to execute the one time script.

See also:

  • Lua Model Scripts describes continuously running model scripts
  • Lua Script Reference detailed reference of OpenTX Lua implementation and interface
  • Lua Script Examples some example scripts with comments

Examples of typical use of one-time scripts

  • All kind of wizards to set up/edit model settings. The official model wizard is one example of such script
  • Replacement for templates
  • Games

Limitations of one-time scripts

  • When running all other Lua scripts are halted.
  • Should not exceed maximum allowed runtime/ number of instructions.

Anatomy of one-time script

Location of one-time scripts

Place them anywhere on SD card, the folder /SCRIPTS/ is recommended. The only exception is official model wizard script, that should be put into /SCRIPTS/WIZARD/ folder - that way it will start automatically when new model is created.

Lifetime of a one-time script

  • script is executed when user selects Execute on a script file from SD card browser screen.
  • script executes until:
  • it returns value different from 0
  • is forcefully closed by user by long press of EXIT key
  • is forcefully closed by system if if it misbehaves (too long runtime, error in code, low memory)

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:

  • script init function (optional)
  • script run function

For example:

-- script body would be here

return { run=run_func, init=init_func }

This example defines:

  • run_func() function as periodic execution function that takes a key press event as parameter and returns some value
  • init_func() function as function that is called one time when script is loaded and begins execution.

Parameter init is optional.

Script initialization

see script initialization

Script execution

The run function is the function that is periodically called for the entire lifetime of script. Syntax of run function is different between model scripts and one-time scripts.

local <run_function_name>(event)

Parameters:

event

number that contains currently active key press code.
If no key is pressed the value is 0.
event contains two distinct fields:

    * what happened (key up, key down, long key press, etc)
   * which key is/was pressed    

The actual values of event are usually not important inside Lua script, the event is mainly used as one of parameters for the popupInput() function.

Returns:

0

script will continue execution (run function will be called again

!=0

script is terminated (ends execution)

Example Script

Function Scripts

TODO (blank in Wiki)


Telemetry Scripts

General description

These scripts are used for building customized telemetry screens. Theoretically it is possible to have up to 7 custom telemetry screens, all written in Lua. It is possible to use different scripts on a per model basis.

Anatomy of telemetry script

Location of telemetry scripts

Place them on SD card in the folder /SCRIPTS/«modelname»/telemX.lua where X is a number from 0 to 6.

Example: /SCRIPTS/Extra/telem0.lua would be first custom telemetry screen for model Extra.

Lifetime of telemetry script

  • script is loaded from SD card and executed when the model is loaded.
  • script init function is called
  • script background function is periodically called when custom telemetry screen is not visible
  • script run function is periodically called when custom telemetry screen is visible
  • script is stopped and disabled if it misbehaves (too long runtime, error in code, low memory)
  • all telemetry 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:

  • script init function (optional)
  • script background function
  • script run function

For example:

-- script body would be here

return { run=run_func, init=init_func, background=bckgrnd_func }

This example defines:

  • bckgrnd_func() function as periodic execution function that is periodically called when custom telemetry screen is not visible
  • run_func() function as periodic execution function that is periodically called when custom telemetry screen is visible
  • init_func() function as function that is called one time when script is loaded and begins execution.

Parameter init is optional.

Script initialization

see script initialization

Script execution

The run or background function is the function that is periodically called for the entire lifetime of script. Which one is called depends on the visibility of custom telemetry screen:

  • not visible - the background function is called. Script should not draw to screen. Usually used to store/process telemetry data.
  • visible - run function is called. Script should draw its screen.

local <background_function_name>()

Parameters:

none

Returns:

none

local <run_function_name>(event)

Parameters:

event

number that contains currently active key press code. If no key is pressed, the value is 0

Event contains two distinct fields:

  * what happened (key up, key down, long key press, etc).

  * which key is/was pressed.

Returns:

none

Examples


Lua Script Reference

General Syntax

Local vs. Global

All Lua model scripts in OpenTX exist in same Lua environment. This means, that they share global functions and variables. Using global variable with the same name from two different scripts could lead to unpredictable results. Therefore the use of global variables and functions should be avoided!

TODO: how to share data between scripts

Warning

Even variables defined inside local functions without local keyword are global. For example if we have two scripts, script1:

local function run()
   global_var
= 7   -- this one is GLOBAL
   
local local_var = "foo"   -- this one is local to script1, 
                             
-- but visible in all script1 functions
end

and script 2:

local function run()
   
if global_var == 7 then   -- here global_var is already defined from script1
       playFile
("Whoopsie.wav")
   
end
   
if local_var == "foo" then   -- local_var here is nil, because it was not yet assigned
       
print("We don't get here, local_var is nil")
   
end
end

If we execute both scripts, we would hear "Whoopsie.wav" (if it is present on SD card). This means that variable global_var is actually global even if it is first defined in some local function in other script.

Local Variables

Script can have any number (limited by memory usage) of local variables, their value is preserved between each call to run function. They are defined as:

local simple_number = 4
local some_table = {1, 2, 120}

Local variables are only visible to the script that defined them. Two scripts can define a local variable with the same name. These two variables don't share anything, each script has his own instance of variable.

Local Functions

Script can have any number (limited by memory usage) of local functions:

local function some_function(a, b, c)
   
local value1 = a + b * c
   
return value1
end

Local functions are only visible to the script that defined them. Two scripts can define a local function with the same name. These two functions don't share anything, each script has his own instance of function.

Inputs Syntax

Input are only used in model scripts. However the same number format is returned by function getValue().

Number Format

Inputs are analogue values from opentTX that are converted to 16 bit signed integers before they reach Lua scripts.

Analogue values such as sticks and sliders have value in percent multiplied by 10.24:

Aileron Stick Value

Input Value to Script

0%

0

60.6%

620

100.0%

1024

-100.0%

-1024

Switches (real and logical) are represented as:

Switch Position

Input Value to Script

down (-100%)

-1024

middle

0

up (100%)

1024

Telemetry values are returned as proper values:

Telemetry Value

Input Value to Script

altitude 120.5m

120.5

A1 voltage 5.47V

5.47

Consumption 1260mAh

1260

Types of Inputs

Source

Source type provides current value of selected OpenTX variable (stick position, slider, channel). User assigns assigns actual source for this input in Custom script menu. Source can be any value OpenTX knows about (inputs, channels, telemetry values, switches, custom functions,...).

Syntax: { name, SOURCE }

Example: { "Aileron", SOURCE }

Defines SOURCE type input with name Aileron. Name length is limited to TODO.

Value

Value type provides constant value that user sets in Custom script menu

Syntax: { name, VALUE, min, max, default }

Example: { "Ratio", VALUE, -100, 100, 0 }

Defines VALUE input with name Ratio that has limits -100 and 100 and default value of 0. Name length is limited to TODO.

Outputs Syntax

Outputs are only used in model scripts.

Syntax: { name1, name2 }

Example: { "Calc", "Out" }

Output name is limited to four characters.

Number Format

Outputs are 16 bit signed integers when they leave Lua script and are then divided by 10.24 to produce output value in percent:

Output from Script

Output as seen from OpenTX

0

0%

996

97.2%

1024

100%

-1024

-100%


Lua General Functions

getTime()

Returns the time since the radio was started in multiple of 10ms

Parameters:

none

Returns:

number

Number of 10ms ticks since the radio was started

Status:

current

Introduced in 2.0.0


getVersion()

Returns OpenTX version

Parameters:

none

Returns:

value

(string) Version (i.e. 2.0.0)

Status:

current

Introduced in 2.0.0

Example: Display Version Number

local function run_func(event)

  lcd.lock()

  lcd.clear()

  lcd.drawScreenTitle("getVersion",1,1)

  lcd.drawText(10,20,getVersion(),MIDSIZE)

  if event == EVT_EXIT_BREAK then   -- Test for Exit Key

    return 1  -- Exit

  else

    return 0

  end

end

return { run=run_func }


getValue(source)

Returns the value of a source

Parameters:

source

can be a constant (i.e STICK_RUDDER)

or a string name (i.e. “altitude”)

Returns:

number

value of source or nil if value is not available.

Status:

current

Introduced in 2.0.0

supported source constants

name

MIXSRC_FIRST_INPUT

MIXSRC_Rud

MIXSRC_Ele

MIXSRC_Thr

MIXSRC_Ail

MIXSRC_SA

MIXSRC_SB

MIXSRC_SC

MIXSRC_SD

MIXSRC_SE

MIXSRC_SF

MIXSRC_CH1

This may be  a beter reference point until 2.0.6 http://www.rcgroups.com/forums/showpost.php?p=28897780&postcount=298

Supported source names are:

name

value

example

"altitude"

barometric altitude in meters

120.56

"altitude-max"

max barometric altitude in meters

120.56

"vario"

vario speed in m/s

120.56

"tx-voltage"

Tx voltage in V

120.56

"rpm"

RPMs

120.56

"latitude"

GPS latitude in degrees, North is positive

45.5667

"longitude"

GPS longitude in degrees, East is positive

120.5677

"pilot-latitude"

first GPS value (usually pilot position) format same as "latitude"

-12.567

"pilot-longitude"

first GPS value (usually pilot position) format same as "longitude"

-0.567

Names are case sensitive eg getValue("altitude")


playFile(path)

Plays a file from the SD card

Parameters:

path

full path to wav file (i.e. “/SOUNDS/en/system/tada.wav”)

Returns:

none

value of source or nil if value is not available.

Status:

current

introduced in 2.0.0

Introduced in 2.1.0

If you use a relative path, will append current language to the path.


popupInput(title, event, input, min, max)

Raises a popup on screen that allows uses input

Parameters:

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 be decremented by the - key

max

(number) max value that input can be decremented by the - key

Returns:

result

(string) “OK” ENT pressed

(string) “CANCEL” EXIT pressed

(number) the result of the input adjustment

Status:

current

introduced in 2.0.0

Example: Pressing +/- will increment/decrement number.

local result = 0

local swtch = 0

local function run_func(event)

  lcd.lock()

  lcd.clear()

  lcd.drawScreenTitle("popupInput",1,1)

  result = popupInput("Input", event, swtch, -10, 10)

  lcd.drawNumber(62,24,swtch,0)

  if result == "OK" then

    return 0 -- ignore

  elseif result == "CANCEL" then

    return 1 -- exit program

  else

    swtch = result   -- it is number

    return 0

  end

end 

return { run=run_func }

 


getGeneralSettings()

Returns a table containing battMin and battMax

Parameters:

none

Returns:

value

(general-table) Min and Max battery value

Status:

Current

Introduced 2.0.6

General Table Format

battMin

(number) Minimum Battery

battMax

(number) Maximum Battery

Example: Display Min and Max Battery volatge

local settings=getGeneralSettings()

lcd.drawNumber(10,20,settings.battMin,LEFT+MIDSIZE)

lcd.drawNumber(100,20,settings.battMax,LEFT+MIDSIZE)


playNumber(number, unit, att)

Parameters:

number

(integer)

unit

(integer)

att

(integer)

Returns:

0

Status:

Current

Introduced 2.0.0

Unit table

Unit

Sound

Description

0

1

Volts

0115.wav

2

Amperes

0118.wav

3

Meters per Second

0120.wav

4

5

Speed

KMH or Knots depending on radio setting (imperial/metric)

6

Height

Number is meters. Converted to feet for Imperial.

7

Temperature

Number is celcius. converted to F if radio is in Imperial.

8

Percent

9

Millions

10

MH

11

Watts

12

DB

13

Feet

14

Speed

KMH or Knots depending on radio setting (imperial/metric)

15

Hours

16

Minutes

17

Seconds

18

RPM

19

Gee

20

Degrees

21

22

23

Point Zero

24

Point two

25

Point four

26

Point six

27

Point eight

Attr

ATTR

PREC1

Add decimal place to number. ie if number is 58, will announce 5.8


defaultStick(channel)

Get stick that is assigned to a channel. See Default Channel Order in General Settings

Parameters:

number

(number) Channel Number

Returns:

value

(number) Stick assigned to this channel

Status:

Current

Introduced 2.0.0


defaultChannel(stick)

Get channel assigned to stick. See Default Channel Order in General Settings

Parameters:

stick

(number) Stick Number

Returns:

nil

value

(number) Channel Number

Status:

Current

Introduced 2.0.0


killEvents(key-event)

Removes key-event from event

Parameters:

key-event

(number) Key events to remove (mask)

Returns:

nil

Status:

Current

introduced in 2.0.0

Key Events

comments

EVT_MENU_BREAK

EVT_PAGE_BREAK

EVT_PAGE_LONG

EVT_ENTER_BREAK

EVT_ENTER_LONG

EVT_EXIT_BREAK

EVT_PLUS_BREAK

EVT_MINUS_BREAK

EVT_PLUS_FIRST

EVT_MINUS_FIRST

EVT_PLUS_RPT

EVT_MINUS_RPT


getFieldInfo(fieldname)


Gets detailed information about field.

Parameters:

fieldname

(string) short field name. see LUA Source List

Returns:

value

(field-table) details of field

Status:

Current

2.0.8

Field Table Format

id

(number) Field index

name

(string) Short Name

desc

(string) Long description for field


playDuration(duration,playtime)

Parameters:

duration

(integer)

playtime

(boolean)

Returns:

none

Status:

Planned

2.1.0


playTone(frequency, length, pause, attr, frequnecyInc)

Parameters:

frequency

(integer) Frequency of tone, in Hertz

length

(integer) Length of tone in ms

pause

(integer)

attr

(integer) See table below

frequencyInc

(integer)

Returns:

none

Status:

Planned

2.1.0

Attr

Description

PLAY_NOW

Play immediately

PLAY_BACKGROUND

Place in background queue


Lua Model Functions

Please note that writing (even the same value) to model settings will cause the a write to EEPROM. This could occur within 5 seconds of the change or when model is unloaded or radio switched off.

model.getTimer(timer)

Returns model timer

Parameters:

timer

(number) timer number

Returns:

nil

unknown timer number.

value

(timer-table) timer data

Status:

current

introduced in 2.0.0

Timer Table Format

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

Example:

--get timer data into tim1
tim1
= model.getTimer(1)
--access returned values as tim1.<value>
if tim1.value > 0 then
   
--do something
end


model.setTimer(timer, data)

Sets model timer

Parameters:

timer

(number) timer number

data

(timer-table) new timer data. See

Returns:

none

Status:

current

introduced in 2.0.0

see model.getTimer(timer) for timer table format


model.getInputsCount(input)

Returns number of lines for given input

Parameters:

input

(unsigned number) input number (0 -> max inputs - 1)

Returns:

value

(unsigned number) number of configured lines for given input.

Status:

current

introduced in 2.0.0


model.getInput(input, line)

Returns input data for given input and line number

Parameters:

input

(unsigned number) input number (0 -> max inputs - 1)

line

(unsigned number) input line (0 -> max lines - 1)

Returns:

value

(input-table) input data

Status:

current

introduced in 2.0.0

Input-Table Format

name

(string) input line name

source

(number) input source index

weight

(number) input weight

offset

(number) input offset


model.insertInput(input, line, value)

Inserts an Input at specified line

Parameters:

input

(unsigned number) input number (0 -> max inputs - 1)

line

(unsigned number) input line (0 -> max lines - 1)

value

(input-table) see model.getInput(input, line)

Returns:

none

Status:

current

introduced in 2.0.0


model.deleteInput(input, line)

Delete line from specified input

Parameters:

input

(unsigned number) input number (0 -> max inputs - 1)

line

(unsigned number) input line (0 -> max lines - 1)

Returns:

none

Status:

current

introduced in 2.0.0


model.deleteInputs()

Delete all Inputs

Parameters:

none

Returns:

none

Status:

current

introduced in 2.0.0


model.defaultInputs()

Set all inputs to Defaults.

Parameters:

none

Returns:

none

Status:

current

introduced in 2.0.0

Example:

local function run_func(event)

  model.defaultInputs()

  return 1

end

return { run=run_func}

Radio before script is run

Radio after script is run


model.getMixesCount(channel)

Get the number of Mixer lines that the specified Channel has

Parameters:

channel

(number) Channel number to look up. Zero numbered (i.e. CH1 is 0)

Returns:

value

(number) number of line

Status:

current

introduced in 2.0.0

Example

  mix = model.getMixesCount(0)

  lcd.drawNumber(10,20,mix,LEFT+MIDSIZE)

Radio Configuration

Result


model.getMix(channel, line)

Get configuration for specified Mix

Parameters:

channel

(number) Channel number to look up. Zero numbered (i.e. CH1 is 0)

line

(number) line number of Mix. Zero numbered.

Returns:

value

(mix-table) line details

nil

invalid parameters

Status:

current

introduced in 2.0.0

Mix-Table Format

name

(string)

source

(number)

weight

(number) Weight value or gVar1..9 = 4096..4114, -gVar1..9 = 4095.. 4087

offset

(number) Offset value or gVar1..9 = 4096..4114, -gVar1..9 = 4095.. 4087

switch

(number) Switch Number

multiplex

(number) 0=ADD, 1=MULTIPLY, 2=REPLACE


model.insertMix(channel, mix, value)

Insert a mixer line into Channel

Parameters:

channel

(number) Channel number to look up. Zero numbered (i.e. CH1 is 0)

line

(number) line number to insert. Existing line will be moved down one line

value

(mix-table) see model.getMix(channel, line)

Returns:

nil

Status:

current

introduced in 2.0.0


model.deleteMix(channel, mix)

Delete mixer line from specified Channel

Parameters:

channel

(number) Channel number to look up. Zero numbered (i.e. CH1 is 0)

line

(number) line number to delete. Existing lines will be moved up one line

Returns:

nil

Status:

current

introduced in 2.0.0


model.deleteMixes()

Removes ALL lines from ALL channels

Parameters:

none

Returns:

none

Status:

current

introduced in 2.0.0


model.getLogicalSwitch(switch)

Get Logical Switch parameters

Parameters:

switch

(number) Logical Switch Number

Returns:

value

(switch-table)

Status:

current

introduced in 2.0.0

Switch-Table Format

func

(number)

v1

(number)

v2

(number)

v3

(number)

and

(number)

delay

(number)

duration

(number)


model.setLogicalSwitch(switch, value)

Set Logical Switch parameters

Parameters:

switch

(number) Logical Switch Number

value

(switch-table) See model.getLogicalSwitch(switch).

Returns:

none

Status:

current

introduced in 2.0.0


model.getCustomFunction(function)

Get Special Functions

Parameters:

function

(number) Special Function Number

Returns:

value

(function-table)

Status:

current

introduced in 2.0.0

Function-Table Format

switch

(number) Switch Number

func

(number) Action Number

name

(string) Name of track to play, only returned if Action is play track or sound.

value

(number)

mode

(number)

param

(number)

active

(number) 0 = !Enabled, 1 = Enabled


Function Table. Caution, table behavior changes depending on the function. Need to determine a good way to show this information. The sound orientated functions in particular affect the usages of fields.

Unused variables will contain values from a previous function i.e. if you change a function and value is no longer used, it will still contain the value from the old function.

Action

Parameter

func

value

mode

param

Safety CHx

125..-125

0

Parameter Value

Channel 0-21

Trainer

1

0

Trainer RUD

1

1

Trainer ELE

1

2

Trainer THR

1

3

Trainer AIL

1

4

Instant Trim

2

Play Sound

10

Reset

Timer1

3

0

Reset

Timer2

3

1

Reset

All

3

2

Reset

Telemetry

3

3

Set Timer 1

0..n

4

Parameter Value

0

Set Timer 2

0..n

4

1

Vario

18

Play Value

- - -

12

Start Logs

0.0..25.5

20

Parameter value * 10

Volume

source

6

See source table

Backlight

21

Background Music

Background Music Pause

17