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

Was this helpful?

  1. Part III - OpenTX Lua API Reference
  2. General Functions

getValue(source)

PreviousgetTime()NextgetVersion()

Last updated 4 years ago

Was this helpful?

Returns the value of a source.

The list of valid sources is available:

  • for OpenTX 2.0.x at

  • for OpenTX 2.1.x at (depreciated)

  • for OpenTX 2.1.x Taranis and Taranis Plus at

  • for OpenTX 2.1.x Taranis X9E at

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

  • 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

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.

Examples

local function run(e)
  --
  -- NOTE: analog values (e.g. sticks and sliders) typically range from -1024 to +1024
  --       divide by 10.24 to scale into -100% thru +100%
  --       or add 1024 and divide by 20.48 to scale into 0% thru 100%
  --
  local rsValue = getValue('rs')
  local thrValue = getValue('thr')
  lcd.clear()
  lcd.drawText(1, 1, "getvalue() example",0)
  lcd.drawText(1, 11, "rsValue: ", 0)
  lcd.drawText(lcd.getLastPos() + 2, 11, rsValue, 0)
  lcd.drawText(120, 11, "percent: ", 0)
  lcd.drawNumber(lcd.getLastPos() + 32, 11, rsValue / 10.24, PREC2)
  lcd.drawText(1, 21, "thrValue: ", 0)
  lcd.drawText(lcd.getLastPos() + 2, 21, thrValue, 0)
  lcd.drawText(120, 21, "percent: ", 0)
  lcd.drawNumber(lcd.getLastPos() + 32, 21, (thrValue + 1024) / 20.48, PREC2)
end

return{run=run}

http://downloads-20.open-tx.org/firmware/lua_fields.txt
http://downloads-21.open-tx.org/firmware/lua_fields.txt
http://downloads-21.open-tx.org/firmware/lua_fields_taranis.txt
http://downloads-21.open-tx.org/firmware/lua_fields_taranis_x9e.txt
general/getValue-example