diff --git a/Makefile b/Makefile index d81c3e18..2f494937 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,2 @@ all: - bin/build.sh + bin/build.sh min diff --git a/README.md b/README.md index 636f509f..1acc3e2e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # betaflight-tx-lua-scripts-mod - *based on release [1.3.0](https://github.com/betaflight/betaflight-tx-lua-scripts/releases/tag/1.3.0)* ## Changes - **+ Display external telemetry templates beside betaflight screens** **+ Configurable navigation controls, radio type independent** @@ -18,8 +16,7 @@ **+ Minified script files, shrinked down to 75% the size of 1.3.0** (thanks to [mathiasbynens/luamin](https://github.com/mathiasbynens/luamin)) ## Notes - -I wanted to explore the potential of the popular betaflight-tx-lua-scripts a bit, as I wasn't quit satisfied with a few things. Came up with this mod and it upgraded the UX for me so well, that I decided to share it with the community. Runs nique smooth on my FrSky Taranis Q X7, but I wasn't able to do tests with any *Horus* or other model than *FrSky Taranis* so far. +Wanted to explore the potential of the popular betaflight-tx-lua-scripts a bit, as I wasn't quit satisfied with a few things. Came up with this mod and it upgraded the UX for me so well, that I decided to share it with the community. Runs nique smooth on my FrSky Taranis Q X7, but I wasn't able to do tests with any other models than FrSky so far. Install and use this modified version just the way you're used to. First time users should have a glimpse at the [install instructions](#installing). @@ -35,31 +32,37 @@ Prepend `-- ` to the line to hide a page (e.g. rescue.lua and gps.lua, if you do Use relative pathnames to refer external templates. If you add or edit pages, keep in mind that the radios internal memory isn't endless. -### Navigation controls -The code wich handles the user events was extracted from `ui.lua` into a table `ctrlSchema = { ... }` and placed in each `SCRIPTS/BF/[platform]/[platform]pre.lua` file. +> *If you have TBS Crossfire, you can try* `../../../CROSSFIRE/crossfire.lua`*. The Page seems to load, but tell me if it's actually working.* + +### Mapping navigation controls +The code wich handles the user events was abstracted from `ui.lua` into a table `ctrlSchema = { ... }` and placed in each `SCRIPTS/BF/[platform]/[platform]pre.lua` file. The assignment of radio inputs to script actions depends now on this platform specific config. For instance: if you want to have switching pages on the [DIAL WHEEL] input, change the condition of `ctrlSchema.display.prevPage` to `dial.left` and `ctrlSchema.display.nextPage` to `dial.right`. -To add a radio control schema based on its platform, just overwrite the affected table fields below the schema table (see overrides for X9E in `SCRIPTS/BF/X9/x9pre.lua` for example). +To add a transmitter control schema based on its platform, just overwrite the affected table fields below the schema table (see overrides for X9E in `SCRIPTS/BF/X9/x9pre.lua` [for example](https://github.com/Matze-Jung/betaflight-tx-lua-scripts-mod/blob/7c4463aec29757763e8eb7aea49905e677711ef7/src/SCRIPTS/BF/X9/x9pre.lua#L101)). -### Memory warning -If you just copied the files, launched the script and a `not enough memory` warning appears, probably restarting the radio is the only thing to do here. If OpenTX still complains, try to delete all `.luac` files (compiled them with LUAC 5.3, don't know if that's a problem with some radios). +This concept should have the potential to implement new coming radios much easier and be handled separately from the core ui code. -### Test environment -* OpenTX v2.2.3 on FrSky Taranis Q X7 Hardware -* Betaflight 4.0.3 on OmnibusF4 FC -* Companion v2.2.3 Simulator (*all FrSky, **except Horus***) +### Memory warning +If you just copied the files, launched the script and a `not enough memory` warning appears, probably restarting the radio is the only thing to do here. If OpenTX still complains, try to delete all `.luac` files (compiled with LUAC 5.3.5, don't know if that's a problem with some devices). -> *Any feedback about testing on different hardware welcome.* +## Test environment +* OpenTX v2.2.3 on Taranis Q X7, Betaflight 4.0.3 on OmnibusF4, R-XSR +* Companion Sim v2.2.3 & 2.3.0N34 (*FrSky radios only*) -### Download +> *Any [feedback](https://github.com/Matze-Jung/betaflight-tx-lua-scripts-mod/issues/new/choose) about testing on different hardware welcome.* +## Download Please go to the [releases page](https://github.com/Matze-Jung/betaflight-tx-lua-scripts-mod/releases) to download the latest files. +## Building from source +- Be sure to have `LUA 5.2`and `Node.js` installed +- Run `npm install` from the root folder to install node modules +- Run `npm start`, `make` or `./bin/build.sh min` from the root folder with appropriate privileges (omit the `min` switch to build without minifying) +- Compiled/minified files will be created at the `obj` folder. Copy the files to your transmitter as instructed in the [Installing section](#installing) below as if you unzipped from a downloaded file. ## Control schema layout - | State | Action | Condition (X7) | | - | - | - | | display | prevPage | *longPress.page* | @@ -77,10 +80,9 @@ Please go to the [releases page](https://github.com/Matze-Jung/betaflight-tx-lua | | next | *dial.right* | | | cnfrm | *release.enter* | | | exit | *release.exit* or *release.menu* | - +> *Action `func()` is fired when condition is true and in application state.* ## User events - | Action | Name | | - | - | | press | minus | @@ -102,11 +104,9 @@ Please go to the [releases page](https://github.com/Matze-Jung/betaflight-tx-lua | | left | | | right | - --- - -# betaflight-tx-lua-scripts +# betaflight-tx-lua-scripts 1.3.0 ### Important: @@ -119,11 +119,6 @@ For now, the recommendation is for users wanting to update OpenTX from 2.2.0 to - Crossfire - v2.11 or greater - FrSky - While most receivers work fine, it's recommended to update the XSR family of receivers to their most recent firmware version to correct any known bugs in SmartPort telemetry. -## Building from source -- Be sure to have `LUA 5.2` installed in the path -- Run `./bin/build.sh` from the root folder -- Compiled files will be created a the `obj` in the root folder. Copy the files to your transmitter as instructed in the `Installing` section below as if you unzipped from a downloaded file. - ## Installing !! IMPORTANT: DON'T COPY THE CONTENTS OF THIS REPOSITORY ONTO YOUR SDCARD !! diff --git a/bin/build.sh b/bin/build.sh index ff6dbdf0..bd29468b 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,35 +1,105 @@ #!/bin/bash +MINIFY=$1 +ERRCNT=0 + if [ -d obj ]; then rm -fR obj/* else mkdir obj fi -cp -fR src/* obj +if [ -d tmp ]; then + rm -dfR tmp +fi + +mkdir -p tmp/SCRIPTS/BF +echo +luac -v -MANIFEST=(`find obj/ -name *.lua -type f`); -LAST_FAILURE=0 +if [[ $MINIFY == "min" ]]; then + echo + echo luamin $(npm view luamin version)" "Copyright Mathias Bynens [https://github.com/mathiasbynens/luamin] +fi + +echo +echo "duplicating ..." +## backup minify excludes +EXCLUDE=(`find src/SCRIPTS/BF/* -name *pre.lua -type f`); +for x in ${EXCLUDE[@]}; +do + mkdir -p $(dirname ${x/src/tmp}) + cp -fR $x ${x/src/tmp} +done +cp -fR src/SCRIPTS/BF/X7/exmpl1.lua tmp/SCRIPTS/BF/X7/exmpl1.lua + +MANIFEST=(`find src/* -name *.lua -type f`); if [ ${#MANIFEST[@]} -eq 0 ]; then - echo -e "\e[1m\e[39m[\e[31mTEST FAILED\e[39m]\e[21m No scripts could be found!." + echo -e "\e[1m\e[39m[\e[31mTEST FAILED\e[39m] \e[21mNo scripts could be found\e[21m!" exit 1 fi -for f in ${MANIFEST[@]}; +rm -f tmp/tmperr +touch tmp/tmperr + +echo "building ..." + +for file in ${MANIFEST[@]}; do - SRC_NAME=$f - OBJ_NAME=$(dirname ${f})/$(basename ${f} .lua).luac - echo -e "Compiling file \e[1m${SRC_NAME}\e[21m..." - luac -s -o ${OBJ_NAME} ${SRC_NAME} + SRC_PATH=$(dirname ${file})/ + OBJ_PATH=${SRC_PATH/src/obj} + OBJ_LUA=$(basename ${file}) + OBJ_LUAC=${OBJ_LUA/.lua/.luac} + + echo + echo -ne "\e[1m\e[37m${file}\e[39m\e[1m\e[0m ...\e[0m" + + mkdir -p ${OBJ_PATH} + + if [[ $MINIFY == "min" ]]; then + echo -n " minify ..." + node node_modules/luamin/bin/luamin -f "$file" > "${OBJ_PATH}${OBJ_LUA}" + cp -f "${file/src/tmp}" "${OBJ_PATH}${OBJ_LUA}" >/dev/null >tmp/null 2>tmp/null + else + cp -f "$file" "${OBJ_PATH}${OBJ_LUA}" + fi + + echo -n " compile ..." + luac -s -o "${OBJ_PATH}${OBJ_LUAC}" "$file" >tmp/tmpvar 2>tmp/tmpvar + STDOUT=$(>tmp/tmperr + echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m] \e[1m \e[0m\e[37mCompilation error:\e[0m" + echo -e "\e[1m\e[37m${STDOUT}\e[39m\e[1m\e[0m \e[0m" + else + echo -ne " \e[1m\e[39m[\e[32mok\e[39m]\e[1m\e[0m\e[0m" fi done +echo -if [[ $LAST_FAILURE -eq 0 ]]; then - echo -e "\e[1m\e[39m[\e[32mTEST SUCCESSFUL\e[39m]\e[21m All lua files built successfully!" +LAST_FAILURES=$(> ".builderr" + echo + echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m] \e[1m \e[0m\e[37mCompilation error(s):\e[0m" + echo -e "\e[1m\e[37m${LAST_FAILURES}\e[39m\e[1m\e[0m \e[0m"$'\r' fi -exit $LAST_FAILURE + +echo +exit $ERRCNT diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..fc78a73d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,23 @@ +{ + "name": "betaflight-tx-lua-scripts", + "version": "1.3.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "luamin": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/luamin/-/luamin-1.0.4.tgz", + "integrity": "sha1-lEUptY/G+k0x6s4uA1PUEhDw49M=", + "dev": true, + "requires": { + "luaparse": "^0.2.1" + } + }, + "luaparse": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/luaparse/-/luaparse-0.2.1.tgz", + "integrity": "sha1-qo9WEysN6X0388mRqd9C4OF/ZWw=", + "dev": true + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 00000000..27c6fddb --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "betaflight-tx-lua-scripts", + "version": "1.3.0", + "scripts": { + "start": "bash bin/build.sh min", + }, + "description": "", + "devDependencies": { + "luamin": "^1.0.4" + } +}