Widgets are small scripts that show some info in a 'zone' in one of the model specific user defined (telemetry) screens. You can define those screens within the telemetry menu on the HORUS.
Each model can have up to five custom screens, with up to 8 widgets per screen, depending on their size and layout. Each instance of a widget has his own custom settings.
Widgets are located on the SD card, each in their specific folder /WIDGETS/<name>/main.lua (name must be in 8 characters or less).
Widgets need to be registered through the telemetry setup menu.
widget create function is called
widget update function is called upon registration and at change of settings in the telemetry setup menu.
widget background function is periodically called when custom telemetry screen is not visible. Notice:
This is different from the way telemetry scripts are handled
widget refresh function is periodically called when custom telemetry screen is visible
widget is stopped and disabled if it misbehaves (too long runtime, error in code, low memory)
all widgets are stopped while one-time script is running (see Lua One-time scripts)
Once registered, widgets are started when the model is loaded.
Every widget must include a return statement at the end, that defines its interface to the rest of OpenTX code. This statement defines:
widget name (name must be a string of 10 characters or less)
widget options array (maximum five options are allowed, 10 character names max, no spaces!)
widget create function
widget update function
script background function
script refresh function
options are only passed through to OpenTX to be used on widget creation. Don't change them during operation, this has no effect.
create() function is called once when widget is loaded and begins execution.
update() function is called once when widget is loaded and begins execution.
background() is called periodically when custom telemetry screen containing widget is not visible.
refresh() function is called periodically when custom telemetry screen containing wodget is visible.
in the example given, you can see that no global variables or functions are needed to operate the widget.
variables that are used throughout the widget, can best be declared inside the create function as local variables
those local variablkes can then be passed through to the other functions as an element of the widget array that is returned