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),