Integrated user-indication via led
This commit is contained in:
parent
fdf61c5d3a
commit
9f194a9a03
1 changed files with 54 additions and 21 deletions
|
@ -1,14 +1,40 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import ConfigParser
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
|
||||||
|
yellowLed = 15
|
||||||
|
redLed = 17
|
||||||
|
greenLed = 18
|
||||||
|
|
||||||
mopidyConf = '/etc/mopidy/mopidy.conf'
|
mopidyConf = '/etc/mopidy/mopidy.conf'
|
||||||
userDir = '/etc/mopidy/conf.user/'
|
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():
|
def stopMopidy():
|
||||||
command = ['service', 'mopidy', 'stop']
|
command = ['service', 'mopidy', 'stop']
|
||||||
subprocess.call(command, shell=False)
|
subprocess.call(command, shell=False)
|
||||||
|
@ -44,9 +70,11 @@ def switchConfig():
|
||||||
def buttonHandler(channel):
|
def buttonHandler(channel):
|
||||||
print 'Switching to ' + getNextConfig()
|
print 'Switching to ' + getNextConfig()
|
||||||
try:
|
try:
|
||||||
|
setLeds(0, 0, 0)
|
||||||
stopMopidy()
|
stopMopidy()
|
||||||
switchConfig()
|
switchConfig()
|
||||||
startMopidy()
|
startMopidy()
|
||||||
|
setConfiguredLedColor()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print 'Error: ' + e.strerror
|
print 'Error: ' + e.strerror
|
||||||
|
|
||||||
|
@ -55,6 +83,11 @@ if __name__ == '__main__':
|
||||||
dummyPin = 15
|
dummyPin = 15
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
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(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
GPIO.setup(dummyPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
GPIO.setup(dummyPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue