diff -r 11fabe1f7c40 -r efdf471642f5 slotUI/SlotCli.py --- a/slotUI/SlotCli.py Sun Oct 28 18:04:38 2012 +0100 +++ b/slotUI/SlotCli.py Sun Oct 28 18:43:50 2012 +0100 @@ -24,7 +24,7 @@ LOGLEVEL = 10 SOUNDPREFIX = "quake-" - +EVENTPREFIX = "event/" SOUNDS = { "countdown_start": os.path.abspath(SOUNDPREFIX + "sound/countdown.mp3"), "race_start": os.path.abspath(SOUNDPREFIX + "sound/racestart.mp3"), @@ -49,6 +49,10 @@ #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what]) #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid +def trigger_event(what): + trigger_sound(what) + Popen([os.path.abspath(EVENTPREFIX + what]) + class SlotCli(): def __init__(self, test = None, dev=""): self.box = Blackbox() @@ -401,13 +405,13 @@ 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") + trigger_event("lap_record") self.bestlap = t self.slot[slot]["status"] = "IN-RACE" if (self.slot[slot]["laps_last"] != l) and (l == self.laplimit): # we have lap limit reached! - trigger_sound("win") + trigger_event("win") self.raceactive = False self.slot[slot]["status"] = "WINNER!" self.box.query("+") # stop race @@ -426,12 +430,12 @@ if (self.slot[slot]["fuel_last"] == 16) and (f == 15): # 15 percent fuel, set speed limit for car to 8 # warning sound - trigger_sound("fuel_warning1") + trigger_event("fuel_warning1") cli.box.speedlimit(slot, 8) if (self.slot[slot]["fuel_last"] == 6) and (f == 5): # 5 percent, set speed limit for car to 6 # warning sound - trigger_sound("fuel_warning2") + trigger_event("fuel_warning2") cli.box.speedlimit(slot, 6) if (self.slot[slot]["fuel_last"] == 1) and (f == 0): # fuel empty @@ -440,7 +444,7 @@ if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): cli.box.speedlimit(slot, 15) if (self.slot[slot]["fuel_last"] < f) and (f == 100): - trigger_sound("fuel_full") + trigger_event("fuel_full") self.render_slots() if rx[:1] == "~": @@ -461,10 +465,10 @@ # pitlane sent something if (status == 5): self.slot[slot]["status"] = "PITLANE" - trigger_sound("pitlane_enter") + trigger_event("pitlane_enter") if (status == 7): self.slot[slot]["status"] = "IN-RACE" - trigger_sound("pitlane_exit") + trigger_event("pitlane_exit") self.render_slots() @@ -474,32 +478,32 @@ self.reset_slots() for slot in range(MAXSLOTS): self.slot[slot]["status"] = "Prepare" - trigger_sound("race_prepare") + trigger_event("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") + trigger_event("race_start") self.raceactive = True if rx == "!COUNTDOWN": # countdown initiated for slot in range(MAXSLOTS): self.slot[slot]["status"] = "~~~~~~~~~~" - trigger_sound("countdown_start") + trigger_event("countdown_start") if rx == "!PANIC": # panic mode - trigger_sound("panic") + trigger_event("panic") if rx == "!SHORTCUT": # panic mode - trigger_sound("panic_shortcut") + trigger_event("panic_shortcut") if rx == "!RESUME": # panic mode - trigger_sound("resume") + trigger_event("resume") if ((self.timelimit > 0) and (self.raceactive) and @@ -509,7 +513,7 @@ self.raceactive = False # we have time limit reached! self.box.query("+") # stop race - trigger_sound("win") + trigger_event("win") # get the one with position 1 for slot in self.slots: if slot["position"] == 1: @@ -526,7 +530,7 @@ self.scr.refresh() except Exception: - trigger_sound("data_error") + trigger_event("data_error") pass # terminate