some changes to btctrl

This commit is contained in:
speedie 2022-12-31 16:30:32 +01:00
parent 47e5be68a3
commit cd256ff66c

View file

@ -72,31 +72,31 @@ LIST_OPTIONS
# Trust device
TRUST() {
bluetoothctl trust $SELDEVICE_MAC
bluetoothctl trust $SELDEVICE_MAC && return 0 || return 1
}
# Pair device
PAIR() {
bluetoothctl pair $SELDEVICE_MAC
bluetoothctl pair $SELDEVICE_MAC && return 0 || return 1
}
# Remove device
REMOVE() {
bluetoothctl remove $SELDEVICE_MAC
bluetoothctl remove $SELDEVICE_MAC && return 0 || return 1
}
UNTRUST() {
bluetoothctl untrust $SELDEVICE_MAC
bluetoothctl untrust $SELDEVICE_MAC && return 0 || return 1
}
# Connect
CONNECT() {
if [ -e "$/tmp/isconnected" ]; then
if [ -e "/tmp/isconnected" ]; then
NOTIFY_ALREADY_CONNECTED && exit 0
fi
bluetoothctl connect $SELDEVICE_MAC
touch /tmp/isconnected
bluetoothctl connect $SELDEVICE_MAC && isconnected=true
[ "$isconnected" = "true" ] && touch /tmp/isconnected && return 0 || return 1
}
# Disconnect
@ -107,7 +107,11 @@ DISCONNECT() {
# Notification when connecting
NOTIFY_CONNECT() {
if [ "$isconnected" = "true" ]; then
notify-send " Connected to ${USEROPT_1}!"
else
notify-send " Failed to connect to ${USEROPT_1}! Is the device on and available?"
fi
}
# Notification when disconnecting
@ -130,7 +134,7 @@ PERFORM() {
case "$USEROPT_2" in
"Trust") TRUST && LIST_OPTIONS ;;
"Pair") PAIR && LIST_OPTIONS ;;
"Connect") CONNECT && NOTIFY_CONNECT && LIST_OPTIONS ;;
"Connect") CONNECT; NOTIFY_CONNECT ;;
"Disconnect") DISCONNECT && NOTIFY_DISCONNECT && LIST_OPTIONS ;;
"Untrust") UNTRUST && LIST_OPTIONS ;;
"Remove") REMOVE && NOTIFY_REMOVE && LIST_OPTIONS ;;
@ -141,5 +145,3 @@ PERFORM() {
}
PERFORM
$0 && exit 0