LUA Programming for Jeti – Considerations

While it is relatively easy, there is a few things we need to take into consideration when writing LUA applications for Jeti -24 transmitters.

It has to be said right at the start, any of these rules and / or limitations might change on a firmware update. I know there are some limitations that are bugging me.

Rules of engagement

The basic rules are simple at the moment when running on transmitters firmware 4.10:

  • Maximum of 10 applications running per model.
  • One application can have 2 forms.
  • One form can have 127 sub-forms.
  • Max 10 controls (LUA switches), either one application with 10 controls or 10 applications with one control each or anything in between.
  • One application can have maximum of 2 telemetry controls.
  • LUA version used in firmware 4.10 is 5.3.1 (Good to know when googling for answers!)
  • All applications must be inside /Apps -folder on the SD-card.
  • Filename of application-file has to be in 8.3 format. So no “My_first_cool_app.lua” here.

All of the above can be found in the LUA API documentation. The current API can be found from Jetimodels site here. (Zip-file, containing quite a lot of examples to get you going.)

LUA code?

The actual code for LUA is relatively easy to read, there is a clear structure and order in it. If not elsewhere You will notice that when wondering in what order for example telemetry window initialization have to be compared to loop. Examples and trial & error are really good in this.

some_lua

One good advice: Use the print() function! When examining if application execution is going where you want it to go you can insert a line with print(“This just got done!”) in suitable places to find out where the execution might go wrong.

All these print(“Text here”) will be printed to debug screen. It truly is your friend.

What not to do with LUA + Jeti

Well. Jeti has some safety measures lined up for us coders who have more enthusiasm than knowledge. When writing bad code especially inside the “local function loop()” I got the transmitter to freeze once. There is a possibility I did not wait long enough but if this happens and there is 20 000 instructions available for callback (like printform, loop etc). If this limit is reached the application is killed by transmitter. And yes, I’ve seen that too :)

Personal advice

While I’m also a total novice I can point out a few things. It might be easier to build the application piece by piece, testing the function after every add-on. While it sounds time-consuming to upload a script to transmitter, test it, modify the code and repeat it actually is not.

Basic LUA-code can be tested also online on pages like repl.it but keep in mind the differences in LUA versions, missing of all system-libraries, no possibility to do for example lcdDraw, buttons, switches etc. But for example checking what’s wrong with you loops mathematical functions it might be a good help.

A good editor is a real plus. Do not use wordpad etc in windows, use notepad, I prefer notepad++ (from here) due the possibility of LUA highlighting, auto indent and indent on demand. All this makes code-writing more pleasant and faster, not to mention easier for others to read.

Last but not least. Google. It is amazing what can be done with it :)

And one more thing: If I can do it, so can you!

The whole point of LUA in Jeti?

As I see it:

  • To get some by user missing functions to transmitters by users
  • To share applications
  • And simply, to have a hobby

And please do remember one thing. While xkcd is fun they are not always right! :)

programming-alcohol-chart

(Source: xkcd.com)

Leave a Reply

Your email address will not be published. Required fields are marked *