diff --git a/.buildfiles b/.buildfiles new file mode 100644 index 0000000..7f350ad --- /dev/null +++ b/.buildfiles @@ -0,0 +1 @@ +-name *.lua ! -name debug*.* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb7db05 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +/bin/* +!/bin/attachments.sh +!/bin/build.sh +/node_modules +/obj +/releases +.builderr +*.lnk +debug.lua diff --git a/.minignore b/.minignore new file mode 100644 index 0000000..93ec78e --- /dev/null +++ b/.minignore @@ -0,0 +1 @@ +-name *.lua ! -name widgets.lua diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2f49493 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +all: + bin/build.sh min diff --git a/README.md b/README.md new file mode 100644 index 0000000..52da238 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# README \ No newline at end of file diff --git a/bin/attachments.sh b/bin/attachments.sh new file mode 100644 index 0000000..b9bfde2 --- /dev/null +++ b/bin/attachments.sh @@ -0,0 +1,4 @@ +#!/bin/bash +## copy files unprocessed + +cp -fvR src/SCRIPTS/WIDGETS/X9/BMP obj/SCRIPTS/WIDGETS/X9/BMP diff --git a/bin/build.sh b/bin/build.sh new file mode 100644 index 0000000..5e78468 --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +MINIFY=$1 +ERRCNT=0 + +if [ -d obj ]; then + rm -fR obj/* +else + mkdir obj +fi + +if [ -d tmp ]; then + rm -dfR tmp +fi +mkdir tmp + +echo +luac -v + +if [[ $MINIFY == "min" ]]; then + echo + echo luamin $(npm view luamin version)" "Copyright Mathias Bynens [https://github.com/mathiasbynens/luamin] +fi + +if [ -f .minignore ]; then + EXCLUDE=(`find src/* $(<.minignore)`); +fi + +MANIFEST=(`find src/* $(<.buildfiles)`); + +if [ ${#MANIFEST[@]} -eq 0 ]; then + echo -e "\e[1m\e[39m[\e[31mTEST FAILED\e[39m] \e[21mNo scripts could be found\e[21m! \e[0m" + exit 1 +fi + +rm -f tmp/tmperr +touch tmp/tmperr + +echo +echo "building ..." + +for file in ${MANIFEST[@]}; +do + 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 + if [[ $EXCLUDE && ($(printf "_[%s]_" "${EXCLUDE[@]}") =~ .*_\[$file\]_.*) ]]; then + cp -f "$file" "${OBJ_PATH}${OBJ_LUA}" + else + echo -n " minify ..." + node node_modules/luamin/bin/luamin -f "$file" > "${OBJ_PATH}${OBJ_LUA}" + fi + 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 + +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 + +echo +exit $ERRCNT diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..fc78a73 --- /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 0000000..4ec2e53 --- /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" + } +} diff --git a/src/SCRIPTS/TELEMETRY/lynix.lua b/src/SCRIPTS/TELEMETRY/lynix.lua new file mode 100644 index 0000000..6ede597 --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/lynix.lua @@ -0,0 +1,10 @@ +-- X9 layout based on https://github.com/lynix/opentx-telemetry +local layout = { + { {id="X9/tx-batt"} }, + { {id="X9/mode"}, {id="X9/gps"}, {id="X9/timer"} }, + { {id="X9/distance"}, {id="X9/altitude"}, {id="X9/speed"} }, + { {id="X9/rssi"} }, +} +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/TELEMETRY/thrgph.lua b/src/SCRIPTS/TELEMETRY/thrgph.lua new file mode 100644 index 0000000..cc5805a --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/thrgph.lua @@ -0,0 +1,37 @@ +local layout = { + { + { + id="graph", + opts={ + uid=7, + src="thr", + lbl="THR", + unit="%", + speed=35, + min=-1000, + max=1000, + lblmax="max", + lblmin="min", + p={l=18} + } + }, + { + id="graph", + opts={ + uid=8, + src=function() return getGraphAverage(7) end, + lbl="THR AVRG", + unit="%", + speed=70, + min=-1000, + max=1000, + lblmax="max", + lblmin="min", + p={l=18} + } + }, + }, +} +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/TELEMETRY/wdgts1.lua b/src/SCRIPTS/TELEMETRY/wdgts1.lua new file mode 100644 index 0000000..3b99d71 --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/wdgts1.lua @@ -0,0 +1,29 @@ +local layout = { + { + { id="rssi" } + }, + { + { id="rssi2" } + }, + -- { + -- { id="batt" } + -- }, + { + { id="batt2" } + }, + { + { id="batt3", opts={src="tx-voltage", lbl="TX Bat", p={r=0}} } + }, + -- { + -- { id="graph", opts={uid=5, src="thr", lbl="THR", unit="%", speed=50, min=-1000, max=1000, lblmax="max", lblmin="min", p={r=18}} }, + -- { id="graph", opts={uid=6, src=function() return getGraphAverage(5) end, lbl="THR AVRG", unit="%", speed=50, min=-1000, max=1000, lblmax="max", lblmin="min", p={r=18}} }, + -- --[[,"../TELEMETRY/graph3"--]] + -- }, + -- {"fm", "gps", "timer"}, + -- {"distance", "altitude", "speed"}, +-- {"batt"}, + -- {"rssi"}, +} +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/TELEMETRY/wdgts2.lua b/src/SCRIPTS/TELEMETRY/wdgts2.lua new file mode 100644 index 0000000..cfab9f8 --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/wdgts2.lua @@ -0,0 +1,29 @@ +local rssi, alarm_low, alarm_crit = getRSSI() +local layout = { + { + { id="batt3", opts={src="tx-voltage", lbl="TX Bat"} } + }, + -- { + -- { id="batt3", opts={src="tx-voltage", lbl="txV"} } + -- }, + { + -- set opts.parent to a true value, if it should call a nested/sub widget + { id="../TELEMETRY/wdgts2_sub", opts={parent=1} }, + { id="graph", + opts={ + uid=5, + src=function() local x = getRSSI() return x end, + speed=100, + min=alarm_crit, + max=99, + crit=alarm_low, + -- lblmax=99, + -- lblmin=alarm_crit, + p={t=6,l=1} + } + }, + } +} +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/TELEMETRY/wdgts2_sub.lua b/src/SCRIPTS/TELEMETRY/wdgts2_sub.lua new file mode 100644 index 0000000..b7fc5e8 --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/wdgts2_sub.lua @@ -0,0 +1,61 @@ +local layout = { + { + { + id="value", + opts={ + src=function() return getValue("gvar9") > 0 and getValue("gvar9") or 100 end, + lbl="THR RNG", + unit="%", + style=SMLSIZE, + } + }, + { + id="value", + opts={ + src=function() local db = getRSSI() return db end, + lbl="RSSI", + unit="dB", + min=alarm_low, + style=SMLSIZE, + p={t=4,r=0}, + } + }, + }, + { + -- { + -- id="value", + -- opts={ + -- src=function() local m = model.getInfo() return m.name end, + -- lbl="Model", + -- p={r=0,l=0} + -- } + -- }, + { + id="h-bar", + opts={ + lbl="LQ", + src=function() + local db, low, crit = getRSSI() + return (db - crit) * 100 / (99-crit) + end, + space=0, + bg=true, + -- p={b=-1}, + } + }, + { + id="value", + opts={ + src=function() return getGraphAverage(5) end, + lbl="Avrg", + unit="dB", + style=SMLSIZE, + p={t=4,r=0}, + } + }, + }, +} +-- set the second param to a true value, if this is nested inside a parent widget +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout, 1) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/TELEMETRY/wdgts3.lua b/src/SCRIPTS/TELEMETRY/wdgts3.lua new file mode 100644 index 0000000..baecc8f --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/wdgts3.lua @@ -0,0 +1,34 @@ +local layout = { + { + { id="stairs", + opts={ + lbl="TX Bat", + src=function() + local settings = getGeneralSettings() + return (getValue("tx-voltage") - settings.battMin) * 100 / (settings.battMax-settings.battMin) + end, + stairs=10, + space=2 + } + } + }, + { + -- set opts.parent to a true value, if it should call a nested/sub widget + { id="../TELEMETRY/wdgts3_sub", opts={parent=1} }, + { + id="stairs", + opts={ + src=function() + local settings = getGeneralSettings() + return (getValue("tx-voltage") - settings.battMin) * 100 / (settings.battMax-settings.battMin) + end, + stairs=20, + space=2, + p={t=4,r=0,b=0} + } + }, + } +} +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/TELEMETRY/wdgts3_sub.lua b/src/SCRIPTS/TELEMETRY/wdgts3_sub.lua new file mode 100644 index 0000000..3c4a327 --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/wdgts3_sub.lua @@ -0,0 +1,62 @@ +local layout = { + { + { + id="stairs", + opts={ + lbl="RSSI", + src=function() + local db, low, crit = getRSSI() + return (db - crit) * 100 / (99-crit) + end, + stairs=8, + space=1, + p={b=-2} + } + }, + { + id="stairs", + opts={ + lbl="RSSI", + src=function() + local db, low, crit = getRSSI() + return (db - crit) * 100 / (99-crit) + end, + stairs=6, + space=1, + p={t=4,r=0,b=-4} + } + }, + }, + { + { + id="stairs", + opts={ + lbl="RSSI", + src=function() + local db, low, crit = getRSSI() + return (db - crit) * 100 / (99-crit) + end, + stairs=5, + space=1, + p={r=0,b=-2} + } + }, + { + id="stairs", + opts={ + lbl="RSSI", + src=function() + local db, low, crit = getRSSI() + return (db - crit) * 100 / (99-crit) + end, + stairs=7, + space=1, + p={t=4,r=0,b=-4} + } + }, + }, +} +-- set the second param to a true value, if this is nested inside a parent widget +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout, 1) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/TELEMETRY/x7home.lua b/src/SCRIPTS/TELEMETRY/x7home.lua new file mode 100644 index 0000000..519b3ff --- /dev/null +++ b/src/SCRIPTS/TELEMETRY/x7home.lua @@ -0,0 +1,124 @@ +-- local rssi, alarm_low, alarm_crit = getRSSI() +local layout = { + { + { + id="stairs", + opts={ + lbl="TX Batt", + src=function() + local settings = getGeneralSettings() + return math.floor(((getValue("tx-voltage")-settings.battMin) * 100 / (settings.battMax-settings.battMin)) + 0.5) + end, + stairs=8, + space=1, + p={r=0,b=3} --??? + } + }, + { + id="stairs", + opts={ + lbl="VFAS", + src=function() + local settings = getGeneralSettings() + local min = 14 + local max = 16.8 + return math.floor(((getValue("VFAS")-min) * 100 / (max-min)) + 0.5) + end, + stairs=8, + space=1, + p={r=0,b=3} --??? + } + }, + -- { + -- id="value", + -- opts={ + -- lbl="Model", + -- src=function() local m = model.getInfo() return m.name end, + -- } + -- }, + -- { + -- id="value", + -- opts={ + -- lbl="VFAS", + -- src="VFAS", + -- unit="V", + -- min=14, + -- } + -- }, + { + id="value", + opts={ + lbl="THR Timer", + src=function() return getValue("timer1") end, + unit="timer", + } + }, + }, + { + { + id="value", + opts={ + lbl="Cell (2S)", + src=function() + return getValue("tx-voltage") / 2 * 100 + end, + unit="V", + min=3.5, + style=PREC2, + } + }, + { + id="value", + opts={ + lbl="Cells", + src=function() + local cels = getValue("Cels") + local sum = 0 + for i=1, #cels do + sum = sum + cels[i] + end + return sum / #cels * 100 + end, + unit="V", + min=3.5, + style=PREC2, + } + }, + -- { + -- id="value", + -- opts={ + -- lbl="F-Mode", + -- src=function() + -- return getValue("gvar8") > 0 and getValue("gvar8") or "N/A" + -- end, + -- unit="", + -- } + -- }, + { + id="value", + opts={ + src=function() return getValue("ls4") > 0 and "ARMED" or "" end, + style=BLINK + MIDSIZE, + p={t=4,l=1}, + } + }, + }, + { + { id="rssi" } + }, + -- { + -- { id="rssi", opts={p={l=0}} } + -- }, + -- { + -- { id="graph", opts={uid=5, src="thr", lbl="THR", unit="%", speed=50, min=-1000, max=1000, lblmax="max", lblmin="min", p={r=18}} }, + -- { id="graph", opts={uid=6, src=function() return getGraphAverage(5) end, lbl="THR AVRG", unit="%", speed=50, min=-1000, max=1000, lblmax="max", lblmin="min", p={r=18}} }, + -- --[[,"../TELEMETRY/graph3"--]] + -- }, + -- {"fm", "gps", "timer"}, + -- {"distance", "altitude", "speed"}, +-- {"batt"}, + -- {"rssi"}, +} +local w = assert(loadScript("/SCRIPTS/WIDGETS/widgets.lua"))(layout) + +return { init=w.init, run=w.run } diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh00.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh00.bmp new file mode 100644 index 0000000..f4b6e99 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh00.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh01.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh01.bmp new file mode 100644 index 0000000..1696bec Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh01.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh02.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh02.bmp new file mode 100644 index 0000000..fc33de9 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh02.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh03.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh03.bmp new file mode 100644 index 0000000..f9c1323 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh03.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh04.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh04.bmp new file mode 100644 index 0000000..6b1595b Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh04.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh05.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh05.bmp new file mode 100644 index 0000000..c3a239b Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh05.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh06.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh06.bmp new file mode 100644 index 0000000..4f45758 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh06.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh07.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh07.bmp new file mode 100644 index 0000000..9c14e95 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh07.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh08.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh08.bmp new file mode 100644 index 0000000..6443bd7 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh08.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh09.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh09.bmp new file mode 100644 index 0000000..55cbe0c Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh09.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh10.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh10.bmp new file mode 100644 index 0000000..e7ce091 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/RSSIh10.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/dist.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/dist.bmp new file mode 100644 index 0000000..34276ef Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/dist.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/fm.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/fm.bmp new file mode 100644 index 0000000..02fb652 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/fm.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/gps_0.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/gps_0.bmp new file mode 100644 index 0000000..5bc55b6 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/gps_0.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/gps_1.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/gps_1.bmp new file mode 100644 index 0000000..d2f0c59 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/gps_1.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/gps_2.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/gps_2.bmp new file mode 100644 index 0000000..f31f228 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/gps_2.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/gps_3.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/gps_3.bmp new file mode 100644 index 0000000..400adf1 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/gps_3.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/gps_4.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/gps_4.bmp new file mode 100644 index 0000000..1de06d1 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/gps_4.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/gps_5.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/gps_5.bmp new file mode 100644 index 0000000..29edf2e Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/gps_5.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/gps_6.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/gps_6.bmp new file mode 100644 index 0000000..50d49e6 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/gps_6.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/hgt.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/hgt.bmp new file mode 100644 index 0000000..d54d8c2 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/hgt.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/sat0.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/sat0.bmp new file mode 100644 index 0000000..0ef202d Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/sat0.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/sat1.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/sat1.bmp new file mode 100644 index 0000000..d115010 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/sat1.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/sat2.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/sat2.bmp new file mode 100644 index 0000000..b88aa87 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/sat2.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/sat3.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/sat3.bmp new file mode 100644 index 0000000..507b732 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/sat3.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/speed.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/speed.bmp new file mode 100644 index 0000000..bf14fc6 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/speed.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/BMP/timer_1.bmp b/src/SCRIPTS/WIDGETS/X9/BMP/timer_1.bmp new file mode 100644 index 0000000..7d98a40 Binary files /dev/null and b/src/SCRIPTS/WIDGETS/X9/BMP/timer_1.bmp differ diff --git a/src/SCRIPTS/WIDGETS/X9/altitude.lua b/src/SCRIPTS/WIDGETS/X9/altitude.lua new file mode 100644 index 0000000..50eb956 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/altitude.lua @@ -0,0 +1,16 @@ +local function altitudeWidget(zone) + + lcd.drawPixmap(zone.x+1, zone.y+2, "/SCRIPTS/WIDGETS/X9/BMP/hgt.bmp") + + local height = getValue("GAlt") + if simModeOn == 1 then + height = theight + end + + lcd.drawNumber(zone.x+18, zone.y+7, height, LEFT) + lcd.drawText(lcd.getLastPos(), zone.y+7, "m", 0) + + lcd.drawLine(zone.x, zone.h-1, zone.x+zone.w, zone.h-1, SOLID, GREY_DEFAULT) +end + +return { run=altitudeWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/distance.lua b/src/SCRIPTS/WIDGETS/X9/distance.lua new file mode 100644 index 0000000..1a9b1b8 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/distance.lua @@ -0,0 +1,16 @@ +local function distWidget(zone) + + lcd.drawPixmap(zone.x+1, zone.y+2, "/SCRIPTS/WIDGETS/X9/BMP/dist.bmp") + + local dist = getValue("Dist") + if simModeOn == 1 then + dist = tdist + end + + lcd.drawNumber(zone.x+18, zone.y+7, dist, LEFT) + lcd.drawText(lcd.getLastPos(), zone.y+7, "m", 0) + + lcd.drawLine(zone.x, zone.y-1, zone.x+zone.w, zone.y-1, SOLID, GREY_DEFAULT) +end + +return { run=distWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/gps.lua b/src/SCRIPTS/WIDGETS/X9/gps.lua new file mode 100644 index 0000000..7086e9e --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/gps.lua @@ -0,0 +1,28 @@ +local function gpsWidget(zone) + + local sats = getValue("Sats") + local fix = getValue("Fix") + + local fixImg = "/SCRIPTS/WIDGETS/X9/BMP/sat0.bmp" + if fix == 2 then fixImg = "/SCRIPTS/WIDGETS/X9/BMP/sat1.bmp" + elseif fix == 3 then fixImg = "/SCRIPTS/WIDGETS/X9/BMP/sat2.bmp" + elseif fix == 4 then fixImg = "/SCRIPTS/WIDGETS/X9/BMP/sat3.bmp" + end + + local satImg = "/SCRIPTS/WIDGETS/X9/BMP/gps_0.bmp" + if sats > 5 then satImg = "/SCRIPTS/WIDGETS/X9/BMP/gps_6.bmp" + elseif sats > 4 then satImg = "/SCRIPTS/WIDGETS/X9/BMP/gps_5.bmp" + elseif sats > 3 then satImg = "/SCRIPTS/WIDGETS/X9/BMP/gps_4.bmp" + elseif sats > 2 then satImg = "/SCRIPTS/WIDGETS/X9/BMP/gps_3.bmp" + elseif sats > 1 then satImg = "/SCRIPTS/WIDGETS/X9/BMP/gps_2.bmp" + elseif sats > 0 then satImg = "/SCRIPTS/WIDGETS/X9/BMP/gps_1.bmp" + end + + lcd.drawPixmap(zone.x+1, zone.y+1, fixImg) + lcd.drawPixmap(zone.x+13, zone.y+3, satImg) + lcd.drawNumber(zone.x+19, zone.y+1, sats, SMLSIZE) + + lcd.drawLine(zone.x, zone.y-1, zone.x+zone.w, zone.y-1, SOLID, GREY_DEFAULT) +end + +return { run=gpsWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/heading.lua b/src/SCRIPTS/WIDGETS/X9/heading.lua new file mode 100644 index 0000000..bfd04c0 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/heading.lua @@ -0,0 +1,13 @@ +local function headingWidget(zone) + + lcd.drawPixmap(zone.x+1, zone.y+2, "/SCRIPTS/WIDGETS/X9/BMP/compass.bmp") + + local heading = getValue("Hdg") + + lcd.drawNumber(zone.x+18, zone.y+7, heading, LEFT) + lcd.drawText(lcd.getLastPos(), zone.y+7, "dg", 0) + + lcd.drawLine(zone.x, zone.y-1, zone.x+zone.w, zone.y-1, SOLID, GREY_DEFAULT) +end + +return { run=headingWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/mode.lua b/src/SCRIPTS/WIDGETS/X9/mode.lua new file mode 100644 index 0000000..755c2e1 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/mode.lua @@ -0,0 +1,29 @@ +local function fmWidget(zone) + + lcd.drawPixmap(zone.x+1, zone.y+2, "/SCRIPTS/WIDGETS/X9/BMP/fm.bmp") + + local mode = " ?" + local style = MIDSIZE + + if getValue("RSSI") <= 20 then + mode = "N/A" + style = style + BLINK + elseif getValue("ch8") > 0 then + mode = "COFF" + style = style + BLINK + INVERS + elseif getValue("ch7") > 0 then + mode = "RTH" + elseif getValue("ch5") < 0 then + mode = "POS" + elseif getValue("ch5") == 0 then + mode = "STA" + elseif getValue("ch5") > 0 then + mode = "ALT" + end + + lcd.drawText(zone.x+20, zone.y+4, mode, style) + + lcd.drawLine(zone.x, zone.y-1, zone.x+zone.w, zone.y-1, SOLID, GREY_DEFAULT) +end + +return { run=fmWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/rssi.lua b/src/SCRIPTS/WIDGETS/X9/rssi.lua new file mode 100644 index 0000000..497fdd7 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/rssi.lua @@ -0,0 +1,25 @@ +local function rssiWidget(zone, event) + local db, alarm_low, alarm_crit = getRSSI() + local perc = 0 + local pixmap = "00" + + if db > alarm_crit then + perc = (math.log(db-28, 10) - 1) / (math.log(72, 10) - 1) * 100 + end + + if perc >= 99 then + pixmap = "10" + else + for i=1, 10 do + if perc >= i*10 and perc < i*10+10 then + pixmap = "0"..i + break + end + end + end + + lcd.drawPixmap(zone.x+4, zone.y+1, "/SCRIPTS/WIDGETS/X9/BMP/RSSIh"..pixmap..".bmp") + lcd.drawText(zone.x+6, zone.y+54, db .. "dB", 0) +end + +return { run=rssiWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/speed.lua b/src/SCRIPTS/WIDGETS/X9/speed.lua new file mode 100644 index 0000000..7db01a9 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/speed.lua @@ -0,0 +1,13 @@ +local function speedWidget(zone) + + lcd.drawPixmap(zone.x+1, zone.y+2, "/SCRIPTS/WIDGETS/X9/BMP/speed.bmp") + + local speed = getValue("GSpd") * 3.6 + + lcd.drawNumber(zone.x+18, zone.y+7, speed, LEFT) + lcd.drawText(lcd.getLastPos(), zone.y+7, "kmh", 0) + + lcd.drawLine(zone.x, zone.y-1, zone.x+zone.w, zone.y-1, SOLID, GREY_DEFAULT) +end + +return { run=speedWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/timer.lua b/src/SCRIPTS/WIDGETS/X9/timer.lua new file mode 100644 index 0000000..58f4621 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/timer.lua @@ -0,0 +1,9 @@ +local function timerWidget(zone) + + lcd.drawPixmap(zone.x+1, zone.y+3, "/SCRIPTS/WIDGETS/X9/BMP/timer_1.bmp") + lcd.drawTimer(zone.x+18, zone.y+8, getValue(196), 0) + + lcd.drawLine(zone.x, zone.y-1, zone.x+zone.w, zone.y-1, SOLID, GREY_DEFAULT) +end + +return { run=timerWidget } diff --git a/src/SCRIPTS/WIDGETS/X9/tx-batt.lua b/src/SCRIPTS/WIDGETS/X9/tx-batt.lua new file mode 100644 index 0000000..cc8b8c4 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/X9/tx-batt.lua @@ -0,0 +1,40 @@ +local function batteryWidget(zone, event) + local cellV = getValue("tx-voltage") + local settings = getGeneralSettings() + local maxV = settings.battMax + local minV = settings.battMin + local cellRange = maxV - minV + local availV = 0 + local z = zone + + lcd.drawFilledRectangle(z.x+13, z.y+7, 5, 2, 0) + lcd.drawRectangle(z.x+10, z.y+9, 11, 40) + + if cellV > maxV then + availV = cellRange + elseif cellV > minV then + availV = cellV - minV + end + local availPerc = math.floor(availV / cellRange * 100) + + local myPxHeight = math.floor(availPerc * 0.37) + local myPxY = 11 + 37 - myPxHeight + if availPerc > 0 then + lcd.drawFilledRectangle(z.x+11, myPxY, 9, myPxHeight, 0) + end + + local i = 36 + while (i > 0) do + lcd.drawLine(z.x+12, z.y+10+i, z.x+18, z.y+10+i, SOLID, GREY_DEFAULT) + i = i-2 + end + + local style = PREC2 + LEFT + if (cellV < minV) then + style = style + BLINK + end + lcd.drawNumber(z.x+5, z.y+53, cellV*100, style) + lcd.drawText(lcd.getLastPos(), z.y+53, "V", 0) +end + +return { run=batteryWidget } diff --git a/src/SCRIPTS/WIDGETS/batt.lua b/src/SCRIPTS/WIDGETS/batt.lua new file mode 100644 index 0000000..1334874 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/batt.lua @@ -0,0 +1,79 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Renders a vertical (B->T) battery picto from a given source. + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: display height, fixed + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + src: sensor-ID string/number (optional, default "tx-voltage") + - Data source + + max: number (only optional, if 'src' is default) + - Largest value + + min: number (only optional, if 'src' is default) + - Smallest value + + p: table (optional, default [t=0, r=0, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function batteryWidget(zone, event, opts) + local src = opts.src or "tx-voltage" + + local settings = getGeneralSettings() + local maxV = opts.max or settings.battMax + local minV = opts.min or settings.battMin + local cellRange = maxV - minV + local availV = 0 + local z = calcWidgetZone(zone, p, opts.p or false) + local cellV = getValue(src) + + lcd.drawFilledRectangle(z.x+13, z.y+7, 5, 2, 0) + lcd.drawRectangle(z.x+10, z.y+9, 11, 40) + + if cellV > maxV then + availV = cellRange + elseif cellV > minV then + availV = cellV - minV + end + local availPerc = math.floor(availV / cellRange * 100) + + local myPxHeight = math.floor(availPerc * 0.37) + local myPxY = 11 + 37 - myPxHeight + if availPerc > 0 then + lcd.drawFilledRectangle(z.x+11, myPxY, 9, myPxHeight, 0) + end + + local i = 36 + while (i > 0) do + lcd.drawLine(z.x+12, z.y+10+i, z.x+18, z.y+10+i, SOLID, INVERS) + i = i-2 + end + + local style = PREC2 + LEFT + if (cellV < minV) then + style = style + BLINK + end + lcd.drawNumber(z.x+5, z.y+53, cellV*100, style) + lcd.drawText(lcd.getLastPos(), z.y+53, "V", 0) +end + +return { run=batteryWidget } diff --git a/src/SCRIPTS/WIDGETS/batt2.lua b/src/SCRIPTS/WIDGETS/batt2.lua new file mode 100644 index 0000000..e2253ce --- /dev/null +++ b/src/SCRIPTS/WIDGETS/batt2.lua @@ -0,0 +1,69 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Renders a vertical (B->T) battery picto from a given source. + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: display height, fixed + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + src: sensor-ID string/number (optional, default "tx-voltage") + - Data source + + max: number (only optional, if 'src' is default) + - Largest value + + min: number (only optional, if 'src' is default) + - Smallest value + + p: table (optional, default [t=0, r=0, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function batteryWidget(zone, event, opts) + local src = opts.src or "tx-voltage" + + local settings = getGeneralSettings() + local maxV = opts.max or settings.battMax + local minV = opts.min or settings.battMin + local format = PREC1 + LEFT + local cellV = getValue(src) + local perc = math.floor(((cellV-minV) * 100 / (maxV-minV)) + 0.5) + local z = calcWidgetZone(zone, p, opts.p or false) + + if perc <= 0 then perc = 0 end + + if cellV <= minV then + format = format+BLINK + end + + lcd.drawFilledRectangle(z.x+12, z.y+2, 7, 2, 0) + lcd.drawRectangle(z.x+8, z.y+4, 15, 47) + lcd.drawRectangle(z.x+9, z.y+5, 13, 45) + + local i = 40 + while i > 0 and i > 40-math.floor(perc * .4) do + lcd.drawLine(z.x+11, z.y+7+i, z.x+19, z.y+7+i, SOLID, 0) + lcd.drawLine(z.x+11, z.y+7+i-1, z.x+19, z.y+7+i-1, SOLID, 0) + i = i-3 + end + lcd.drawNumber(z.x+7, z.y+54, cellV*10, format) + lcd.drawText(lcd.getLastPos(), z.y+54, "V", format) +end + +return { run=batteryWidget } diff --git a/src/SCRIPTS/WIDGETS/batt3.lua b/src/SCRIPTS/WIDGETS/batt3.lua new file mode 100644 index 0000000..654b590 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/batt3.lua @@ -0,0 +1,77 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Renders a vertical (B->T) battery picto from a given source. + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: display height, fixed + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + src: sensor-ID string/number (optional, default "tx-voltage") + - Data source + + lbl: string (optional) + - Label text + + max: number (only optional, if 'src' is default) + - Largest value + + min: number (only optional, if 'src' is default) + - Smallest value + + p: table (optional, default [t=0, r=2, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function batteryWidget(zone, event, opts) + local src = opts.src or "tx-voltage" + local p = { t=0, r=2, b=0, l=0 } + + local settings = getGeneralSettings() + local maxV = opts.max or settings.battMax + local minV = opts.min or settings.battMin + local format = PREC1 + LEFT + local cellV = getValue(src) + local perc = math.floor(((cellV-minV) * 100 / (maxV-minV)) + 0.5) + local z = calcWidgetZone(zone, p, opts.p or false) + + if perc <= 0 then perc = 0 end + + if cellV <= minV then + format = format+BLINK + end + + if opts.lbl then + lcd.drawFilledRectangle(z.x, z.y, z.w, 8) + lcd.drawText(z.x + 1, z.y + 1, opts.lbl, SMLSIZE + INVERS) + end + + lcd.drawFilledRectangle(z.x+12, z.y+10, 7, 1, 0) + lcd.drawRectangle(z.x+8, z.y+11, 15, 41) + lcd.drawRectangle(z.x+9, z.y+12, 13, 39) + + local i = 36 + while i > 0 and i > 36-math.floor(perc * .36) do + lcd.drawLine(z.x+11, z.y+12+i, z.x+19, z.y+12+i, SOLID, 0) + i = i-2 + end + lcd.drawNumber(z.x+7, z.y+54, cellV*10, format) + lcd.drawText(lcd.getLastPos(), z.y+54, "V", format) +end + +return { run=batteryWidget } diff --git a/src/SCRIPTS/WIDGETS/h-bar.lua b/src/SCRIPTS/WIDGETS/h-bar.lua new file mode 100644 index 0000000..8e6008f --- /dev/null +++ b/src/SCRIPTS/WIDGETS/h-bar.lua @@ -0,0 +1,74 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Draws a horizontal (L->R) bar from a given percent value. + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: scalable + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + src: function or sensor-ID string/number + - Data source in percent (0..100) + + lbl: string (optional) + - Label text + + space: number (optional, default 0) + - Divide bar with vert spaces in px + + bg: bool (optional, default false) + - Show background + + p: table (optional, default [t=0, r=0, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function barWidget(zone, event, opts) + local p = { t=0, r=0, b=0, l=0 } + + local z = calcWidgetZone(zone, p, opts.p or false) + local val = type(opts.src) == "function" + and opts.src() + or getValue(opts.src) + + if opts.lbl then + lcd.drawFilledRectangle(z.x, z.y, z.w, 8) + lcd.drawText(z.x + 1, z.y + 1, opts.lbl, SMLSIZE + INVERS) + z.y = z.y + 9 + z.h = z.h - 8 + end + + local lnX = z.x + local spc = opts.space or 0 + + for i=1, z.w, 1 do + if val > 100 / z.w * (lnX - z.x) then + lnX = z.x + i + i * spc + lcd.drawLine(lnX-1, z.y, lnX-1, z.y + z.h, SOLID, 0) + else + if opts.bg and lnX/2 == math.floor(lnX/2) and lnX < z.x + z.w then + for j=0, z.h, 2 do + lcd.drawPoint(lnX + (val > 1 and spc or 0), z.y + j) + end + end + lnX = lnX + 1 + end + end +end + +return { run=barWidget } diff --git a/src/SCRIPTS/WIDGETS/rssi.lua b/src/SCRIPTS/WIDGETS/rssi.lua new file mode 100644 index 0000000..dc2d483 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/rssi.lua @@ -0,0 +1,61 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Renders a vertical (B->T) RSSI bar indicator using getRSSI(). + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: display height, fixed + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + p: table (optional, default [t=0, r=0, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function rssiWidget(zone, event, opts) + local pxRng = 45 + + local z = calcWidgetZone(zone, false, opts.p or false) + local db, alarm_low, alarm_crit = getRSSI() + local perc = math.floor(((db-alarm_crit) * 100 / (99-alarm_crit)) + 0.5) + local format = PREC1 + LEFT + + if perc <= 0 then perc = 0 end + + if db <= alarm_low then + format = format+BLINK + end + + local wOfs = 1 + local i = pxRng + while i > 0 and i > pxRng-math.floor(perc * (pxRng/100)) do + local x1 = z.x+14-wOfs + local y1 = z.y+2+i + local x2 = z.x+16+wOfs + local y2 = z.y+2+i + + lcd.drawLine(x1, y1, x2, y2, SOLID, 0) + lcd.drawLine(x1+1, y1+1, x2-1, y2+1, SOLID, 0) + + i = i-4 + wOfs = wOfs + 1 + end + + lcd.drawText(z.x + 5, z.y + z.h - 11, db .. "dB", format) +end + +return { run=rssiWidget } diff --git a/src/SCRIPTS/WIDGETS/rssi2.lua b/src/SCRIPTS/WIDGETS/rssi2.lua new file mode 100644 index 0000000..c9a927d --- /dev/null +++ b/src/SCRIPTS/WIDGETS/rssi2.lua @@ -0,0 +1,60 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Renders a vertical (B->T) RSSI bar indicator using getRSSI(). + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: display height, fixed + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + p: table (optional, default [t=0, r=0, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function rssiWidget(zone, event, opts) + local pxRng = 45 + + local z = calcWidgetZone(zone, false, opts.p or false) + local db, alarm_low, alarm_crit = getRSSI() + local perc = math.floor(((db-alarm_crit) * 100 / (99-alarm_crit)) + .5) + local format = PREC1 + LEFT + + if perc <= 0 then perc = 0 end + + if db <= alarm_low then + format = format+BLINK + end + + local wOfs = 1 + local i = pxRng + while i > 0 and i > pxRng-math.floor(perc * (pxRng/100)) do + local x1 = math.floor(z.x+15-wOfs) + local y1 = z.y+2+i + local x2 = math.ceil(z.x+15+wOfs) + local y2 = z.y+2+i + + lcd.drawLine(x1, y1, x2, y2, SOLID, 0) + + i = i-2 + wOfs = wOfs + .5 + end + + lcd.drawText(z.x + 5, z.y + z.h - 11, db .. "dB", format) +end + +return { run=rssiWidget } diff --git a/src/SCRIPTS/WIDGETS/stairs.lua b/src/SCRIPTS/WIDGETS/stairs.lua new file mode 100644 index 0000000..1029ab7 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/stairs.lua @@ -0,0 +1,78 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Renders a horizontal (L->R) stair graph from a given percent value. + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: scalable + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + src: function or sensor-ID string/number + - Data source in percent (0..100) + + lbl: string (optional) + - Label text + + stairs: number (optional, default 5) + - Stair count + + space: number (optional, default 1) + - Space between stairs/bars in px + + p: table (optional, default [t=0, r=2, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function stairsWidget(zone, event, opts) + local p = { t=0, r=2, b=0, l=0 } + local stairs = opts.stairs or 5 + local space = opts.space or 1 + + local z = calcWidgetZone(zone, p, opts.p or false) + local val = type(opts.src) == "function" + and opts.src() + or getValue(opts.src) + + if opts.lbl then + lcd.drawFilledRectangle(z.x, z.y, z.w, 8) + lcd.drawText(z.x + 1, z.y + 1, opts.lbl, SMLSIZE + INVERS) + z.y = z.y + 9 + z.h = z.h - 8 + end +--lcd.drawRectangle(z.x, z.y, z.w, z.h) + local hUnit = math.floor(z.h / stairs) + + + for i=1, stairs do + local barW = math.ceil(z.w / stairs) + local barH = z.h - ((i-1) * hUnit) + local barY = z.y + z.h - barH + local barX = z.x + ((stairs - i) * barW) + + + if barX + barW > z.x + z.w then + barW = (((barX - z.x + barW) - z.w) - barW) *-1 + end + + if val > 100 / z.w * (barX - z.x) then + lcd.drawFilledRectangle(barX + space, barY, barW - space, barH) + end + end +end + +return { run=stairsWidget } diff --git a/src/SCRIPTS/WIDGETS/value.lua b/src/SCRIPTS/WIDGETS/value.lua new file mode 100644 index 0000000..f26a87a --- /dev/null +++ b/src/SCRIPTS/WIDGETS/value.lua @@ -0,0 +1,84 @@ +--[[ ** TELEMETRY SCREEN WIDGET ** + + Draws a string/number/timer from a given source. + + + PLATFORM + X7, X9 and relatives + + SCALING + vert: scalable + horiz: scalable + + PARAMETER + zone: table [x, y, w, h] + - Location on display in px + (x-pos, y-pos, width, height) + + event: int + - User event + + opts: table + - Configurations + + src: function or sensor-ID string/number (optional, default "tx-voltage") + - Data source + + unit: string (optional) + - Unit sign drawn behind the value + - Set to "timer", to display as timer (00:00) + - Set to "%", to output percent of 'src', calculated with 'min' and 'max' + + style: int (optional, default 0) + - Text format + + max: number (only optional, if 'unit' is not "%") + - Largest value + + min: number (only optional, if 'unit' is not "%") + - Smallest value + + p: table (optional, default [t=0, r=2, b=0, l=0]) + - Padding between content and widget boundaries in px + (top, right, bottom, left) +--]] + +local function valueWidget(zone, event, opts) + local p = { t=0, r=2, b=0, l=0 } + local format = opts.style or 0 + + local z = calcWidgetZone(zone, p, opts.p or false) + local val = type(opts.src) == "function" + and opts.src() + or getValue(opts.src) + local tOfs = 0 + + if (opts.min and opts.min > val) or (opts.max and opts.max < val) then + format = format + BLINK + end + + if opts.unit == "%" and opts.max and opts.min then + val = (val + opts.max) * 100 / (opts.max-opts.min) + if val < 0 then val = 0 end + if val > 100 then val = 100 end + end + + if opts.lbl then + tOfs = 10 + lcd.drawFilledRectangle(z.x, z.y, z.w, 8) + lcd.drawText(z.x + 1, z.y + 1, opts.lbl, SMLSIZE + INVERS) + end + + if opts.unit and opts.unit == "timer" then + lcd.drawTimer(z.x + 1, z.y + tOfs, val, format) + else + if type(val) == "string" then + lcd.drawText(z.x + 1, z.y + tOfs, val, format) + else + lcd.drawNumber(z.x + 1, z.y + tOfs, val, format) + end + lcd.drawText(lcd.getLastPos() + 1, z.y + tOfs, opts.unit or "", format) + end +end + +return { run=valueWidget } diff --git a/src/SCRIPTS/WIDGETS/widgets.lua b/src/SCRIPTS/WIDGETS/widgets.lua new file mode 100644 index 0000000..89c88c9 --- /dev/null +++ b/src/SCRIPTS/WIDGETS/widgets.lua @@ -0,0 +1,106 @@ +local widgetWidthSingle = 32 +local widgetWidthMulti = 0 +local numSingleCols = 0 +local numMultiCols = 0 +local widgets = {} +local layout, nested = ... + +local lcd=LCD or lcd +local LCD_W = lcd.W or LCD_W +local LCD_H = lcd.H or LCD_H + +function calcWidgetZone(z, t, t2) + if not t then + t = {t=0, r=0, b=0, l=0} + end + + if t2 then + for i, v in pairs(t2) do + t[i] = v + end + end + + z.x = t.l+z.x + z.y = t.t+z.y + z.w = z.w-t.l-t.r + z.h = z.h-t.t-t.b + + return z +end + +local function run(event, zone) + if #widgets == 0 then return end + + if not nested then lcd.clear() end + + local x = 0 + local y = 0 + local lcdW = LCD_W + + if zone then + x = zone.x + x + y = zone.y + y + lcdW = zone.w + end + + widgetWidthMulti = (lcdW - (numSingleCols * widgetWidthSingle)) / numMultiCols + + if numSingleCols == #widgets then + widgetWidthSingle = math.floor((lcdW / #widgets) + .5) + end + + for col=1, #widgets do + local h = math.floor((LCD_H / #widgets[col]) + .5) + + if zone then + h = math.floor((zone.h / #widgets[col]) + .5) + end + + local w = #widgets[col] == 1 + and widgetWidthSingle + or widgetWidthMulti + + for row=1, #widgets[col] do + local wdgt = widgets[col][row] +--lcd.drawRectangle(x, y, w, h) + + if wdgt.opts.parent then + wdgt.func.run(event, {x=x, y=y, w=w , h=h}) + else + wdgt.func.run({x=x, y=y, w=w , h=h}, event, wdgt.opts) + end + + y = y+h + end + + y = 0 + x = x + w + end +end + +local function init() + for col=1, #layout, 1 + do + if (#layout[col] == 1) then + numSingleCols = numSingleCols + 1 + else + numMultiCols = numMultiCols + 1 + end + + widgets[col] = {} + for row=1, #layout[col], 1 do + local c = layout[col][row] + local w = { run=function()end } + if c.id then + w.opts = c.opts or {} + w.func = assert(loadScript("/SCRIPTS/WIDGETS/"..(c.id)..".lua"))(event) + + -- initalize widget + if w.func.init then w.func.init() end + end + widgets[col][row] = w + end + end +end + +return { init=init, run=run }