Skip to content

Commit

Permalink
fixed bt connect.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tearran committed Apr 3, 2024
1 parent e005537 commit de8ce9a
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions config.ng.functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function connect_bt_interface(){

IFS=$'\r\n'
GLOBIGNORE='*'
echo -e "\nDiscovering Bluetooth devices ... " | show_infobox
show_infobox <<< "\nDiscovering Bluetooth devices ... "
BT_INTERFACES=($(hcitool scan | sed '1d'))

local LIST=()
Expand All @@ -244,25 +244,24 @@ function connect_bt_interface(){
LIST_LENGTH=$((${#LIST[@]}/2));
if [ "$LIST_LENGTH" -eq 0 ]; then
BT_ADAPTER=${WLAN_INTERFACES[0]}
echo -e "\nNo nearby Bluetooth devices were found!" | show_message
show_message <<< "\nNo nearby Bluetooth devices were found!"
else
exec 3>&1
#BT_ADAPTER=$(dialog --backtitle "$BACKTITLE" --no-collapse --title "Select interface" \
#--clear --menu "" $((6+${LIST_LENGTH})) 50 15 "${LIST[@]}" 2>&1 1>&3)
BT_ADAPTER=$( echo "${LIST[@]}" | show_menu )
BT_ADAPTER=$(whiptail --title "Select interface" \
--clear --menu "" $((6+${LIST_LENGTH})) 50 $LIST_LENGTH "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
if [[ $BT_ADAPTER != "" ]]; then
echo -e "\nConnecting to $BT_ADAPTER " | show_infobox
show_infobox <<< "\nConnecting to $BT_ADAPTER "
BT_EXEC=$(
expect -c 'set prompt "#";set address '$BT_ADAPTER';spawn bluetoothctl;expect -re $prompt;send "disconnect $address\r";
sleep 1;send "remove $address\r";sleep 1;expect -re $prompt;send "scan on\r";sleep 8;send "scan off\r";
expect "Controller";send "trust $address\r";sleep 2;send "pair $address\r";sleep 2;send "connect $address\r";
send_user "\nShould be paired now.\r";sleep 2;send "quit\r";expect eof')
echo "$BT_EXEC" > /tmp/bt-connect-debug.log
if [[ $(echo "$BT_EXEC" | grep "Connection successful" ) != "" ]]; then
echo -e "\nYour device is ready to use!" | show_message
show_message <<< "\nYour device is ready to use!"
else
echo -e "\nError connecting. Try again!" | show_message
show_message <<< "\nError connecting. Try again!"
fi
fi
fi
Expand Down

0 comments on commit de8ce9a

Please sign in to comment.