-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
168 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.0.0 | ||
2.0.1 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Set up variables | ||
VOLUME_UP_GPIO=$(</usr/src/volume_up_gpio) | ||
|
||
BLUETOOTH_GPIO=$(</usr/src/bluetooth_gpio) | ||
|
||
VOLUME_DOWN_GPIO=$(</usr/src/volume_down_gpio) | ||
|
||
TIMER="0" | ||
|
||
BLUETOOTH_DISCOVERABLE="0" | ||
|
||
# Set up + volume | ||
if [[ ! -d /sys/class/gpio/gpio$VOLUME_UP_GPIO ]]; then | ||
echo "$VOLUME_UP_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$VOLUME_UP_GPIO/direction | ||
|
||
# Set up bluetooth | ||
if [[ ! -d /sys/class/gpio/gpio$BLUETOOTH_GPIO ]]; then | ||
echo "$BLUETOOTH_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$BLUETOOTH_GPIO/direction | ||
|
||
# Set up - volume | ||
if [[ ! -d /sys/class/gpio/gpio$VOLUME_DOWN_GPIO ]]; then | ||
echo "$VOLUME_DOWN_GPIO" > /sys/class/gpio/export | ||
sleep 1 | ||
fi | ||
echo "in" > /sys/class/gpio/gpio$VOLUME_DOWN_GPIO/direction | ||
|
||
while : ; do | ||
|
||
DEVICE="$(echo "$(amixer -D bluealsa scontrols)" | sed -n " s,[^']*'\([^']*\).*,\1,p ")" | ||
MAC="$(cat /var/cache/bluetooth/reconnect_device)" | ||
MAC_PARSED="$(echo ${MAC//:/_})" | ||
# PLAYER_ADDRESS="$(echo "$(dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED org.freedesktop.DBus.Properties.Get string:org.bluez.MediaControl1 string:Player)" | cut -d'"' -f 2)" | ||
|
||
while [[ "$(cat /sys/class/gpio/gpio$BLUETOOTH_GPIO/value)" == 1 ]]; do | ||
if [[ "$TIMER" < 3 ]]; then | ||
TIMER=$((TIMER+1)) | ||
sleep 1 | ||
fi | ||
done | ||
|
||
if [[ "$TIMER" == 3 ]]; then | ||
if [[ ! -a /usr/src/is_discoverable ]]; then | ||
printf "Making the device for 3 min discoverable. \n" | ||
hciconfig hci0 up | ||
touch /usr/src/is_discoverable | ||
(sleep 180 ; hciconfig hci0 down ; rm /usr/src/is_discoverable) & | ||
else | ||
printf "The device is already discoverable. \n" | ||
fi | ||
fi | ||
|
||
if [[ ! -z "$(echo "$(amixer -D bluealsa scontrols)" | sed -n " s,[^']*'\([^']*\).*,\1,p ")" ]]; then | ||
|
||
# Volume up | ||
if [[ "$(cat /sys/class/gpio/gpio$VOLUME_UP_GPIO/value)" == 1 ]]; then | ||
printf "Setting volume higher. \n" | ||
amixer -D bluealsa sset "$DEVICE" 10%+ | ||
sleep 0.5 | ||
fi | ||
|
||
if [[ "$TIMER" == 1 ]]; then | ||
if [[ "$(dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.freedesktop.DBus.Properties.Get string:org.bluez.MediaPlayer1 string:Status | cut -d'"' -f 2)" == *"playing"* ]]; then | ||
printf "Stoping music playback. \n" | ||
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.bluez.MediaPlayer1.Pause | ||
else | ||
printf "Starting music playback. \n" | ||
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.bluez.MediaPlayer1.Play | ||
fi | ||
fi | ||
|
||
if [[ "$TIMER" == 2 ]]; then | ||
if [[ "$(dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.freedesktop.DBus.Properties.Get string:org.bluez.MediaPlayer1 string:Status | cut -d'"' -f 2)" == *"playing"* ]]; then | ||
printf "Stoping music playback. \n" | ||
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.bluez.MediaPlayer1.Pause | ||
else | ||
printf "Starting music playback. \n" | ||
dbus-send --system --dest=org.bluez --print-reply /org/bluez/hci0/dev_$MAC_PARSED/player0 org.bluez.MediaPlayer1.Play | ||
fi | ||
fi | ||
|
||
|
||
# Volume down | ||
if [[ "$(cat /sys/class/gpio/gpio$VOLUME_DOWN_GPIO/value)" == 1 ]]; then | ||
printf "Setting volume lower. \n" | ||
amixer -D bluealsa sset "$DEVICE" 10%- | ||
sleep 0.5 | ||
fi | ||
|
||
fi | ||
|
||
TIMER="0" | ||
|
||
done |
7 changes: 3 additions & 4 deletions
7
...audio/bluetooth-scripts/bluetooth-connect → ...tooth/bluetooth-scripts/bluetooth-connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
#!/usr/bin/python | ||
# This sript runs, when your pi connects to a bluetooth device and BLUETOOTH_CONNECT is set to anything. | ||
# This sript runs, when your pi connects to a bluetooth device and BLUETOOTH_SCRIPTS is set to true. | ||
# You can add your own code. BalenaSound has gpiozero installed so you can work with it. | ||
# Here is a example: | ||
|
||
# from gpiozero import LED | ||
# from time import sleep | ||
|
||
# led = LED(17) | ||
# led = LED(16) | ||
|
||
# led.off() | ||
# sleep(1) | ||
|
||
# sleep(1) |
6 changes: 3 additions & 3 deletions
6
...io/bluetooth-scripts/bluetooth-disconnect → ...th/bluetooth-scripts/bluetooth-disconnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
#!/usr/bin/python | ||
# This sript runs, when your pi disconnects from a bluetooth device and BLUETOOTH_DISCONNECT is set to anything. | ||
# This sript runs, when your pi disconnects from a bluetooth device and BLUETOOTH_SCRIPTS is set to true. | ||
# You can add your own code. BalenaSound has gpiozero installed so you can work with it. | ||
# Here is a example: | ||
|
||
# from gpiozero import LED | ||
# from time import sleep | ||
|
||
# led = LED(17) | ||
# led = LED(16) | ||
|
||
# led.off() | ||
# sleep(1) | ||
# sleep(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.