added sound triggers to live mode STABLE1

Tue, 13 Dec 2011 18:40:20 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Tue, 13 Dec 2011 18:40:20 +0100
changeset 78
d9126a55295c
parent 77
cede78304992
child 79
027e164b32f3

added sound triggers to live mode

slotUI/SlotCli.py file | annotate | diff | comparison | revisions
slotUI/sound/countdown.mp3 file | annotate | diff | comparison | revisions
slotUI/sound/info.txt file | annotate | diff | comparison | revisions
slotUI/sound/laprecord.mp3 file | annotate | diff | comparison | revisions
slotUI/sound/racestart.mp3 file | annotate | diff | comparison | revisions
slotUI/sound/select.mp3 file | annotate | diff | comparison | revisions
slotUI/sound/siren.mp3 file | annotate | diff | comparison | revisions
--- 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),
Binary file slotUI/sound/countdown.mp3 has changed
--- /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
Binary file slotUI/sound/laprecord.mp3 has changed
Binary file slotUI/sound/racestart.mp3 has changed
Binary file slotUI/sound/select.mp3 has changed
Binary file slotUI/sound/siren.mp3 has changed

mercurial