Thread Tools
Nov 23, 2021, 04:27 PM
Registered User
Jet_Flyer's Avatar
Thread OP
New Product

FrSky ETHOS Lua Script Programming


FrSky ETHOS Lua Script Programming

This thread is dedicated to the discussion of the ETHOS Lua programming. Lua scripts allows users to extend ETHOS with custom features.

ETHOS Lua

The Lua interpreter embedded inside ETHOS is based on LUA 5.4.3. and is packaged with those libraries:

* basic library
* table library
* io library
* os library
* math library

ETHOS Lua Documentation

The ETHOS Lua documentation can be downloaded from the ETHOS release files 1.1.0. Alpha 2 or newer here on GitHub https://github.com/FrSkyRC/ETHOS-Fee...unity/releases Click on the release header name and the files will populate the page. The file name is lua_doc.zip. Download the lua_doc.zip file and unzip it. To open the documentation, click on file name index.html in the file list and the documentation will open in in your default web browser.

ETHOS Lua Script Files Location

The ETHOS Lua script files are stored on the radio system SD card in the "scripts" folder. There are sample Lua files provided with the SD download of gauge.lua, rssi.lua, sinus.lua and test.lua.

Current Lua Implementation

Currently the first release of ETHOS Lua can be used in any radio display window cell that supports widgets.



** Fill in lots of info here **



For folks that might be wondering why Lua scripting is helpful with ETHOS here is some information https://www.lua.org/about.html

Mike
Last edited by Jet_Flyer; Nov 28, 2021 at 06:06 PM.
Sign up now
to remove ads between posts
Nov 23, 2021, 04:27 PM
Registered User
Jet_Flyer's Avatar
Thread OP
ETHOS Release 1.1.0. Lua Scripting Examples

The first release of ETHOS 1.1.0. is here and its new feature is Lua Scripting. I'm sharing a few screens and comments to provide some insight on what to expect from ETHOS Lua.

ETHOS Lua Scripting

1. Example operating Lua screen
2. Selecting widget configuration
3. Configuring widget
4. Sample code. ETHOS Lua is not limited like some of the other RC OS systems that support Lua where it is not possible for the Lua writer to setup fields as wanted. In other OS systems the fields can be very limited and they may be displayed as one field per line.
5. It is possible in ETHOS to use the storage as the user wishes
6. Lua registration
7. Registration allows the selection of available Lua widgets, just like other widgets
8. Title control
9. Title on
10. Title off.
11. Another screen example

ETHOS provides the ability to catch any event in the widget, through the onEvent function

Mike
Last edited by Jet_Flyer; Nov 23, 2021 at 04:52 PM.
Nov 23, 2021, 04:28 PM
Registered User
Jet_Flyer's Avatar
Thread OP
Thead Index

Webpages

Main FrSky X20, X20S & X20HD Tandem and ETHOS 24 Channel System thread https://www.rcgroups.com/forums/show...ndem-and-ETHOS

The ETHOS Lua documentation can be downloaded from the ETHOS release files 1.1.0. Alpha 2 or newer here on GitHub https://github.com/FrSkyRC/ETHOS-Fee...unity/releases

User Created Scripts

Radio map lua by ronron https://www.rcgroups.com/forums/show...7&postcount=57
Last edited by Jet_Flyer; Nov 28, 2021 at 05:57 PM.
Nov 23, 2021, 04:28 PM
Registered User
Jet_Flyer's Avatar
Thread OP
Future
Nov 23, 2021, 05:17 PM
Registered User
Jet_Flyer's Avatar
Thread OP
ETHOS Lua Questions and Answers

Provided by Bertrand

> When does wakeup() get called on a script?
At each cycle of the main task, i.e. every 50ms. The screen is refresh only if needed and partially when possible (i.e. a widget requested it, or the time changed)

> Are there some defined colors for draw functions? (not sure how that would work as they need red green blue parameters).
Just call setColor(red, green, blue)

> Is there a way to set background color for text?
First you draw a filled rectangle, then the text above

> For the drawText function is there a way to set BOLD, etc type text? Is that a parameter at the end or a separate function like the new setFont(S)?
Not all fonts are possible. To write in bold font, just call setFont(BOLD)

1) background + refresh (OpenTX) vs wakeup + paint (Ethos)
=======================================

OpenTX: the screen is always FULLY refreshed, even if nothing has changed - when a Lua widget is visible, its refresh() function is called so that he can paint his own region. when it is not visible, only the background() function is called

Ethos: wakeup() function is called at each cycle. The wakeup() will call the wakeup() of all (Lua) widgets. If nothing has changed, then the screen is not refreshed. If only one widget needs to be refreshed (invalidateWindow has been called), then only this widget is drawn and the cycle is very quick. When a refresh is needed, paint() is called.

2) Yes, if something has changed in the widget and you want to draw it again, then invalidateWindow needs to be called

3) The events flow is different as well. Basically, all events are passed, if the widget doesn't do anything with this event, it just returns false which means "I didn't do anything special, just deal with it as you would do with any widget".
Last edited by Jet_Flyer; Nov 24, 2021 at 08:38 AM.
Nov 23, 2021, 05:31 PM
Premium Registered User
Giant Tortoise's Avatar
*Watling patiently for inav lua
Nov 23, 2021, 06:17 PM
Registered User
aerografixs's Avatar
following
Nov 23, 2021, 06:23 PM
Adam
xStatiCa's Avatar
How do we create timers? If you have several things you need either for alarms, timers to display countdowns/ups, intervals, what can we use for that? In OpenTX there was getTimer() and setTimer().

EDIT: Also what version of Lua is being used and what libraries are included?

And also thanks for starting a thread on this and all your answers.
Last edited by xStatiCa; Nov 23, 2021 at 08:31 PM.
Nov 24, 2021, 01:22 AM
Registered User
Here is a little widget to show the window size of a widget.

-- Lua check widget size

local function create()
return {value=nil}
end

local function paint(widget)
w, h = lcd.getWindowSize()
text_w, text_h = lcd.getTextSize("")
lcd.setFont(STD)
lcd.drawText(w/2, (h - text_h)/2, w.." x "..h, CENTERED)
end

local function init()
system.registerWidget({key="wdgsize", name="Widget Size", create=create, paint=paint})
end

return {init=init}
Nov 24, 2021, 02:21 AM
RC pilot by soul
what's the resolution of X20 screen?
to use in DrawBitmap as a wall paper?
also is there an online tutorial on how to run LUA on X20 PC simulator? where to place files.. how to load it etc?
i have installed X20 simulator but under "configure widget" there are no LUA options shown. the list of options ends with "Line Chart".
Last edited by i3dm; Nov 24, 2021 at 05:11 AM.
Nov 24, 2021, 05:52 AM
Adam
xStatiCa's Avatar
It is nice that the draw functions that take arguments for x and y use 0 as the start of the area for the widget. That is another difference from OpenTX. Nice to see that. There was a request for that in OpenTX but since it always worked the other way around (beginning of the screen area display), I assume they didn't want to change it. Fresh start here.
Nov 24, 2021, 06:03 AM
Adam
xStatiCa's Avatar
Quote:
Originally Posted by i3dm
what's the resolution of X20 screen?
to use in DrawBitmap as a wall paper?
also is there an online tutorial on how to run LUA on X20 PC simulator? where to place files.. how to load it etc?
i have installed X20 simulator but under "configure widget" there are no LUA options shown. the list of options ends with "Line Chart".
The specs of the screen on the FrSky site say the screen resolution is 800 x 480. The size usable by a Widget depends on what Widget size you are using. You can find that out using the w, h = lcd.getWindowSize() function as shown in the included sample lua scripts and explained in the lua documentation that is available on github with the release. The widget created by Lothar 3 posts above this will show you the widget size for any widget area you use it for to determine that too.

The models are stored in your home directory under a .ethos\models directory on Windows. I tried copying the example lua scripts to my home directory under C:\Users\Adam\.ethos\scripts directory but they don't show up so maybe Lua isnt functional yet in the simulator.
Last edited by xStatiCa; Nov 24, 2021 at 06:22 AM.
Nov 24, 2021, 07:01 AM
RC pilot by soul
Quote:
Originally Posted by xStatiCa
The specs of the screen on the FrSky site say the screen resolution is 800 x 480. The size usable by a Widget depends on what Widget size you are using. You can find that out using the w, h = lcd.getWindowSize() function as shown in the included sample lua scripts and explained in the lua documentation that is available on github with the release. The widget created by Lothar 3 posts above this will show you the widget size for any widget area you use it for to determine that too.

The models are stored in your home directory under a .ethos\models directory on Windows. I tried copying the example lua scripts to my home directory under C:\Users\Adam\.ethos\scripts directory but they don't show up so maybe Lua isnt functional yet in the simulator.
i would like to make a widget with a full size background image (full screen) - is that not possible?
i modified the included test.lua with:

-- Demo of a bitmap
local w2, h2 = lcd.getWindowSize()
local bitmap = lcd.loadBitmap("/bitmaps/user/sprvpr.png")
lcd.drawBitmap(10, 25, bitmap, w2, h2)

(i thought this would size the image to the size of the full LCD)
and the result is:
1. image does not span on the full screen (perhaps wrong sized?)
2. lua loads extremely slow.

here is a video showing the result:
lua super slow (0 min 16 sec)
Nov 24, 2021, 08:36 AM
Registered User
Jet_Flyer's Avatar
Thread OP
Quote:
Originally Posted by xStatiCa

EDIT: Also what version of Lua is being used and what libraries are included?

And also thanks for starting a thread on this and all your answers.
Updated post #1 with:

The Lua interpreter embedded inside ETHOS is based on LUA 5.4.3. and is packaged with those libraries:

* basic library
* table library
* Io library
* os library
* math library

Mike
Nov 24, 2021, 08:47 AM
Adam
xStatiCa's Avatar
Quote:
Originally Posted by i3dm
i would like to make a widget with a full size background image (full screen) - is that not possible?
i modified the included test.lua with:

-- Demo of a bitmap
local w2, h2 = lcd.getWindowSize()
local bitmap = lcd.loadBitmap("/bitmaps/user/sprvpr.png")
lcd.drawBitmap(10, 25, bitmap, w2, h2)

(i thought this would size the image to the size of the full LCD)
and the result is:
1. image does not span on the full screen (perhaps wrong sized?)
2. lua loads extremely slow.
It would appear to me that the drawBitmap() function is not working properly. I think you are misunderstanding how it should work too though.

Assuming I am interpreting the LUA docs correctly (which really doesn't explain all the parameters and functions well), You are telling the drawBitmap() function to start inside the Widget area at x=10 and y=20. That would offset the image over to the right and down... not the start of the widget area. You would think you want that to be 0, 0. You are then telling the drawBitmap() to scale the image to the size of the window size (getWindowSize). That function returns 784x294 for the largest widget size. Since you offset the image by x=10 and y=25, I would expect the image to be drawn outside the widget area on the bottom and right hand side since you offset it to start at x=10 and y=20. It should print it inside the entire red box area and clip it from the menu area since that is outside the widget area. Maybe scaling keeps aspect ratio but I would have still expected your image to but cut off at the bottom because you offset it by 25 in the Y direction. Maybe the optional 4th and 5th parameters (h and w) to drawBitmap() don't scale though and are used for something else?

I would expect your code to look like the image I attached where the entire red box area would be your image.

The video you show does not look anything like that though. I have no idea why it is centering your image instead of starting it at x=10 and y=25. I also expected it to scale the image to 784x294 which is what getWindowSize() returns for the largest widget.

The speed issue I don't know.
Last edited by xStatiCa; Nov 24, 2021 at 09:14 AM.


Quick Reply
Message:

Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Download An Ardupilot frsky telemetry LUA script for the Horus X10/ X12 and Taranis X9D/E/QX7 yaapu Radios 830 Nov 05, 2021 12:06 PM
Discussion Frsky r-xsr and LUA script not working hawk21 Multirotor Drone Electronics 2 May 28, 2019 03:36 AM
Question All about FrSky OS and lua script FlyHorus FrSky 0 Feb 12, 2019 03:55 PM
Mini-HowTo Check Your FrSky Taranis Sticks and Gimbals With This Lua Script Miami Mike Radios 1 Mar 01, 2017 01:20 PM