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...
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...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This section introduces the types of Lua scripts supported by EdgeTX and how they may be used.
This section describes various constants that are provided for Lua by EdgeTX.
Lua makes it easy to load and unload code modules on the fly, to save memory or to provide program extensions.
chunkf1f2c-- /SCRIPTS/TestScript.lua
local c = ...
local function f(x)
return x + c
end
return flocal chunk = loadScript("/SCRIPTS/TestScript.lua")
local f1 = chunk(1)
local y = f1(5)
-- y = 5 + 1
local f2 = chunk(3)
local z = f2(5)
-- z = 5 + 3In addition to the key events described in the previous section, radios with a color touch screen also provide touch events to the widget scripts.
local function init()
-- Called once when the script is loaded
end
local function run()
-- Called periodically while the Special Function switch is on
end
local function background()
-- Called periodically while the Special Function switch is off
end
return { run=run, background=background, init=init }local function init()
-- init is called once when model is loaded
end
local function run(event)
-- run is called periodically only when screen is visible
-- A non-zero return value will halt the script
return x
end
return { run=run, init=init }local function init()
-- init is called once when model is loaded
end
local function background()
-- background is called periodically
end
local function run(event)
-- run is called periodically only when screen is visible
end
return { run = run, background = background, init = init }monbitmapindex (unsigned number) output number (use 0 for CH1)function (unsigned number) custom function number (use 0 for CF1)sensor (unsigned number) sensor number (use 0 for sensor 1)timer (number) timer index (0 for Timer 1)input (unsigned number) input number (use 0 for Input1)title (string) text to displayswitch (unsigned number) logical switch number (use 0 for LS1)frequency (number) tone frequency in Hz (from 150 to 15000) 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 return 0 on radio without rotary encoder 1 - Wrong number of points
2 - Invalid Curve number
3 - Cuve does not fit anymore
4 - point of out of index
5 - x value not monotonically increasing
6 - y value not in range [-100;100]
7 - extra values for y are set
8 - extra values for x are setlocal function counter(start, step)
local x = start
return function()
local y = x
x = x + step
return y
end
endlocal function match(x, ...)
for i, y in ipairs({...}) do
if x == y then
return true
end
end
return false
end params = {}
params["x"] = {-100, -34, 77, 100}
params["y"] = {-70, 20, -89, -100}
params["smooth"] = true
params["type"] = 1
val = model.setCurve(2, params) val = model.setCurve(3, {smooth=true, y={-100, -50, 0, 50, 100, 80}})CH1 [I4]Ail Weight(+100%)
:= LUA4b Weight(+100%)local input =
{
{ "Strength", SOURCE}, -- user selects source (typically slider or knob)
{ "Interval", VALUE, 0, 100, 0 } -- interval value, default = 0.
}
local output = { "Val1", "Val2" }
local function init()
-- Called once when the script is loaded
end
local function run(Strength, Interval) -- Must match input table
local v1, v2
-- Called periodically
return v1, v2 -- Must match output table
end
return { input=input, output=output, run=run, init=init }{ "<name>", SOURCE }{ "<name>", VALUE, <min>, <max>, <default> }{ "<name1>", "<name2>" }index (unsigned number) flight mode number (use 0 for FM0) fun, err = loadScript("/SCRIPTS/FUNCTIONS/print.lua")
if (fun ~= nil) then
fun("Hello from loadScript()")
else
print(err)
endlocal 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 }subTypename (string) field name
version: 2.4.0
radio: tx16s-simu
maj: 2
minor: 4
rev: 0
osname: EdgeTXlocal name = "WidgetName"
-- Create a table with default options
-- Options can be changed by the user from the Widget Settings menu
-- Notice that each line is a table inside { }
local options = {
{ "Source", SOURCE, 1 },
-- BOOL is actually not a boolean, but toggles between 0 and 1
{ "Boolean", BOOL, 1 },
{ "Value", VALUE, 1, 0, 10},
{ "Color", COLOR, ORANGE },
}
local function create(zone, options)
-- Runs one time when the widget instance is registered
-- Store zone and options in the widget table for later use
local widget = {
zone = zone,
options = options
}
-- Add local variables to the widget table,
-- unless you want to share with other instances!
widget.someVariable = 3
-- Return widget table to EdgeTX
return widget
end
local function update(widget, options)
-- Runs if options are changed from the Widget Settings menu
widget.options = options
end
local function background(widget)
-- Runs periodically only when widget instance is not visible
end
local function refresh(widget, event, touchState)
-- Runs periodically only when widget instance is visible
-- If fullscreen, then event is 0 or event value, otherwise nil
end
return {
name = name,
options = options,
create = create,
update = update,
refresh = refresh,
background = background
}zone.h