Widget Scripts
Purpose
Widget scripts are available on radios equipped with color LCD. They are designed to run constantly in the background performing various tasks. Widget scripts are mostly used to extend EdgeTX functionality via Widgets that are placed by the user on Main Views. They are the equivalent of Telemetry Scripts on radios equipped with B&W LCD.
Most of the time, widget scripts show some info in a Widget's zone in one of the user defined Main Views. They cannot receive direct input from the user via key events with exception of being displayed in so called Full Screen mode. Full screen mode can be entered by selecting the widget, pressing ENTER and selecting Full screen from the widget's contextual menu, or by double tapping the widget on radios with a touch screen. Full screen mode can be exited by long pressing the EXIT (RTN) button, or by calling the Lua function lcd.exitFullScreen().
Each model can have up to nine Main Views, with up to 8 widgets per screen, depending on their size and layout. Each instance of a widget has its own options table.
!!! warning Widget scripts are only available on radios with color LCD screens, such as e.g. FrSky X10 or X12, Radiomaster TX16S, Jumper T16 or T18, Flysky NV14, etc. Read more about supported radios.
Execution & Lifetime
All widget scripts on the SD card are loaded into memory when the model is selected, even widgets that are not used. This has the side effect that any global functions defined in a widget script will always be available to other widget scripts. It also means that any Widget Script placed in the proper location on the SD card will consume part of the radio's memory - even if it is not being used.
!!! warning It is important to either keep Widget Scripts small, or to use Lua's loadScript() function to load code dynamically
Script executes until:
- it misbehaves (e.g. too long runtime, run-time error, or low memory)
- a One-Time script is running. When the One-Time script finishes execution, the Widget Script resumes execution.
File Location
Widget scripts are located on the SD card, each one in their specific folder:
/WIDGETS/<folder name>/
!!! warning Widget script folder name length must be 8 characters or less
Widget script name is constant and has to be named main.lua
!!! info Example of proper Widget script placement to be registered by EdgeTX as a valid Widget script available to the user in the Widgets selection menu:
/WIDGETS/MYWGT/main.lua
!!! info Try to use a unique folder name. In case of a naming clash, the previously installed widget will be overwritten.
Interface
Every Widget Script must include a return statement at the end, defining its interface to EdgeTX. This statement returns a table with the following fields:
Field
Type
Required
Description
name
string
true
This variable holds a name that is displayed to the user as the Widget script's name in the available Widgets list.
!!! warning The name length must be 10 characters or less.
Field
Type
Required
Description
options
table
false
Options table is used to store the Widget's options available to the EdgeTX user via the Widget's Settings menu. To see valid options read Widget Options Constants.
!!! info options table is passed to create function when invoked and then stored in Lua. Changing options table values while the Widget script is running has no effect. This table is designed to be changed via EdgeTX system menus.
!!! info If options is changed by the user in the Widget Settings menu, then update will be called with a new options table, unaffected by any changes made by Lua code to the old options table.
Field
Type
Required
Description
create
function
true
Function is called once when the widget instance is registered (started).
Parameters
Parameter
Description
zone table
This parameter will hold visible dimensions of Widget (height & width)
options table
Initial options table as described above
Return values
Returns
Description
widget table
Create function will return a table that has to be later passed to update, background, and refresh functions, allowing access to the widget's unique variables.
!!! info The size of the widget's zone area is as follows:
!!! info If local variables are declared outside functions in the widget script, then they are shared between all instances of the widget. Therefore, local variables that are private for each instance should be added to the widget table in the create function before returning the widget table to EdgeTX.
Field
Type
Required
Description
update
function
false
This function is called when the Widget's Settings are changed by the user. It is mostly used to modify Widget Script variables or behaviour based on the options values entered by the user.
Parameters
Parameter
Description
widget table
Widget's table returned by the create function, described above.
options table
Initial options table as described above
Return values none
Field
Type
Required
Description
background
function
false
This function is called periodically when the widget instance is NOT VISIBLE.
Parameters
Parameter
Description
widget table
Widget's table returned by the create function, described above.
Return values none
Field
Type
Required
Description
refresh
function
true
This function is called periodically when the widget instance IS VISIBLE.
Parameters
Parameter
Description
widget table
Widget's table returned by the create function, described above.
event number
- When the Widget Script is in full screen mode, then
eventis either 0, a key event value, or a touch event value. - When the widget is not in full screen mode, then
eventisnil
See Key Events.
touchState table
This parameter is only present when the radio is equipped with a touch interface and event is a touch event.
- If
eventis a touch event value, thentouchStateis a table. Otherwise, it isnil. - When the widget is not in full screen mode then
touchStateisnil
See Touch State Events.
Return values none
!!! info if you want the background function to run when the widget is visible, then call it from the refresh function.