Skip to content

Commit 411b4eb

Browse files
committed
bluetooth - only show unregistered devices when scanning to simplify use
Before when looking for devices to pair with, previously registered devices could be shown which can make it confusing with multiple gamepads with the same name as to which to add
1 parent dd0cb8c commit 411b4eb

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

scriptmodules/supplementary/bluetooth.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,36 @@ function list_available_bluetooth() {
8585
local device_name
8686
local info_text="\n\nSearching ..."
8787

88+
declare -A registered=()
89+
declare -A found=()
90+
91+
# get an asc array of registered mac addresses
92+
while read mac_address; read device_name; do
93+
registered+=(["$mac_address"]="$device_name")
94+
done < <(list_registered_bluetooth)
95+
8896
# sixaxis: add USB pairing information
8997
[[ -n "$(lsmod | grep hid_sony)" ]] && info_text="Searching ...\n\nDualShock registration: while this text is visible, unplug the controller, press the PS/SHARE button, and then replug the controller."
9098

9199
dialog --backtitle "$__backtitle" --infobox "$info_text" 7 60 >/dev/tty
92100
if hasPackage bluez 5; then
93101
# sixaxis: reply to authorization challenge on USB cable connect
94102
while read mac_address; read device_name; do
95-
echo "$mac_address"
96-
echo "$device_name"
97-
done < <(bluez_cmd_bluetooth "default-agent\nscan on" "15" "Authorize service$" "yes" >/dev/null; bluez_cmd_bluetooth "devices" "3" | grep "^Device " | cut -d" " -f2,3- | sed 's/ /\n/')
103+
found+=(["$mac_address"]="$device_name")
104+
done < <(bluez_cmd_bluetooth "default-agent\nscan on" "15" "Authorize service$" "yes" >/dev/null; bluez_cmd_bluetooth "devices" "3" | grep "^Device " | cut -d" " -f2,3- | sed 's/ /\n/')
98105
else
99106
while read; read mac_address; read device_name; do
100-
echo "$mac_address"
101-
echo "$device_name"
107+
found+=(["$mac_address"]="$device_name")
102108
done < <(hcitool scan --flush | tail -n +2 | sed 's/\t/\n/g')
103109
fi
110+
111+
# display any found addresses that are not already registered
112+
for mac_address in "${!found[@]}"; do
113+
if [[ -z "${registered[$mac_address]}" ]]; then
114+
echo "$mac_address"
115+
echo "${found[$mac_address]}"
116+
fi
117+
done
104118
}
105119

106120
function list_registered_bluetooth() {

0 commit comments

Comments
 (0)