# HG changeset patch # User Malte Bayer # Date 1323798020 -3600 # Node ID d9126a55295cf2a1938372278931975e33a80759 # Parent cede783049923b5d23f33857692ec488a1f140c1 added sound triggers to live mode diff -r cede78304992 -r d9126a55295c slotUI/SlotCli.py --- a/slotUI/SlotCli.py Sun Dec 11 17:34:40 2011 +0100 +++ b/slotUI/SlotCli.py Tue Dec 13 18:40:20 2011 +0100 @@ -7,7 +7,8 @@ from freeslot import Blackbox, LOGLEVEL from optparse import OptionParser from operator import itemgetter -import sys +from subprocess import Popen, PIPE +import sys, os from copy import copy import curses @@ -21,6 +22,19 @@ # disable debug log output LOGLEVEL = 10 +SOUNDS = { + "countdown_start": os.path.abspath("sound/countdown.mp3"), + "race_start": os.path.abspath("sound/racestart.mp3"), + "race_prepare": os.path.abspath("sound/siren.mp3"), + "lap_record": os.path.abspath("sound/laprecord.mp3"), + } + +def trigger_sound(what): + if what in SOUNDS: + Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) + #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what]) + #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid + class SlotCli(): def __init__(self): self.box = Blackbox() @@ -45,6 +59,7 @@ ] self.reset_slots() self.sysclk = 0.00 + self.bestlap = 9999999.00 def reset_slots(self): idx = 0 @@ -58,6 +73,7 @@ slt["status"] = self.slot_dummy["status"] slt["clk"] = 0 idx += 1 + self.bestlap = 0.00 def update_positions(self): order1 = sorted(self.slot, key=itemgetter( @@ -178,6 +194,10 @@ self.slot[slot]["last"] = t self.slot[slot]["clk"] = self.sysclk if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): self.slot[slot]["best"] = t + if self.bestlap > t: + trigger_sound("lap_record") + self.bestlap = t + self.slot[slot]["status"] = "IN-RACE" self.render_slots() @@ -214,18 +234,22 @@ if rx == "!RACE PREPARE": # reset current race status # and display PREPARE PHASE + self.reset_slots() for slot in range(MAXSLOTS): self.slot[slot]["status"] = "Prepare" + trigger_sound("race_prepare") if rx == "!RACE START": for slot in range(MAXSLOTS): if self.slot[slot]["status"] == "~~~~~~~~~~": self.slot[slot]["status"] = "Idle" + trigger_sound("race_start") if rx == "!COUNTDOWN": # countdown initiated for slot in range(MAXSLOTS): self.slot[slot]["status"] = "~~~~~~~~~~" + trigger_sound("countdown_start") self.scr.addstr(10,31, "Race Timer: %7.3f min" % (self.sysclk / 60), diff -r cede78304992 -r d9126a55295c slotUI/sound/countdown.mp3 Binary file slotUI/sound/countdown.mp3 has changed diff -r cede78304992 -r d9126a55295c slotUI/sound/info.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/slotUI/sound/info.txt Tue Dec 13 18:40:20 2011 +0100 @@ -0,0 +1,4 @@ +The sounds are just examples, you can exchange them with whatever you want + +The sound files are public domain, downloaded from: +http://www.mediacollege.com/downloads/permission/public-domain.html \ No newline at end of file diff -r cede78304992 -r d9126a55295c slotUI/sound/laprecord.mp3 Binary file slotUI/sound/laprecord.mp3 has changed diff -r cede78304992 -r d9126a55295c slotUI/sound/racestart.mp3 Binary file slotUI/sound/racestart.mp3 has changed diff -r cede78304992 -r d9126a55295c slotUI/sound/select.mp3 Binary file slotUI/sound/select.mp3 has changed diff -r cede78304992 -r d9126a55295c slotUI/sound/siren.mp3 Binary file slotUI/sound/siren.mp3 has changed