Integrated user-indication via led
This commit is contained in:
parent
fdf61c5d3a
commit
9f194a9a03
@ -1,14 +1,40 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python
|
||||
|
||||
import glob
|
||||
import os
|
||||
import subprocess
|
||||
import ConfigParser
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
|
||||
yellowLed = 15
|
||||
redLed = 17
|
||||
greenLed = 18
|
||||
|
||||
mopidyConf = '/etc/mopidy/mopidy.conf'
|
||||
userDir = '/etc/mopidy/conf.user/'
|
||||
|
||||
def setLeds(yellow, red, green):
|
||||
GPIO.output(yellowLed, yellow)
|
||||
GPIO.output(redLed, red)
|
||||
GPIO.output(greenLed, green)
|
||||
|
||||
def getConfiguredLedColor():
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.read(mopidyConf)
|
||||
|
||||
return config.get('moped-switcher', 'led')
|
||||
|
||||
def setConfiguredLedColor():
|
||||
ledColor = getConfiguredLedColor()
|
||||
|
||||
if ledColor == 'yellow':
|
||||
setLeds(1, 0, 0)
|
||||
elif ledColor == 'red':
|
||||
setLeds(0, 1, 0)
|
||||
elif ledColor == 'green':
|
||||
setLeds(0, 0, 1)
|
||||
|
||||
def stopMopidy():
|
||||
command = ['service', 'mopidy', 'stop']
|
||||
subprocess.call(command, shell=False)
|
||||
@ -44,9 +70,11 @@ def switchConfig():
|
||||
def buttonHandler(channel):
|
||||
print 'Switching to ' + getNextConfig()
|
||||
try:
|
||||
setLeds(0, 0, 0)
|
||||
stopMopidy()
|
||||
switchConfig()
|
||||
startMopidy()
|
||||
setConfiguredLedColor()
|
||||
except OSError as e:
|
||||
print 'Error: ' + e.strerror
|
||||
|
||||
@ -55,6 +83,11 @@ if __name__ == '__main__':
|
||||
dummyPin = 15
|
||||
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
GPIO.setup(yellowLed, GPIO.OUT)
|
||||
GPIO.setup(redLed, GPIO.OUT)
|
||||
GPIO.setup(greenLed, GPIO.OUT)
|
||||
|
||||
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
GPIO.setup(dummyPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
|
||||
|
Reference in New Issue
Block a user