hilink: control WFB lifecycle and power from CH6 knob
This commit is contained in:
@@ -3,20 +3,23 @@
|
|||||||
CHANNEL="${1:-}"
|
CHANNEL="${1:-}"
|
||||||
VALUE="${2:-}"
|
VALUE="${2:-}"
|
||||||
|
|
||||||
|
# CH6 is the GX12 WFB knob. Betaflight exposes it as 1000..2000 PWM.
|
||||||
[ "$CHANNEL" = "6" ] || exit 0
|
[ "$CHANNEL" = "6" ] || exit 0
|
||||||
|
|
||||||
case "$VALUE" in
|
case "$VALUE" in
|
||||||
''|*[!0-9]*) exit 2 ;;
|
''|*[!0-9]*) exit 2 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$VALUE" -le 1250 ]; then
|
# First 5% is an explicit OFF detent. Above it WFB starts at 5% and the
|
||||||
logger -t channels "AUX2=$VALUE -> management"
|
# remaining travel maps continuously to 100%. This is a UI-range guard, not a
|
||||||
exec /usr/bin/link-mode management
|
# regulatory EIRP cap.
|
||||||
|
if [ "$VALUE" -le 1050 ]; then
|
||||||
|
rm -f /run/wfb-power
|
||||||
|
logger -t channels "CH6=$VALUE -> management"
|
||||||
|
exec /usr/bin/link-mode management
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$VALUE" -ge 1350 ]; then
|
POWER=$((5 + (VALUE - 1051) * 95 / 949))
|
||||||
logger -t channels "AUX2=$VALUE -> preflight"
|
[ "$POWER" -gt 100 ] && POWER=100
|
||||||
exec /usr/bin/link-mode preflight
|
logger -t channels "CH6=$VALUE -> WFB txpower=$POWER"
|
||||||
fi
|
exec /usr/bin/wfb-power "$POWER"
|
||||||
|
|
||||||
exit 0
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
POWER="${1:-}"
|
||||||
|
LOCK=/run/wfb-power.lock
|
||||||
|
STATE=/run/wfb-power
|
||||||
|
|
||||||
|
case "$POWER" in
|
||||||
|
''|*[!0-9]*) exit 2 ;;
|
||||||
|
esac
|
||||||
|
[ "$POWER" -ge 5 ] && [ "$POWER" -le 100 ] || exit 2
|
||||||
|
|
||||||
|
# The runtime state is tmpfs. Do not rewrite /etc/wfb.yaml while a knob moves.
|
||||||
|
printf '%s\n' "$POWER" >"$STATE"
|
||||||
|
|
||||||
|
if ! mkdir "$LOCK" 2>/dev/null; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
trap 'rmdir "$LOCK" 2>/dev/null || true' EXIT HUP INT TERM
|
||||||
|
|
||||||
|
if pidof wfb_tx wfb_rx wfb_tun wifilink >/dev/null; then
|
||||||
|
# RTL8812EU expects the OpenIPC scalar multiplied by 50 mBm.
|
||||||
|
iw wlan0 set txpower fixed $((POWER * 50))
|
||||||
|
logger -t wfb-power "runtime txpower=$POWER"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
logger -t wfb-power "txpower=$POWER -> WFB preflight"
|
||||||
|
/usr/bin/link-mode preflight
|
||||||
@@ -20,6 +20,12 @@ wfb_yaml() {
|
|||||||
load_config() {
|
load_config() {
|
||||||
wfb_yaml /rom"$wfb_cfg"
|
wfb_yaml /rom"$wfb_cfg"
|
||||||
wfb_yaml "$wfb_cfg"
|
wfb_yaml "$wfb_cfg"
|
||||||
|
if [ -r /run/wfb-power ]; then
|
||||||
|
runtime_txpower=$(cat /run/wfb-power)
|
||||||
|
case "$runtime_txpower" in
|
||||||
|
[5-9]|[1-9][0-9]|100) txpower="$runtime_txpower" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
[ ! -e "$wfb_key" ] && wfb_key=/rom"$wfb_key"
|
[ ! -e "$wfb_key" ] && wfb_key=/rom"$wfb_key"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user