Commit f5572935 authored by Igor Pecovnik's avatar Igor Pecovnik
Browse files

Add CLI Bluetooth connector. Tested on Bluetooth with keyboard and mouse.

parent b0c05fb6
...@@ -184,6 +184,48 @@ function get_wlan_interface () ...@@ -184,6 +184,48 @@ function get_wlan_interface ()
exec 3>&- exec 3>&-
fi fi
} }
# search for BT devices and connect
#
function connect_bt_interface ()
{
IFS=$'\r\n'
GLOBIGNORE='*'
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nDiscovering Bluetooth devices ... " 5 37
BT_INTERFACES=($(hcitool scan | sed '1d'))
local LIST=()
for i in "${BT_INTERFACES[@]}"
do
local a=$(echo ${i[0]//[[:blank:]]/} | sed -e 's/^\(.\{17\}\).*/\1/')
local b=${i[0]//$a/}
local b=$(echo $b | sed -e 's/^[ \t]*//')
LIST+=( "$a" "$b")
done
LIST_LENGHT=$((${#LIST[@]}/2));
if [ "$LIST_LENGHT" -eq 0 ]; then
BT_ADAPTER=${WLAN_INTERFACES[0]}
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nNo nearby Bluetooth devices were found!" 7 43
else
exec 3>&1
BT_ADAPTER=$(dialog --backtitle "$BACKTITLE" --no-collapse --title "Select interface" \
--clear --menu "" $((6+${LIST_LENGHT})) 50 15 "${LIST[@]}" 2>&1 1>&3)
exec 3>&-
if [[ $BT_ADAPTER != "" ]]; then
dialog --backtitle "$BACKTITLE" --title "Please wait" --infobox "\nConnecting to $BT_ADAPTER " 5 35
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
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nYour device is ready to use!" 7 32
else
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nError connecting. Try again!" 7 32
fi
fi
fi
}
# #
#-----------------------------------------------------------------------------------------------------------------------------------------# #-----------------------------------------------------------------------------------------------------------------------------------------#
...@@ -212,6 +254,7 @@ while true; do ...@@ -212,6 +254,7 @@ while true; do
[[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "WiFi" "Connect to wireless access point" ) [[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "WiFi" "Connect to wireless access point" )
[[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "Hotspot" "Create WiFi access point" ) [[ -n $(nmcli -f DEVICE,TYPE device status | grep wifi) ]] && LIST+=( "Hotspot" "Create WiFi access point" )
fi fi
[[ $(hcitool dev | sed '1d') != "" ]] && LIST+=( "Bluetooth" "Connect Bluetooth devices" )
[[ -f /usr/bin/h3disp && "$LINUXFAMILY" = "sun8i" && "$BRANCH" = "default" && \ [[ -f /usr/bin/h3disp && "$LINUXFAMILY" = "sun8i" && "$BRANCH" = "default" && \
-n $(bin2fex </boot/script.bin 2>/dev/null | grep -w "hdmi_used = 1") ]] && LIST+=( "Display" "set the display resolution" ) -n $(bin2fex </boot/script.bin 2>/dev/null | grep -w "hdmi_used = 1") ]] && LIST+=( "Display" "set the display resolution" )
[[ -f /usr/sbin/nodm && -n $(service nodm status | grep -w active | grep -w running) ]] && LIST+=( "Desktop" "Disable desktop" ) [[ -f /usr/sbin/nodm && -n $(service nodm status | grep -w active | grep -w running) ]] && LIST+=( "Desktop" "Disable desktop" )
...@@ -546,6 +589,13 @@ while true; do ...@@ -546,6 +589,13 @@ while true; do
;; ;;
# Connect to Bluetooth
#
"Bluetooth" )
dialog --backtitle "$BACKTITLE" --title "Bluetooth" --msgbox "\nMake sure your Bluetooth devices are discoverable!" 7 54
connect_bt_interface
;;
# Edit boot environment # Edit boot environment
# #
"Bootenv" ) "Bootenv" )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment