Skip to content

2.0 The First Self‐Coded Widget

Udo edited this page Nov 19, 2024 · 5 revisions

General

Now that the foundation is set, it’s time to program a small widget on your own.
I thought a bit about what the goal should be.

There always seems to be demand for a more customized form of telemetry display.
Sometimes it’s the color, other times the font size, or even the background that users want to modify compared to the standard widget.
For example, I often find it a waste of space if only one value is displayed in a widget, and I like having more information per "frame."

This gave me the idea to develop a small widget for this chapter that can display two values in one frame, allowing the programmer to control color representation and add a bit of "graphics" to enhance the presentation.

Lothar also suggested that we make maximum and minimum values accessible via switch, and with that, the theme for Chapter 2 was found.
The goal is to develop a widget that fits into the small frame of the standard home screen and displays two lines.

The final result should look something like this:

image

Once you understand the basics of widget programming, it’s not a huge task to implement something like this on your own.

I hope that the topic of telemetry display is of broad interest.





The Journey is the Goal

... says Confucius, and I intend to follow that principle.
The widget mentioned above presents some tasks for beginners to tackle:

  • Sensor values need to be queried.
  • Display options (colors, text sizes) should be addressed.
  • Small graphics should be placed within the widget.
  • Switch positions need to be evaluated.
    ….

To avoid overloading the first attempt, I’ll divide this into three stages, allowing for widgets with progressively greater functionality to be built upon one another:

Level 1 Simple display of two lines of text in arbitrarily chosen colors.

Level 2 Telemetry sensors – defining, querying, and displaying values, taking the display into account.

Level 3 Querying switch values, conditionally querying min/max telemetry values, displaying bitmaps.


The complexity of each widget should remain manageable. The widgets are designed to keep the code understandable.
Under these conditions, the initial code will be somewhat "pragmatic" (another term might be "suboptimal"). The widget will work, and getting started will be easy.

Optimization potential will be addressed in the following chapter.

For these reasons, I won’t be adding configurability just yet (e.g., which sensors to display, color schemes, etc.).
Everything will initially be hardcoded.

Configuration options will be described in the later chapter on "Form Handling."


As mentioned in Chapter 1, I assume basic programming knowledge is present.
If not, I recommend a general Lua beginner’s tutorial.

If I feel that certain Ethos-Lua functionalities need closer examination, or if a topic might be interesting for those coming from other programming languages, I’ll add a small, spontaneous detour.

Clone this wiki locally