Refactoring
This commit is contained in:
parent
e06980859b
commit
fdf61c5d3a
1 changed files with 18 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
@ -7,27 +7,34 @@ yellowLed = 15
|
||||||
redLed = 17
|
redLed = 17
|
||||||
greenLed = 18
|
greenLed = 18
|
||||||
|
|
||||||
|
mopidyConf = '/etc/mopidy/mopidy.conf'
|
||||||
|
|
||||||
def setLeds(yellow, red, green):
|
def setLeds(yellow, red, green):
|
||||||
GPIO.output(yellowLed, yellow)
|
GPIO.output(yellowLed, yellow)
|
||||||
GPIO.output(redLed, red)
|
GPIO.output(redLed, red)
|
||||||
GPIO.output(greenLed, green)
|
GPIO.output(greenLed, green)
|
||||||
|
|
||||||
|
def getConfiguredLedColor():
|
||||||
config = ConfigParser.ConfigParser()
|
config = ConfigParser.ConfigParser()
|
||||||
config.read('/etc/mopidy/mopidy.conf')
|
config.read(mopidyConf)
|
||||||
|
|
||||||
ledColor = config.get('moped-switcher', 'led')
|
return config.get('moped-switcher', 'led')
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
def setConfiguredLedColor():
|
||||||
GPIO.setup(yellowLed, GPIO.OUT)
|
ledColor = getConfiguredLedColor()
|
||||||
GPIO.setup(redLed, GPIO.OUT)
|
|
||||||
GPIO.setup(greenLed, GPIO.OUT)
|
|
||||||
|
|
||||||
if ledColor == 'yellow':
|
if ledColor == 'yellow':
|
||||||
print 'yellow'
|
|
||||||
setLeds(1, 0, 0)
|
setLeds(1, 0, 0)
|
||||||
elif ledColor == 'red':
|
elif ledColor == 'red':
|
||||||
setLeds(0, 1, 0)
|
setLeds(0, 1, 0)
|
||||||
elif ledColor == 'green':
|
elif ledColor == 'green':
|
||||||
setLeds(0, 0, 1)
|
setLeds(0, 0, 1)
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
|
GPIO.setup(yellowLed, GPIO.OUT)
|
||||||
|
GPIO.setup(redLed, GPIO.OUT)
|
||||||
|
GPIO.setup(greenLed, GPIO.OUT)
|
||||||
|
|
||||||
|
setConfiguredLedColor()
|
||||||
|
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
Loading…
Reference in a new issue