Add scan/pair to BT menu

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
master
Julian P Samaroo 4 years ago committed by Maarten van Gompel
parent 95ac330d0b
commit cf876823fb
  1. 30
      scripts/core/sxmo_bluetoothmenu.sh

@ -1,9 +1,25 @@
#!/usr/bin/env sh #!/usr/bin/env sh
connect() {
if bluetoothctl info "$1" | grep Connected | grep -q no; then
bluetoothctl discoverable on
if bluetoothctl info "$1" | grep Paired | grep -q no; then
bluetoothctl pairable on
notify-send "Pairing with $1..."
bluetoothctl --timeout=10 pair "$1" || notify-send "Pairing failed" && return
bluetoothctl trust "$1" || notify-send "Trusting failed" && return
fi
bluetoothctl --timeout=5 connect "$1" || notify-send "Connecting failed" && return
fi
}
devicemenu() { devicemenu() {
if bluetoothctl show | grep Powered | grep -q no; then
bluetoothctl power on
fi
while true; do while true; do
DEVICES="$(bluetoothctl devices | awk '{ $1=""; printf $2; $2=""; printf " ^" $0 "\n" }')" DEVICES="$(bluetoothctl devices | awk '{ $1=""; printf $2; $2=""; printf " ^" $0 "\n" }')"
ENTRIES="$(echo "$DEVICES" | sed 's|.* ^ ||' | xargs -0 printf "Close Menu\nDisconnect\n%s")" ENTRIES="$(echo "$DEVICES" | sed 's|.* ^ ||' | xargs -0 printf "Close Menu\nDisconnect\nScan\n%s")"
PICKED="$( PICKED="$(
echo "$ENTRIES" | echo "$ENTRIES" |
@ -14,12 +30,20 @@ devicemenu() {
exit exit
elif echo "$PICKED" | grep -q "Disconnect"; then elif echo "$PICKED" | grep -q "Disconnect"; then
st -e sh -c "bluetoothctl disconnect; sleep 1" st -e sh -c "bluetoothctl disconnect; sleep 1"
continue elif echo "$PICKED" | grep -q "Scan"; then
notify-send "Scanning BT devices for 5 seconds..."
bluetoothctl --timeout=5 scan on
else else
devicemac="$(echo "$DEVICES" | grep " \^ $PICKED$" | sed 's| ^ .*||' )" devicemac="$(echo "$DEVICES" | grep " \^ $PICKED$" | sed 's| ^ .*||' )"
st -e sh -c "bluetoothctl connect $devicemac; sleep 1" st -e sh -c "$0 connect $devicemac"
bluetoothctl pairable off
bluetoothctl discoverable off
fi fi
done done
} }
if [ -n "$1" ]; then
"$@"
else
devicemenu devicemenu
fi

Loading…
Cancel
Save