All pages
Powered by GitBook
1 of 41

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...

General Functions

GREY()

Returns gray value which can be used in LCD functions

@status current Introduced in 2.0.13

Parameters

none

Return value

  • (number) a value that represents amount of greyness (from 0 to 15)

Notice

Only available on Taranis

getRtcTime()

Return current RTC system date as unix timstamp (in seconds since 1. Jan 1970)

Please note the RTC timestamp is kept internally as a 32bit integer, which will overflow in 2038.

Parameters

none

Return value

  • number Number of seconds elapsed since 1. Jan 1970

crossfireTelemetryPush()

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

Parameters

  • command command

  • data table of data bytes

Return value

  • boolean data queued in output buffer or not.

  • nil incorrect telemetry protocol.

multiBuffer(address[,value])

This function reads/writes the Multi protocol buffer to interact with a protocol².

@status current Introduced in 2.3.2

Parameters

  • address to read/write in the buffer

    @param (optional): value to write in the buffer

Return value

  • buffer value (number)

getAvailableMemory()

Get available memory remaining in the Heap for Lua.

Parameters

none

Return value

  • usage (number) a value returned in b

chdir(directory)

Change the working directory

@status current Introduced in 2.3.0

Parameters

  • directory (string) New working directory

Return value

none

getUsage()

Get percent of already used Lua instructions in current script execution cycle.

@status current Introduced in 2.2.1

Parameters

none

Return value

  • usage (number) a value from 0 to 100 (percent)

killEvents(key)

Stops key state machine. See Key Events for the detailed description.

@status current Introduced in 2.0.0

Parameters

  • key (number) key to be killed, can also include event type (only the key part is used)

Return value

none

defaultChannel(stick)

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

@status current Introduced in 2.0.0

Parameters

  • stick (number) stick number (from 0 to 3)

playFile(name)

Play a file from the SD card

@status current Introduced in 2.0.0, changed in 2.1.0

Parameters

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

sportTelemetryPop()

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

Parameters

none

playDuration(duration [, hourFormat])

Play a time value (text to speech)

@status current Introduced in 2.1.0

Parameters

  • duration (number) number of seconds to play. Only integral part is used.

getRAS()

Return the RAS value or nil if no valid hardware found

@status current Introduced in 2.2.0

Parameters

none

crossfireTelemetryPop()

Pops a received Crossfire Telemetry packet from the queue.

@status current Introduced in 2.2.0

Parameters

none

resetGlobalTimer([type])

Resets the radio global timer to 0.

@status current Introduced in 2.2.2, param added in 2.3

Parameters

  • (optional) : if set to 'all', throttle ,throttle percent and session timers are reset too

setSerialBaudrate(baudrate)

Set baudrate for serial port(s) affected to LUA

@status current Introduced in 2.3.12

Parameters

baudrate Desired baudrate

serialRead([num])

@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

Parameters

none

getRotEncSpeed()

Return rotary encoder current speed

@status current Introduced in 2.3.10

Parameters

none

Return value
  • number channel assigned to this stick (from 0 to 3)

  • nil stick not found

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)

Return value

none

Return value
  • 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)

hourFormat (number):

  • 0 or not present play format: minutes and seconds.

  • != 0 play format: hours, minutes and seconds.

Return value

none

Return value
  • 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

Notice

RAS was called SWR in the past

Return value
  • nil queue does not contain any (or enough) bytes to form a whole packet

  • multiple returns 2 values:

    • command (number)

    • packet (table) data bytes

Return value

none

Return value
  • str string. Empty if no new characters were available.

getFlightMode(mode)

Return flight mode data.

@status current Introduced in 2.1.7

Parameters

  • 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.

Return value

  • multiple returns 2 values:

    • (number) (current) flight mode number (0 - 8)

    • (string) (current) flight mode name

playHaptic(duration, pause [, flags])

Generate haptic feedback

@status current Introduced in 2.2.0

Parameters

  • 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

Return value

none

accessTelemetryPush()

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

Parameters

  • module module index (0 = internal, 1 = external)

  • rxUid receiver index

  • sensorId physical sensor ID

  • frameId frame ID

  • dataId data ID

  • value value

Return value

  • boolean data queued in output buffer or not.

defaultStick(channel)

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

@status current Introduced in 2.0.0

Parameters

  • channel (number) channel number (0 means CH1)

Return value

  • number Stick assigned to this channel (from 0 to 3)

serialWrite(str)

@param str (string) String to be written to the serial port.

Writes a string to the serial port. The string is allowed to contain any character, including 0.

@status current Introduced in 2.3.10

Parameters

none

Return value

none

sportTelemetryPush()

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

Parameters

  • sensorId physical sensor ID

  • frameId frame ID

  • dataId data ID

  • value value

Return value

  • boolean data queued in output buffer or not.

  • nil incorrect telemetry protocol.

getRSSI()

Get RSSI value as well as low and critical RSSI alarm levels (in dB)

@status current Introduced in 2.2.0

Parameters

none

Return value

  • rssi RSSI value (0 if no link)

  • alarm_low Configured low RSSI alarm level

  • alarm_crit Configured critical RSSI alarm level

popupConfirmation(title, message, event)

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

Parameters

  • 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)

Return value

  • "CANCEL" user pushed EXIT key

Notice

Use only from stand-alone and telemetry scripts.

Return value
  • number in list: ROTENC_LOWSPEED, ROTENC_MIDSPEED, ROTENC_HIGHSPEED

      return 0 on radio without rotary encoder

Return value

none

              if set to 'session', radio session timer is reset too
              if set to 'ttimer', radio throttle timer is reset too
              if set to  'tptimer', radio throttle percent timer is reset too

loadScript(file [, mode], [,env])

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

Example

Parameters

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

Return value

  • 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.

Notice

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()).

getTxGPS()

Return the internal GPS position or nil if no valid hardware found

@status current Introduced in 2.2.2

Parameters

none

Return value

  • table representing the current radio position

    • lat (number) internal GPS latitude, positive is North

    • lon (number) internal GPS longitude, positive is East

getGeneralSettings()

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.

Parameters

none

Return value

  • table with elements:

    • battWarn (number) radio battery range - warning value

    • battMin (number) radio battery range - minimum value

getGlobalTimer()

Returns radio timers

@status current Introduced added in 2.3.0.

Parameters

none

Return value

  • table with elements:

  • gtimer (number) radio global timer in seconds

  • session (number) radio session in seconds

getFieldInfo(name)

Return detailed information about field (source)

The list of valid sources is available:

getVersion()

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

Example

This example also runs in OpenTX versions where the function returned only one value:

Output of the above script in simulator:

playTone(frequency, duration, pause [, flags [, freqIncr]])

Play a tone

@status current Introduced in 2.1.0

Parameters

  • frequency (number) tone frequency in Hz (from 150 to 15000)

popupWarning(title, event)

Raises a pop-up on screen that shows a warning

@status current Introduced in 2.2.0

Parameters

  • title (string) text to display

getDateTime()

Return current system date and time that is kept by the RTC unit

Parameters

none

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

Raises a pop-up on screen that allows uses input

@status current Introduced in 2.0.0

Parameters

  • title (string) text to display

  fun, err = loadScript("/SCRIPTS/FUNCTIONS/print.lua")
  if (fun ~= nil) then
     fun("Hello from loadScript()")
  else
     print(err)
  end
  • 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().

  • '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

  • 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)

  • ttimer (number) radio throttle timer in seconds

  • tptimer (number) radio throttle percent timer in seconds

  • 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.

  • Return value

    none

    event (number) the event variable that is passed in from the Run function (key pressed)

    Return value

    • "CANCEL" user pushed EXIT key

    Notice

    Use only from stand-alone and telemetry scripts.

    Return value
    • 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

    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

  • Return value

    • number result of the input adjustment

    • "OK" user pushed ENT key

    • "CANCEL" user pushed EXIT key

    Notice

    Use only from stand-alone and telemetry scripts.

    Parameters

    none

    Return value

    • 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)

    local function run(event)
      local ver, radio, maj, minor, rev, osname = getVersion()
      print("version: "..ver)
      if radio then print ("radio: "..radio) end
      if maj then print ("maj: "..maj) end
      if minor then print ("minor: "..minor) end
      if rev then print ("rev: "..rev) end
      if osname then print ("osname: "..osname) end
      return 1
    end
    
    return {  run=run }
    version: 2.4.0
    radio: tx16s-simu
    maj: 2
    minor: 4
    rev: 0
    osname: EdgeTX

    , , ,

    @status current Introduced in 2.0.8, 'unit' field added in 2.2.0

    Parameters

    • name (string) name of the field

    Return value

    • 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

    OpenTX Version

    Radio

    2.0

    all

    2.1

    X9D and X9D+, X9E

    2.2

    X9D and X9D+, X9E, Horus

    2.3

    setTelemetryValue(id, subID, instance, value [, unit [, precision [, name]]])

    @status current Introduced in 2.2.0

    Parameters

    • 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

    • 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"

    Return value

    • true, if the sensor was just added. In this case the value is ignored (subsequent call will set the value)

    Notice

    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.

    playNumber(value, unit [, attributes])

    Play a numerical value (text to speech)

    @status current Introduced in 2.0.0

    Parameters

    • 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)

    Return value

    none

    PREC2 plays a number with two decimal places (for a number 123 it plays 1.23)

    Full list
    Full list
    X9D and X9D+
    X9E
    X7
    Horus

    getValue(source)

    Returns the value of a source.

    The list of fixed sources:

    OpenTX Version

    Radio

    2.0

    2.1

    ,

    2.2

    , ,

    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

    Parameters

    • source can be an identifier (number) (which was obtained by the getFieldInfo())

      or a name (string) of the source.

    Return value

    • value current source value (number). Zero is returned for:

      • non-existing sources

      • for all telemetry source when the telemetry stream is not received

    Notice

    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.

    getTime()

    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

    Parameters

    none

    Return value
    • number Number of 10ms ticks since the radio was started Example:

      run time: 12.54 seconds, return value: 1254

    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

  • 2.3

    X9D and X9D+, X9E, X7, Horus

    all
    X9D and X9D+
    X9E
    X9D and X9D+
    X9E
    Horus