Skip to content

Commit

Permalink
Removed program out of try block
Browse files Browse the repository at this point in the history
  • Loading branch information
speakerbug committed Nov 23, 2015
1 parent adc7d4d commit 6a6dfcf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
1 change: 1 addition & 0 deletions configs/song1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ TIME(MS),COMMAND,VALUE
001000 ,3 ,0
001000 ,4 ,0
001000 ,5 ,0
002000 ,END ,1
93 changes: 46 additions & 47 deletions xmasparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,51 @@
mp3 = str(sys.argv[2])
print 'config file =', config
print 'mp3 file =', mp3
except IndexError:
print 'Usage: python xmasparser.py <config file> <mp3 file>'

# Setup the board
GPIO.setmode(GPIO.BOARD)
for i in range(1,13):
GPIO.setup(pin_map[i], GPIO.OUT)
time.sleep(2.0)

pygame.mixer.init()
pygame.mixer.music.load(mp3)
pygame.mixer.music.play()

# Open the input sequnce file and read/parse it
with open(config,'r') as f:
seq_data = f.readlines()
for i in range(len(seq_data)):
seq_data[i] = seq_data[i].rstrip()

# Start show
start_time = int(round(time.time()*1000))
step = 1 #ignore the header line
while True :
next_step = seq_data[step].split(",");
next_step[1] = next_step[1].rstrip()
cur_time = int(round(time.time()*1000)) - start_time
# Setup the board
GPIO.setmode(GPIO.BOARD)
for i in range(1,12):
GPIO.setup(pin_map[i], GPIO.OUT)
time.sleep(2.0)

# time to run the command
if int(next_step[0]) <= cur_time:
print next_step
# if the command is Relay 1-12
if next_step[1] >= "1" and next_step[1] <= "12":
# change the pin state
if next_step[2] == "1":
GPIO.output(pin_map[int(next_step[1])],True)
else:
GPIO.output(pin_map[int(next_step[1])],False)

# This is used to check for END
if next_step[1].rstrip() == "END":
for i in range(1,13):
GPIO.output(pin_map[i],False)
#Reached end - End loop
break
#Increment what step we are on
step += 1

GPIO.cleanup()

except IndexError:
print 'Usage: python xmasparser.py <config file> <mp3 file>'
pygame.mixer.init()
pygame.mixer.music.load(mp3)
pygame.mixer.music.play()

# Open the input sequnce file and read/parse it
with open(config,'r') as f:
seq_data = f.readlines()
for i in range(len(seq_data)):
seq_data[i] = seq_data[i].rstrip()

# Start show
start_time = int(round(time.time()*1000))
step = 1 #ignore the header line
while True :
next_step = seq_data[step].split(",");
next_step[1] = next_step[1].rstrip()
cur_time = int(round(time.time()*1000)) - start_time

# time to run the command
if int(next_step[0]) <= cur_time:
print next_step
# if the command is Relay 1-12
if next_step[1] >= "1" and next_step[1] <= "12":
# change the pin state
if next_step[2] == "1":
GPIO.output(pin_map[int(next_step[1])],True)
else:
GPIO.output(pin_map[int(next_step[1])],False)

# This is used to check for END
if next_step[1].rstrip() == "END":
for i in range(1,12):
GPIO.output(pin_map[i],False)
#Reached end - End loop
break
#Increment what step we are on
step += 1

GPIO.cleanup()

0 comments on commit 6a6dfcf

Please sign in to comment.