Preemptible Lua widget scripts? #1011
Replies: 3 comments
|
I don't know how the scheduler in FreeRTOS works, but is there now way that the OS preempts the LUA-script without interaction from the script itself? What you suggest is kind of coorparative multitasking if I understand that correctly. |
|
What I suggest here, is the same type of preemption that I made for the other scripts. And you are right that it is a kind of cooperative multitasking in the sense that it is the Lua interpreter that decides when to take a break running the script. |
|
Ok, sounds reasonable. But why do yyou need the visible-flag for the widget? refresh() is called if visible, background() is called if not. |
Uh oh!
There was an error while loading. Please reload this page.
I have now come to the point in the development of SoarETX where I hit the dreaded CPU limit. And I therefore I have the choice between making my widget script divide jobs like reading a score file over multiple cycles with the added complexity of scripts, or figure out a way to have widget scripts preempt like the other scrips 🤓
Standalone scripts use a "backup" buffer for Lua, and this gets copied over to the active LCD buffer. This was already in place before I implemented preemption, and that was very fortunate for me, because I could easily make the buffer copying contingent on Lua having finished the
runfunction call.To my surprise, it appears that the above case is the only place that this "backup" buffer is used in EdgeTX (#1009)! So therefore I wonder if we could make the "backup" LCD buffer the Lua buffer for widgets also?
What I have in mind is the following process for making the widget scripts preemptible:
guiMain()beforeMainWindow::run(). The widgets have avisibleflag added to tell if they must callbackground()orrefresh(...)here. If a widget script is completed thenrefreshedis set to true and otherwise false.checkEvents()setsvisibleto false and callsinvalidate().paint()copies its rectangle (or the entire screen in fullscreen mode) from the "backup" to the active LCD buffer if the widget isrefreshed, and setsvisibleto true.All reactions