Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Config
Commits
f5572935
Commit
f5572935
authored
Jun 16, 2017
by
Igor Pecovnik
Browse files
Add CLI Bluetooth connector. Tested on Bluetooth with keyboard and mouse.
parent
b0c05fb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
debian-config
View file @
f5572935
...
@@ -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
"
\n
Discovering 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
"
\n
No 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
"
\n
Connecting 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
"
\n
Your device is ready to use!"
7 32
else
dialog
--backtitle
"
$BACKTITLE
"
--title
"Bluetooth"
--msgbox
"
\n
Error 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
"
\n
Make sure your Bluetooth devices are discoverable!"
7 54
connect_bt_interface
;;
# Edit boot environment
# Edit boot environment
#
#
"Bootenv"
)
"Bootenv"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment