hilink: control WFB lifecycle and power from CH6 knob
This commit is contained in:
@@ -3,20 +3,23 @@
|
||||
CHANNEL="${1:-}"
|
||||
VALUE="${2:-}"
|
||||
|
||||
# CH6 is the GX12 WFB knob. Betaflight exposes it as 1000..2000 PWM.
|
||||
[ "$CHANNEL" = "6" ] || exit 0
|
||||
|
||||
case "$VALUE" in
|
||||
''|*[!0-9]*) exit 2 ;;
|
||||
''|*[!0-9]*) exit 2 ;;
|
||||
esac
|
||||
|
||||
if [ "$VALUE" -le 1250 ]; then
|
||||
logger -t channels "AUX2=$VALUE -> management"
|
||||
exec /usr/bin/link-mode management
|
||||
# First 5% is an explicit OFF detent. Above it WFB starts at 5% and the
|
||||
# remaining travel maps continuously to 100%. This is a UI-range guard, not a
|
||||
# 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
|
||||
|
||||
if [ "$VALUE" -ge 1350 ]; then
|
||||
logger -t channels "AUX2=$VALUE -> preflight"
|
||||
exec /usr/bin/link-mode preflight
|
||||
fi
|
||||
|
||||
exit 0
|
||||
POWER=$((5 + (VALUE - 1051) * 95 / 949))
|
||||
[ "$POWER" -gt 100 ] && POWER=100
|
||||
logger -t channels "CH6=$VALUE -> WFB txpower=$POWER"
|
||||
exec /usr/bin/wfb-power "$POWER"
|
||||
|
||||
@@ -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() {
|
||||
wfb_yaml /rom"$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"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user