Commit Graph
47 Commits
Author SHA1 Message Date
Jesper FrickmannandGitHub 83fbf1a7f8 feat(lua): Add getSourceValue (#2316)
* Moved getFieldInfo and getValue up right after related functions

* Modified getValue to return a valid status, so Lua can see if it got zero because of invalid source id

* Added new getSourceValue Lua function per Issue #781
Also added alias getSourceInfo for getFieldInfo

* Updated according to comment https://github.com/EdgeTX/edgetx/pull/2175#issuecomment-1245605114

* Replaced isFresh() by !isOld() as requested in https://github.com/EdgeTX/edgetx/pull/2316#issuecomment-1246759370

* Clean up `lua_pushtablenil` - tables cannot hold nil values

* Changed isFresh() to !isOld() ... AGAIN

* Return both `!isOld()` and `isFresh()`

* Return nil for all values if the item does not exist

* Return 0 instead of pushing three nil values

* Update documentation
2022-09-28 09:42:16 +10:00
Raphael CoefficandRaphael Coeffic a3424d5bc0 Support for touch/key events in LUA widgets 2022-06-11 15:38:08 +02:00
Raphael Coeffic 9c9f77a2a9 Do not allocate memory for LUA Rx fifo from the USB ISR
Rather use explicit allocation when the serial is set as the on-demand method that was used previously.
2022-03-20 16:30:59 +01:00
Raphael Coeffic 530d395204 WiP 2022-03-20 16:22:14 +01:00
Jesper FrickmannandGitHub 0069bcc52f Increased Lua buffer size for standalone and telemetry scripts (#1442) 2022-01-17 10:54:08 +10:00
jfrickmannandPeter Feerick f2a360c9d3 Addressed the requests in issue #1285
`getfieldInfo` can now also take a source index as argument. Plus it was modified to also handle "telem1+" etc.
New functions `getSourceIndex(sourceName)` and `getSourceName(sourceIndex)` were added, which use the names shown on the
screen instead of the special names table used by `getFieldInfo` and `getValue`.
Indices are the same for all of the functions, so `getValue(sourceIndex)` also works with indices from `getSourceIndex`.
New iterator functions `sources([first[, last]])` and `switches([first[, last]])` for getting ranges of sources and switches.
`getPhysicalSwitches` was removed, as I consider the iterator function to be a better solution.
2022-01-04 09:51:47 +10:00
jfrickmann ce7b408445 Add touch to Standalone Lua scripts 2021-11-19 08:01:28 -05:00
Jesper FrickmannandGitHub f1baa383ae Fix standalone Lua script screen flicker and improve error messages (#982)
* Relax assumptions about when Lua is called in foreground and background

* Start Lua cycle timer both in foreground and background
Do not assume that background/foreground alternates

* Lua is called at every Standalone GUI cycle instead of 5 Hz
Since Lua preempts every 50 ms or so, the GUI should remain responsive.

* In standalone script, only call Lua once per GUI cycle, to avoid messing up buffer handling.

* Revamped error reporting for Standalone and Telemetry Lua scripts

* Font size for Lua error is reduced from XL to L on color if LCD_W < LCD_H

* In drawTextLines, also possible linebreaks for opening brackets.

* Smaller font for error message on tall color screen

* Make titlebar height match font size on narrow LCD
2021-11-15 12:57:14 +11:00
Peter FeerickandGitHub 3ad98bacf4 [NV14] Use trim hats to emulate key events when standalone lua script running (#985)
* Preliminary trims as keys for lua
Largely based on open-flysky implementation

* Add `isLuaStandaloneRunning()`

* Add more virtual events

* Tweak virtual events further

* Finish remapping keys to virtual events

* Move some virtuals to right trim hat

* Add missing "defined"

* Revert to common EVT_VIRTUAL_MENU mapping

* Make keys/trims reset backlight like other radios
2021-11-09 12:50:20 +11:00
rotormanandRisto fc2142ec78 Changed uniformly to EdgeTX boiler plate (also added boiler for files that were missing it). 2021-10-02 14:22:01 +02:00
Riwan ec1c1ec345 Added LUA file system operations 2021-08-23 14:39:49 +02:00
jfrickmann 5671838864 Cleaned up code for Mixer/Custom/Model scripts and added compiler directives 2021-07-22 15:11:12 -04:00
jfrickmann c62aac7bde Lua task preempts long running scripts instead of killing them
Ported to EdgeTX from https://github.com/opentx/opentx/pull/8194
2021-07-22 14:41:53 -04:00
Raphael Coeffic 78915daf95 Fixed memory leak: widget factories need to be deleted
in opentxClose()
2021-06-12 07:38:31 +02:00
Raphael Coeffic 247ac2a524 Fixes 2021-06-09 09:30:18 +02:00
Raphael Coeffic b0fb80b264 ZChar nightmare / take 2 2021-06-09 09:24:48 +02:00
Raphael Coeffic 493b9aaedc Fixes issue with model LUA API strings 2021-06-04 20:43:02 +02:00
Raphael CoefficandRaphael Coeffic 3ba55ac34e Fixed non-color lcd cmake
No widgets necessary for B/W.
2021-05-06 12:55:59 +02:00
Raphael CoefficandRaphael Coeffic 72a7409d10 First working LUA widget: Timer2 2021-05-06 12:55:59 +02:00
3djcGitHub3djc <Th1sisfmyofmyo>
87cd9047b1 2.4 continued (#8092)
Quite a bit of work on 2.4

Co-authored-by: 3djc <Th1sisfmyofmyo>
2020-11-14 14:55:37 +04:00
3djc 318e4dd516 tx16s aux fixes 2020-05-15 21:11:05 +02:00
Tom van DijkandGitHub 682f0f1b05 lua serialRead (#7520)
Lua serial read
2020-05-15 15:13:23 +02:00
3djcandBertrand Songis c60d3858d2 Allow longer toolsname on wide screens (#6805) 2019-09-18 17:55:51 +02:00
Bertrand Songis ffb731dc30 [X10 Express] Spectrum analyser, first version 2019-08-19 16:21:55 +02:00
3djcandAndre Bernet cd3c4ac654 Add Jumper t12 support by 3djc (#6451)
* Jumper T12 - companion part

* more work

* Add definitions

* fix libsimulator key handling

* Fix simu keys handling

* Cosmetics

* Continued

* Fix wrong regplace

* Fix wrong regplace

* Please travis

* Please travis

* Add T12 to Travis
Switch naming and display

* Cosmetics

* Work on modules

* Work on modules

* typo

* Fix navigation

* Cosmetics

* Introduce NAVIGATION_type

* Fix

* Make NAVIGATION_type more future proof

* Lots of cleanups and improvements

* Cosmetics

* Fix internal module menu

* Cosmetics

* Fix screen reversed

* Small fixes

* Fix navigation issue

* Please travis

* Fix LCD contrast

* Fix T12 switch layout

* Fix T12 keys screen and all radios keys translations

* Complete rework of SWITCHES screen for all radios

* comsetics

* VC++ compilation
2019-05-26 19:51:17 +02:00
Bertrand Songis 131078e3a0 GCC new warnings fixed (GCC) 8.1.1 20180531 2018-08-03 23:02:43 +02:00
Bertrand SongisandGitHub 99604dccc9 XLite support (#5806) 2018-04-25 23:07:04 +02:00
Max PapernoandBertrand Songis ba1073ace6 [Lua] Allow global functions to play scripts. (#5440) 2017-11-30 19:10:11 +01:00
Damjan AdamicandBertrand Songis f0f3e35bf6 Lua memory (de)allocation tracer: (#5191)
* Lua memory (de)allocation tracer:

Usage:
 * turn on: `cmake -DLUA=YES -DLUA_ALLOCATOR_TRACER=YES -DDEBUG=YES -DNANO=NO`
 * get debug output and make plot data: `./simu 2>&1 | grep "^LT" | ../radio/util/lua_trace2plot.py > data.plot`
 * plot: `gnuplot  -e 'set xtics rotate;  plot "data.plot" using 2:xtic(1) ; pause mouse close'`

* Changes based on Bertrand comments
2017-11-11 09:41:05 +01:00
Damjan AdamicandAndre Bernet 955d5775cb Add Lua getUsage() function that returns percent of already used up i… (#5313)
* Add Lua getUsage() function that returns percent of already used up instructions in current script execution cycle. It can be used to avoid script being killed when doing long lasting tasks (like telemetry logs loading and parsing)

* Compilation fixes

* Doc fix

* Disable Lua script instructions limit in DEBUG mode
2017-11-10 17:23:37 +01:00
Damjan AdamicandBertrand Songis f36d01d560 Fixes #4438: wrong cast used when setting Lua mixer script input source (#4470)
* Fixes #4438: wrong cast used when setting Lua mixer script input source
Improved parsing of Lua mixer script inputs

* Additional type check

* ScriptDataInput union introduced.
Fixed: when using SOURCE input, do not use default value
Fixed: when using SOURCE input, min-max range is fixed
2017-02-21 10:59:47 +01:00
Damjan AdamicandBertrand Songis e80c4c858e Prevent Lua from allocating all heap memory (Horus) (#4440)
* Fixes #4284: Prevent Lua from allocating all heap memory (Horus)
Lua bitmap functions cleanup and docs update
Added x or y < 0 check to drawBitmap()

* Proper float constant
2017-02-11 22:21:14 +01:00
Damjan AdamicandBertrand Songis b493973d7d Lua: Use incremental GC and also call it for Widgets (#4369)
Fixes #3885: Error in Lua Widget options handled better (does not disable entire Lua state)
Disable Lua Widget if any of its functions has error.
2017-02-04 10:58:06 +01:00
Max PapernoandBertrand Songis 5d5dc67605 Add runtime Lua script pre-compilation and general .luac file support (#3318) (#4119)
* [simu] simpgmspace: Populate file date/time/size  in f_stat(); Add f_utime(); Fix f_getcwd() on Windows; Fix f_mkdir() build error on Windows.

* [Lua] Add runtime support for script pre-compilation. Changes behavior with LUA_COMPILER (Re: https://github.com/opentx/opentx/issues/3318):
  All .lua scripts are now compiled and saved to binary "bytecode" file (.luac extension) upon first execution;
  Scripts are also automatically re-compiled if .lua source file is newer than existing .luac file;
  The pre-compiled .luac version is loaded if modification time is newer or equivalent to .lua source file;
  If a .luac version of a script exists, then the .lua version does not need to be present;
  Guards against bytecode compatibility issues (binaries from 64-bit sim will not run on 32-bit sim/radio);
  In SIMU and DEBUG builds, the source .lua file is always preferred in order to preserve full debug info (this is is controlled with new LUA_SCRIPT_LOAD_MODE macro, see lua_api.h);
  GC is now run after each script is loaded.

* [Lua] Add loadScript() API function as alternative to loadfile() from Lua base. This can take advantage of the new OTx script pre-compilation features to reduce memory footprint when loading functions dynamically. This is an interface to luaLoadScriptFileToState(). Fully documented.

* [SD][Lua] Flexible file extensions support:
  Allow for variable length file extensions throughout system (no longer hard-coded in LEN_FILE_EXTENSION);
  Fixes issues with renaming files in SD manager which have file extensions longer than ".ext";
  Expand general support for multiple file extensions per file type in sdListFiles() (eg. .lua and .luac for scripts);
  Lua scripts with .luac extensions can now be selected in custom/telemetry/function menus even if no .lua version exists (duplicates are not shown);
  .luac files can now also be executed from SD file manager UI.

* [Build] Added CMake options for LUA_COMPILER and LUA_SCRIPT_LOAD_MODE.

* Cosmetics.

* [SD][gui] Improve efficiency of some file name handling routines in sdmanager GUI and sdListFiles() by extending getFileExtension() function. Use shared isExtensionMatching() in place of isImageFileExtension(). Only allow executing .luac files when LUA_COMPILER defined (as per request).

* [simpgmspace] Fix f_mkdir() for MSVC build and misc. cleanup.

* [Lua] Use getFileExtension() in script loader to determine file type and check for buffer overflow.
2016-12-17 10:56:40 +01:00
Bertrand Songis c23ac292b7 [Companion] Horus simulator fixes 2016-12-02 19:56:41 +01:00
Bertrand Songis 90cb917c24 [Horus] Compilation failed when LUA not defined 2016-11-30 07:55:32 +01:00
Damjan AdamicandBertrand Songis 92553b6589 Projectkk2glider/lua bitmap free (#4075)
* Better memory stats (CLI)

* Bitmap buffer overflow check added

* Lua bitmap improvements

* Proper handling of symbolic links in simulator

* S6R Lua script fixes:
 * added progress screen while loading bitmaps
 * memory for bitmaps is now freed when leaving the script

* S6R Lua script: improved bitmap loading

* * Lua Themes and Widgets moved to separate file and separate Lua state
* Stand-alone, mixer and function scripts now behave the same as on Taranis (restarted after the stand-alone script was run)
* both Lua states are independent: Themes and Widgets is initialized only at the start, the other one is initialized before and after the stand-alone script is run

* Better leak test and report in BitmapBuffer

* Re #3318: Lua compiler enabled in simu and Companion simulator. Usage:
 * any time <xxx>.lua file is about to be loaded and if file <xxx>.lua.src exists:
   * load contents of <xxx>.lua.src
   * compile Lua code
   * save compiled code into <xxx>.lua (effectively overwrites existing file)
 * immediately following the compilation the real file loading is done from <xxx>.lua (which by now contains compiled Lua bytecode)
2016-11-28 23:08:18 +01:00
3djc d84fd993c9 Move lua evt param from signed uint8_t to unsigned event_t 2016-09-12 07:20:06 +02:00
Bertrand SongisandGitHub d3ae3c035d Bsongis/gui refactoring for x7 d (#3701)
* [X7D] New board added
* Cosmetics
2016-08-18 11:49:16 +02:00
Bertrand Songis 3faa81d799 [Taranis] It's now possible to use killEvents() on PAGE_LONG in Lua standalone scripts 2016-07-09 12:39:54 +02:00
Bertrand Songis 231499e191 [Horus] Bitmap class and lcd.drawBitmap() added 2016-05-25 11:48:38 +02:00
Bertrand Songis ecff71b044 Cosmetics 2016-03-25 12:54:35 +01:00
Bertrand Songis 33910c8721 [Horus] UI continued 2016-02-16 20:45:25 +01:00
Bertrand Songis e72a049683 [Horus] Cosmetics 2016-02-16 18:59:45 +01:00
Bertrand Songis 88841f63ca Switch to CMake 2015-12-21 23:43:18 +01:00
Bertrand Songis 1e2130de53 [Horus] Lua model scripts added 2015-12-06 22:54:43 +01:00
Damjan Adamic d54f25ccba Lua api and interface lua_api.cpp moved to lua dir and split into several files 2015-11-15 12:05:53 +01:00