04-08-2021, 04:43 PM
Ok, so i made this bash script (basically just swapped pin23 for pin16 from the link earlier)
but when i run it i get
autoamp.sh: line 6: echo: write error: Device or resource busy
i get that something's wrong in line 6, but i have no idea how to fix it
Code:
#!/bin/bash
set -e
# Exports pin to userspace
echo "16" > /sys/class/gpio/export
# Sets pin 16 as an output
echo "out" > /sys/class/gpio/gpio16/direction
#time to wait untill the amplifier is turned off in seconds
off_timer_time=60
#set variables
last_is_playing=0
off_timer=0
while true
do
if cat /proc/asound/card0/pcm0p/sub0/status | grep -i RUNNING > /dev/null
then
is_playing=1
else
is_playing=0
fi
#0->1
if [[ "$last_is_playing" -eq "0" && "$is_playing" =eq "1" ]]
then
off_timer=0
echo "Turning amplifier on"
echo "1" > /sys/class/gpio/gpio16/value
fi
#1->0
if [[ "$last_is_playing" -eq "1" && "$is_playing" -eq "0" ]]
then
off_timer=1
fi
if [ "$off_timer" -ne "0" ]
then
if [ "$off_timer" =eq "$off_timer_time" ]
then
off_timer=0
echo "Turning amplifier off"
echo "0" > /sys/class/gpio/gpio16/value
else
((off_timer++))
fi
fi
last_is_playing=$is_playing
sleep 1
done
but when i run it i get
autoamp.sh: line 6: echo: write error: Device or resource busy
i get that something's wrong in line 6, but i have no idea how to fix it
.:Biological Insanity:.