Skip to content

Commit 4731383

Browse files
authored
Merge pull request #5 from dtseiler/add_thresholds
Adding no-repeat thresholds for goals, powerplay and penalty music. Tested on hockeybox, everything working as expected.
2 parents 37e7265 + 1aca9fd commit 4731383

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

hockeybox.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
BTW_REPEAT_THRESHOLD = 25
3838
intermission_played_songs = deque([])
3939
INTERMISSION_REPEAT_THRESHOLD = 3
40+
goal_played_songs = deque([])
41+
GOAL_REPEAT_THRESHOLD = 4
42+
penalty_played_songs = deque([])
43+
PENALTY_REPEAT_THRESHOLD = 4
44+
powerplay_played_songs = deque([])
45+
POWERPLAY_REPEAT_THRESHOLD = 4
4046

4147
#
4248
# GPIO Setup
@@ -148,7 +154,20 @@ def play_song(p_song):
148154
def play_goal(channel):
149155
print "GOAL"
150156
change_lights_after_input(OUTPUT_GOAL)
151-
play_song(pick_random_song(GOAL_MP3_DIR))
157+
new_song = ""
158+
while True:
159+
new_song = pick_random_song(GOAL_MP3_DIR)
160+
if new_song in goal_played_songs:
161+
print "Song %s has already been played, skipping." % new_song
162+
else:
163+
goal_played_songs.append(new_song)
164+
break;
165+
166+
# Keep list at GOAL_REPEAT_THRESHOLD
167+
if len(goal_played_songs) > GOAL_REPEAT_THRESHOLD:
168+
print "Removing %s from goal_played_songs list" % goal_played_songs[0]
169+
goal_played_songs.popleft()
170+
play_song(new_song)
152171

153172
#
154173
# WARM-UP
@@ -180,15 +199,41 @@ def play_cdnanthem(channel):
180199
def play_penalty(channel):
181200
print "PENALTY"
182201
change_lights_after_input(OUTPUT_PENALTY)
183-
play_song(pick_random_song(PENALTY_MP3_DIR))
202+
new_song = ""
203+
while True:
204+
new_song = pick_random_song(PENALTY_MP3_DIR)
205+
if new_song in penalty_played_songs:
206+
print "Song %s has already been played, skipping." % new_song
207+
else:
208+
penalty_played_songs.append(new_song)
209+
break;
210+
211+
# Keep list at PENALTY_REPEAT_THRESHOLD
212+
if len(penalty_played_songs) > PENALTY_REPEAT_THRESHOLD:
213+
print "Removing %s from penalty_played_songs list" % penalty_played_songs[0]
214+
penalty_played_songs.popleft()
215+
play_song(new_song)
184216

185217
#
186218
# POWERPLAY
187219
#
188220
def play_powerplay(channel):
189221
print "POWERPLAY"
190222
change_lights_after_input(OUTPUT_POWERPLAY)
191-
play_song(pick_random_song(POWERPLAY_MP3_DIR))
223+
new_song = ""
224+
while True:
225+
new_song = pick_random_song(POWERPLAY_MP3_DIR)
226+
if new_song in powerplay_played_songs:
227+
print "Song %s has already been played, skipping." % new_song
228+
else:
229+
powerplay_played_songs.append(new_song)
230+
break;
231+
232+
# Keep list at POWERPLAY_REPEAT_THRESHOLD
233+
if len(powerplay_played_songs) > POWERPLAY_REPEAT_THRESHOLD:
234+
print "Removing %s from powerplay_played_songs list" % powerplay_played_songs[0]
235+
powerplay_played_songs.popleft()
236+
play_song(new_song)
192237

193238
#
194239
# INTERMISSION

0 commit comments

Comments
 (0)