22 |
22 |
23 # disable debug log output |
23 # disable debug log output |
24 LOGLEVEL = 10 |
24 LOGLEVEL = 10 |
25 |
25 |
26 SOUNDPREFIX = "quake-" |
26 SOUNDPREFIX = "quake-" |
27 |
27 EVENTPREFIX = "event/" |
28 SOUNDS = { |
28 SOUNDS = { |
29 "countdown_start": os.path.abspath(SOUNDPREFIX + "sound/countdown.mp3"), |
29 "countdown_start": os.path.abspath(SOUNDPREFIX + "sound/countdown.mp3"), |
30 "race_start": os.path.abspath(SOUNDPREFIX + "sound/racestart.mp3"), |
30 "race_start": os.path.abspath(SOUNDPREFIX + "sound/racestart.mp3"), |
31 "race_prepare": os.path.abspath(SOUNDPREFIX + "sound/prepare.mp3"), |
31 "race_prepare": os.path.abspath(SOUNDPREFIX + "sound/prepare.mp3"), |
32 "lap_record": os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"), |
32 "lap_record": os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"), |
46 def trigger_sound(what): |
46 def trigger_sound(what): |
47 if what in SOUNDS: |
47 if what in SOUNDS: |
48 Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) |
48 Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) |
49 #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what]) |
49 #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what]) |
50 #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid |
50 #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid |
|
51 |
|
52 def trigger_event(what): |
|
53 trigger_sound(what) |
|
54 Popen([os.path.abspath(EVENTPREFIX + what]) |
51 |
55 |
52 class SlotCli(): |
56 class SlotCli(): |
53 def __init__(self, test = None, dev=""): |
57 def __init__(self, test = None, dev=""): |
54 self.box = Blackbox() |
58 self.box = Blackbox() |
55 if not test: |
59 if not test: |
399 self.slot[slot]["last"] = t |
403 self.slot[slot]["last"] = t |
400 self.slot[slot]["clk"] = self.sysclk |
404 self.slot[slot]["clk"] = self.sysclk |
401 if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): |
405 if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): |
402 self.slot[slot]["best"] = t |
406 self.slot[slot]["best"] = t |
403 if self.bestlap > t: |
407 if self.bestlap > t: |
404 trigger_sound("lap_record") |
408 trigger_event("lap_record") |
405 self.bestlap = t |
409 self.bestlap = t |
406 |
410 |
407 self.slot[slot]["status"] = "IN-RACE" |
411 self.slot[slot]["status"] = "IN-RACE" |
408 if (self.slot[slot]["laps_last"] != l) and (l == self.laplimit): |
412 if (self.slot[slot]["laps_last"] != l) and (l == self.laplimit): |
409 # we have lap limit reached! |
413 # we have lap limit reached! |
410 trigger_sound("win") |
414 trigger_event("win") |
411 self.raceactive = False |
415 self.raceactive = False |
412 self.slot[slot]["status"] = "WINNER!" |
416 self.slot[slot]["status"] = "WINNER!" |
413 self.box.query("+") # stop race |
417 self.box.query("+") # stop race |
414 |
418 |
415 self.render_slots() |
419 self.render_slots() |
424 self.slot[slot]["fuel"] = f |
428 self.slot[slot]["fuel"] = f |
425 if self.slot[slot]["fuel_last"] != f: |
429 if self.slot[slot]["fuel_last"] != f: |
426 if (self.slot[slot]["fuel_last"] == 16) and (f == 15): |
430 if (self.slot[slot]["fuel_last"] == 16) and (f == 15): |
427 # 15 percent fuel, set speed limit for car to 8 |
431 # 15 percent fuel, set speed limit for car to 8 |
428 # warning sound |
432 # warning sound |
429 trigger_sound("fuel_warning1") |
433 trigger_event("fuel_warning1") |
430 cli.box.speedlimit(slot, 8) |
434 cli.box.speedlimit(slot, 8) |
431 if (self.slot[slot]["fuel_last"] == 6) and (f == 5): |
435 if (self.slot[slot]["fuel_last"] == 6) and (f == 5): |
432 # 5 percent, set speed limit for car to 6 |
436 # 5 percent, set speed limit for car to 6 |
433 # warning sound |
437 # warning sound |
434 trigger_sound("fuel_warning2") |
438 trigger_event("fuel_warning2") |
435 cli.box.speedlimit(slot, 6) |
439 cli.box.speedlimit(slot, 6) |
436 if (self.slot[slot]["fuel_last"] == 1) and (f == 0): |
440 if (self.slot[slot]["fuel_last"] == 1) and (f == 0): |
437 # fuel empty |
441 # fuel empty |
438 # set speedlimit to 4 |
442 # set speedlimit to 4 |
439 cli.box.speedlimit(slot, 4) |
443 cli.box.speedlimit(slot, 4) |
440 if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): |
444 if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): |
441 cli.box.speedlimit(slot, 15) |
445 cli.box.speedlimit(slot, 15) |
442 if (self.slot[slot]["fuel_last"] < f) and (f == 100): |
446 if (self.slot[slot]["fuel_last"] < f) and (f == 100): |
443 trigger_sound("fuel_full") |
447 trigger_event("fuel_full") |
444 self.render_slots() |
448 self.render_slots() |
445 |
449 |
446 if rx[:1] == "~": |
450 if rx[:1] == "~": |
447 # jumpstart occured |
451 # jumpstart occured |
448 slot = int(rx[1:2]) |
452 slot = int(rx[1:2]) |
459 self.sysclk = int(data[5], 16) |
463 self.sysclk = int(data[5], 16) |
460 if (devtype == 4): |
464 if (devtype == 4): |
461 # pitlane sent something |
465 # pitlane sent something |
462 if (status == 5): |
466 if (status == 5): |
463 self.slot[slot]["status"] = "PITLANE" |
467 self.slot[slot]["status"] = "PITLANE" |
464 trigger_sound("pitlane_enter") |
468 trigger_event("pitlane_enter") |
465 if (status == 7): |
469 if (status == 7): |
466 self.slot[slot]["status"] = "IN-RACE" |
470 self.slot[slot]["status"] = "IN-RACE" |
467 trigger_sound("pitlane_exit") |
471 trigger_event("pitlane_exit") |
468 |
472 |
469 self.render_slots() |
473 self.render_slots() |
470 |
474 |
471 if rx == "!RACE PREPARE": |
475 if rx == "!RACE PREPARE": |
472 # reset current race status |
476 # reset current race status |
473 # and display PREPARE PHASE |
477 # and display PREPARE PHASE |
474 self.reset_slots() |
478 self.reset_slots() |
475 for slot in range(MAXSLOTS): |
479 for slot in range(MAXSLOTS): |
476 self.slot[slot]["status"] = "Prepare" |
480 self.slot[slot]["status"] = "Prepare" |
477 trigger_sound("race_prepare") |
481 trigger_event("race_prepare") |
478 |
482 |
479 if rx == "!RACE START": |
483 if rx == "!RACE START": |
480 for slot in range(MAXSLOTS): |
484 for slot in range(MAXSLOTS): |
481 if self.slot[slot]["status"] == "~~~~~~~~~~": |
485 if self.slot[slot]["status"] == "~~~~~~~~~~": |
482 self.slot[slot]["status"] = "Idle" |
486 self.slot[slot]["status"] = "Idle" |
483 trigger_sound("race_start") |
487 trigger_event("race_start") |
484 self.raceactive = True |
488 self.raceactive = True |
485 |
489 |
486 if rx == "!COUNTDOWN": |
490 if rx == "!COUNTDOWN": |
487 # countdown initiated |
491 # countdown initiated |
488 for slot in range(MAXSLOTS): |
492 for slot in range(MAXSLOTS): |
489 self.slot[slot]["status"] = "~~~~~~~~~~" |
493 self.slot[slot]["status"] = "~~~~~~~~~~" |
490 trigger_sound("countdown_start") |
494 trigger_event("countdown_start") |
491 |
495 |
492 if rx == "!PANIC": |
496 if rx == "!PANIC": |
493 # panic mode |
497 # panic mode |
494 trigger_sound("panic") |
498 trigger_event("panic") |
495 |
499 |
496 if rx == "!SHORTCUT": |
500 if rx == "!SHORTCUT": |
497 # panic mode |
501 # panic mode |
498 trigger_sound("panic_shortcut") |
502 trigger_event("panic_shortcut") |
499 |
503 |
500 if rx == "!RESUME": |
504 if rx == "!RESUME": |
501 # panic mode |
505 # panic mode |
502 trigger_sound("resume") |
506 trigger_event("resume") |
503 |
507 |
504 |
508 |
505 if ((self.timelimit > 0) and (self.raceactive) and |
509 if ((self.timelimit > 0) and (self.raceactive) and |
506 (self.sysclk_last != self.sysclk) and |
510 (self.sysclk_last != self.sysclk) and |
507 ((self.sysclk / 60) >= self.timelimit)): |
511 ((self.sysclk / 60) >= self.timelimit)): |
508 self.sysclk_last = self.sysclk |
512 self.sysclk_last = self.sysclk |
509 self.raceactive = False |
513 self.raceactive = False |
510 # we have time limit reached! |
514 # we have time limit reached! |
511 self.box.query("+") # stop race |
515 self.box.query("+") # stop race |
512 trigger_sound("win") |
516 trigger_event("win") |
513 # get the one with position 1 |
517 # get the one with position 1 |
514 for slot in self.slots: |
518 for slot in self.slots: |
515 if slot["position"] == 1: |
519 if slot["position"] == 1: |
516 slot["status"] = "WINNER!" |
520 slot["status"] = "WINNER!" |
517 self.render_slots() |
521 self.render_slots() |