After at lot of inspiration by other projects here and on other sites I made my own DIY player with Volumio and Raspberry Pi this fall.
I bought a aluminium box from Ebay and borrowed a tower-drill to drill the holes in the front. For the back I used the drill, an electrical jigsaw and a file. This was the first time I worked with metal.
The green button is power button and connected to a PSU. Red button is connected to GPIO-pins to be able to securely shutdown it without having to fire up the webbrowser or shell. The white button is used for firing up a script that will kill mpd and start snapcast client with multi-rrom audio together with other linux boxes in the home.
nledswitch.py
[code]#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import subprocess
snapcastState = 0
handle the button event
def buttonEventHandlerShutdown (pin):
print “handling button event shutdown”
GPIO.output(29,True)
subprocess.Popen([‘poweroff’])
while True:
time.sleep(0.3)
GPIO.output(29,False)
time.sleep(0.3)
GPIO.output(29,True)
def buttonEventHandlerSnapcast (pin):
global snapcastState
print “handling button event snapcast”
if snapcastState == 0:
snapcastState = 1
GPIO.output(33,True)
subprocess.call(["/etc/init.d/snapclient", “start”])
subprocess.call(["/etc/init.d/mpd", “stop”])
else:
snapcastState = 0
GPIO.output(33,False)
subprocess.call(["/etc/init.d/snapclient", “stop”])
subprocess.call(["/etc/init.d/mpd", “start”])
main function
def main():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(15, GPIO.IN)
GPIO.setup(16, GPIO.IN)
GPIO.setup(29, GPIO.OUT)
GPIO.setup(33, GPIO.OUT)
GPIO.output(29,False)
GPIO.output(33,False)
# tell the GPIO library to look out for an
# event on pin 23 and deal with it by calling
# the buttonEventHandler function
GPIO.add_event_detect(15, GPIO.FALLING, callback=buttonEventHandlerShutdown, bouncetime=200)
GPIO.add_event_detect(16, GPIO.FALLING, callback=buttonEventHandlerSnapcast, bouncetime=200)
# make the red LED flash
while True:
GPIO.output(29,True)
time.sleep(1)
GPIO.output(29,False)
time.sleep(1)
#GPIO.cleanup()
if name==“main”:
main()
[/code]
In /etc/rc.local this line start the scripts that will handle buttons and leds:
python /root/nledswitch.py & > /dev/null 2>&1