Your first widget¶
We'll build a widget that shows any telemetry value the pilot chooses, in a font that scales with the widget size. Along the way it uses the four callbacks almost every widget needs: create, wakeup, paint and configure, plus read/write to remember the settings.
1. Create the folder¶
Scripts live in the scripts folder of the radio's storage, one folder per script:
On a radio connected over USB this is the scripts folder on the SD card (or internal storage, depending on the radio). In the simulator it is the scripts folder inside the simulator's radio directory (see Web simulator and FrSky Suite).
2. Write main.lua¶
3. Run it¶
- Copy the
bigvaluefolder intoscripts/(radio or simulator). - Restart the radio or simulator. Scripts are only loaded at boot.
- Long-press a home screen widget slot (or edit a screen in Displays), choose Big Value, then open its configuration and pick a source such as RSSI or a telemetry sensor.
Nothing shows up?
- The folder must contain
main.luaand that file mustreturn { init = init }. keymust be 7 characters or fewer, and unique across all installed widgets.- Open the simulator's Console panel: a syntax error in
main.luais printed there at boot.
4. What just happened¶
| Callback | Called | What our widget does |
|---|---|---|
create() |
Once, when the widget is placed or loaded with the model | Returns the state table |
read(widget) |
After create, when settings are restored | Restores the chosen source |
wakeup(widget) |
Repeatedly, many times a second, even when nothing changes | Polls the value; calls lcd.invalidate() only on change |
paint(widget) |
After lcd.invalidate(), and when Ethos needs a redraw |
Draws the text |
configure(widget) |
When the pilot opens the widget's settings | Builds a form |
write(widget) |
When settings need saving (after configure) | Stores the source |
The key idea is the split between wakeup (cheap, frequent, decides whether anything changed) and paint (draws, only when asked). Getting this right keeps scripts smooth. See Saving CPU.
Next steps¶
- Script types & lifecycle: every callback for every script type.
- Drawing on screen: colors, fonts, bitmaps, theme colors.
- Telemetry value widget: this widget grown up, with min/max tracking, colors, and alarm thresholds.