Amplifier automatic on/off

Build/modify/repair equipment and improve systems performance by yourself

Re: Amplifier automatic on/off

Postby m0oml » 28 May 2016, 09:25

My Solution to this is a Bash script as a service

Code: Select all
nano /usr/bin/autoamp


Code: Select all
#!/bin/bash

# This Script is to read the Alsa Sound State and Automatcally
# swing a GPIO pin to allow auto switch on / off of an external
# amplifier, its crude dirty and badly written any sugestions
# or criticism welcome
#
# Trevor Cockayne trevoml@gmail.com



#   Exports pin to userspace
echo "26" > /sys/class/gpio/export

# Sets pin 26 as an output
echo "out" > /sys/class/gpio/gpio26/direction


count=0

time=120

let count=$time

for (( ; ; ))
        do
                if grep -q "closed" /proc/asound/card1/pcm0p/sub0/hw_params; then
#                       echo "DAC IDLE"
                        let "count++"
                else
#                       echo "DAC Playing"
                        count=0
        fi
                if [[ $count -gt $time || $count == $time ]]
                        then
#                               echo "Amp Off"
                                echo "0" > /sys/class/gpio/gpio26/value
                                count=$time
                        else
#                               echo "Amp ON"
                                echo "1" > /sys/class/gpio/gpio26/value
        fi
# echo $count
sleep 1
done


Code: Select all
chmod 755 /usr/bin/autoamp


Code: Select all
nano /etc/systemd/system/autoamp.service


Code: Select all
[Unit]
Discription=Automatic Amplifier Control

[Service]
ExecStart=/usr/bin/autoamp

[Install]
WantedBy=multi-user.target



Code: Select all
systemctl enable autoamp.service
systemctl start autoamp.service


Would very much welcome improvments and suggestions

Kind Regards
Trev
m0oml
 
Posts: 8
Joined: 28 May 2016, 09:16

Re: Amplifier automatic on/off

Postby jmar » 19 Jun 2016, 21:47

Thanks for this great idea! When i try it, I get the message " from mpd import MPDClient / ImportError: No module named mpd".
Could you please tell me, if I need to install an additional package (and how to).
jmar
 
Posts: 1
Joined: 19 Jun 2016, 21:39

support RuneAudio Donate with PayPal

Previous

Return to DIY and tweaks

Who is online

Users browsing this forum: No registered users and 1 guest