10 from subprocess import Popen, PIPE |
10 from subprocess import Popen, PIPE |
11 import sys, os |
11 import sys, os |
12 from copy import copy |
12 from copy import copy |
13 import curses |
13 import curses |
14 |
14 |
15 VERSION = "1.3" |
15 VERSION = "1.4" |
16 MAXSLOTS = 6 |
16 MAXSLOTS = 6 |
17 TERM = { |
17 TERM = { |
18 "caption": "\033[1;37m\033[1;44m", |
18 "caption": "\033[1;37m\033[1;44m", |
19 "text": "\033[1;30m", |
19 "text": "\033[1;30m", |
20 } |
20 } |
21 |
21 |
22 # disable debug log output |
22 # disable debug log output |
23 LOGLEVEL = 10 |
23 LOGLEVEL = 10 |
24 |
24 |
|
25 SOUNDPREFIX = "quake-" |
|
26 |
25 SOUNDS = { |
27 SOUNDS = { |
26 "countdown_start": os.path.abspath("sound/countdown.mp3"), |
28 "countdown_start": os.path.abspath(SOUNDPREFIX + "sound/countdown.mp3"), |
27 "race_start": os.path.abspath("sound/racestart.mp3"), |
29 "race_start": os.path.abspath(SOUNDPREFIX + "sound/racestart.mp3"), |
28 "race_prepare": os.path.abspath("sound/siren.mp3"), |
30 "race_prepare": os.path.abspath(SOUNDPREFIX + "sound/siren.mp3"), |
29 "lap_record": os.path.abspath("sound/laprecord.mp3"), |
31 "lap_record": os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"), |
|
32 "fuel_warning1": os.path.abspath(SOUNDPREFIX + "sound/fuel1.mp3"), |
|
33 "fuel_warning2": os.path.abspath(SOUNDPREFIX + "sound/fuel2.mp3"), |
|
34 "fuel_full": os.path.abspath(SOUNDPREFIX + "sound/fuel_full.mp3"), |
|
35 "pitlane_enter": os.path.abspath(SOUNDPREFIX + "sound/pitlane_enter.mp3"), |
|
36 "pitlane_exit": os.path.abspath(SOUNDPREFIX + "sound/pitlane_exit.mp3"), |
30 } |
37 } |
31 |
38 |
32 def trigger_sound(what): |
39 def trigger_sound(what): |
33 if what in SOUNDS: |
40 if what in SOUNDS: |
34 Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) |
41 Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) |
205 # update fuel level |
214 # update fuel level |
206 slot = int(data[1]) |
215 slot = int(data[1]) |
207 f = int(data[2], 16) |
216 f = int(data[2], 16) |
208 f = f / 100 # fuel in percent |
217 f = f / 100 # fuel in percent |
209 self.sysclk = int(data[3], 16) / 2000.00 |
218 self.sysclk = int(data[3], 16) / 2000.00 |
|
219 self.slot[slot]["fuel_last"] = self.slot[slot]["fuel"] |
210 self.slot[slot]["fuel"] = f |
220 self.slot[slot]["fuel"] = f |
|
221 if self.slot[slot]["fuel_last"] != f: |
|
222 # 10 percent fuel, set speed limit for car to 8 |
|
223 if (self.slot[slot]["fuel_last"] == 11) and (f == 10): |
|
224 # warning sound |
|
225 trigger_sound("fuel_warning1") |
|
226 cli.box.speedlimit(slot, 8) |
|
227 # 5 percent, set speed limit for car to 4 |
|
228 if (self.slot[slot]["fuel_last"] == 6) and (f == 5): |
|
229 # warning sound |
|
230 trigger_sound("fuel_warning2") |
|
231 cli.box.speedlimit(slot, 4) |
|
232 if (self.slot[slot]["fuel_last"] == 1) and (f == 0): |
|
233 # set speedlimit to 2 |
|
234 cli.box.speedlimit(slot, 2) |
|
235 if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): |
|
236 cli.box.speedlimit(slot, 15) |
|
237 if (self.slot[slot]["fuel_last"] < f) and (f == 100): |
|
238 trigger_sound("fuel_full") |
211 self.render_slots() |
239 self.render_slots() |
212 |
240 |
213 if rx[:1] == "~": |
241 if rx[:1] == "~": |
214 # jumpstart occured |
242 # jumpstart occured |
215 slot = int(rx[1:2]) |
243 slot = int(rx[1:2]) |
224 sender = int(data[3], 16) |
252 sender = int(data[3], 16) |
225 status = int(data[4], 16) |
253 status = int(data[4], 16) |
226 self.sysclk = int(data[5], 16) |
254 self.sysclk = int(data[5], 16) |
227 if (devtype == 4): |
255 if (devtype == 4): |
228 # pitlane sent something |
256 # pitlane sent something |
229 if (status == 5): self.slot[slot]["status"] = "PITLANE" |
257 if (status == 5): |
230 if (status == 6): self.slot[slot]["status"] = "IN-RACE" |
258 self.slot[slot]["status"] = "PITLANE" |
|
259 trigger_sound("pitlane_enter") |
|
260 if (status == 6): |
|
261 self.slot[slot]["status"] = "IN-RACE" |
|
262 trigger_sound("pitlane_exit") |
231 |
263 |
232 self.render_slots() |
264 self.render_slots() |
233 |
265 |
234 if rx == "!RACE PREPARE": |
266 if rx == "!RACE PREPARE": |
235 # reset current race status |
267 # reset current race status |