Skip to content

Commit

Permalink
Update build scripts, update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Matze-Jung committed Jun 28, 2019
1 parent 6d92e76 commit ac13a82
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
all:
bin/build.sh
bin/build.sh min
47 changes: 21 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -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**
Expand All @@ -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).

Expand All @@ -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* |
Expand All @@ -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 |
Expand All @@ -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:

Expand All @@ -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 !!
Expand Down
100 changes: 85 additions & 15 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -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/tmpvar)
rm -f tmp/tmpvar

_fail=$?
if [[ $_fail -ne 0 ]]; then
LAST_FAILURE=$_fail
echo -e "\e[1m\e[39m[\e[31mBUILD FAILED\e[39m]\e[21m Compilation error in file ${SRC_NAME}\e[1m"
if [[ $_fail -ne 0 || $STDOUT ]]; then
((ERRCNT++))
echo
echo `date +"%Y-%m-%d %T"` "$file $STDOUT"$'\r' >>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=$(<tmp/tmperr)

rm -dfR tmp

if [[ $LAST_FAILURES == '' ]]; then
echo
echo "copying attachments..."
cp -fvR src/SOUNDS obj/SOUNDS

echo
echo -e "\e[1m\e[39m[\e[32mSUCCESSFUL\e[39m] \e[21mAll lua files built successfully!\e[21m\e[1m\e[0m\e[0m"
else
echo "$LAST_FAILURES"$'\r' >> ".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
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit ac13a82

Please sign in to comment.