Lua help, trying to learn, so many questions

openTx has introduced a range of new features, ideas and bling. It is fast becoming the firmware of choice for many users. openTx will run on ALL current hardware platforms, including the gruvin9x and sky9x boards. Work has already started to support the new FrSky X9D radio!
Post Reply
Ivanstein
Posts: 2
Joined: Sat Jun 29, 2019 12:47 am
Country: -

Lua help, trying to learn, so many questions

Post by Ivanstein » Mon Jul 15, 2019 5:09 am

I am trying to learn Lua for Open TX and I am faltering. I have some questions, which are probably obvious to the seasoned programmer.

I would like to reference the BattCheck widget script that comes as part of OpenTX with the Horus.

The fist line is a local variable call:
local shadowed = 0

So, why is this a local variable? It is outside any other functions, so is it necessary to call it local? Does it make it local to the widget script and if not set local becomes obtrusive to the rest of the OS?

Next is a variable set as a table.
local options = {
{ "Sensor", SOURCE, 1 },
{ "Color", COLOR, WHITE },
{ "Shadow", BOOL, 0 }
}

The OpenTX Lua scripting manual (the book) says these are only used in widget creation. Does this mean they are available to all other functions as the script executes, meaning create, update, background and refresh can all pull values from that table?

Also, the table has the key "Sensor", type SOURCE, value (I think??? it doesn't coincide with the book at input table syntax) 1. So, that sets up the table spot for the expected data. Now, here is where I get totally lost....I can't figure out what tells the script to look for the FMVSS sensor and not, for instance, Galt or RSSI.

Ultimately, I would like to figure out a way to read a telemetry value, say RPM, and set a user maximum which is adjustable with a trim switch, calculate the percentage and display it in a widget. I think I can use a global variable for the maximum and a special function to adjust it. However, it would be nice to make that happen in the script because that's what scripts are for (aren't they?)

Thanks for any help. I am sure I will ask more questions as time progresses.


Post Reply

Return to “openTx”