|
|
|
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 here https://github.com/FrSkyRC/ETHOS-Fee...unity/releases Check the newest release for the latest document. ETHOS Lua Script Files Location The ETHOS Lua script files are stored on GitHub here https://github.com/FrSkyRC/ETHOS-Fee.../tree/main/lua Lua Scripting Configuration Limits - 2MB for bitmaps (one full screen bitmap on X20 costs 768K) - 2MB for Lua scripts (this is a large amount) Avoid using too much ram for bit maps. It is suggested the users use lazy loading = load a bitmap ONLY when needed. Then keep it in memory for the next use, to avoid read again from SD 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; Aug 25, 2022 at 11:08 AM.
|
|
|
|
|
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 ImagesView all Images in thread
|
|
Last edited by Jet_Flyer; Nov 23, 2021 at 04:52 PM.
|
|
|
|
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.
|
|
|
|
*Watling patiently for inav lua
|
|
|
|
|
|
following
|
|
|
|
|
|
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 StatiC; Nov 23, 2021 at 08:31 PM.
|
|
|
|
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.font(FONT_STD) lcd.color(lcd.RGB(255,0,255)) 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} Just copy the unzipped ‘wdgsize’ folder to the ‘scripts’ folder on your SD card. |
|
Last edited by Lothar Thole; Sep 07, 2022 at 05:42 PM.
Reason: Updated for current Ethos Lua 1.3.0
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
||
|
Quote:
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 StatiC; Nov 24, 2021 at 06:22 AM.
|
|
|
||||
|
Quote:
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:
|
|||
|
||||
|
||
|
Quote:
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 |
|
|
||
|
||
|
Quote:
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 StatiC; Nov 24, 2021 at 09:14 AM.
|
|
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 | 966 | Jan 17, 2024 09:02 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 |