slotUI/SlotCli.py

changeset 112
fee43a74bed6
parent 111
7e9a451870ed
child 113
b2d91fd5d926
equal deleted inserted replaced
111:7e9a451870ed 112:fee43a74bed6
52 if what in SOUNDS: 52 if what in SOUNDS:
53 Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) 53 Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]])
54 #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what]) 54 #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what])
55 #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid 55 #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid
56 56
57 def trigger_event(what): 57 def trigger_event(what, slot = 0):
58 trigger_sound(what) 58 trigger_sound(what)
59 Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what)]) 59 Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what), str(slot)])
60 60
61 class SlotServer(threading.Thread): 61 class SlotServer(threading.Thread):
62 def __init__(self, blackbox): 62 def __init__(self, blackbox):
63 threading.Thread.__init__(self) 63 threading.Thread.__init__(self)
64 self.server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000)) 64 self.server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000))
425 self.slot[slot]["last"] = t 425 self.slot[slot]["last"] = t
426 self.slot[slot]["clk"] = self.sysclk 426 self.slot[slot]["clk"] = self.sysclk
427 if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): 427 if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0):
428 self.slot[slot]["best"] = t 428 self.slot[slot]["best"] = t
429 if self.bestlap > t: 429 if self.bestlap > t:
430 trigger_event("lap_record") 430 trigger_event("lap_record", slot + 1)
431 self.bestlap = t 431 self.bestlap = t
432 432
433 self.slot[slot]["status"] = "IN-RACE" 433 self.slot[slot]["status"] = "IN-RACE"
434 if (self.slot[slot]["laps_last"] != l) and (l == self.laplimit): 434 if (self.slot[slot]["laps_last"] != l) and (l == self.laplimit):
435 # we have lap limit reached! 435 # we have lap limit reached!
436 trigger_event("win") 436 trigger_event("win", slot + 1)
437 self.raceactive = False 437 self.raceactive = False
438 self.slot[slot]["status"] = "WINNER!" 438 self.slot[slot]["status"] = "WINNER!"
439 self.box.query("+") # stop race 439 self.box.query("+") # stop race
440 440
441 self.render_slots() 441 self.render_slots()
450 self.slot[slot]["fuel"] = f 450 self.slot[slot]["fuel"] = f
451 if self.slot[slot]["fuel_last"] != f: 451 if self.slot[slot]["fuel_last"] != f:
452 if (self.slot[slot]["fuel_last"] == 16) and (f == 15): 452 if (self.slot[slot]["fuel_last"] == 16) and (f == 15):
453 # 15 percent fuel, set speed limit for car to 8 453 # 15 percent fuel, set speed limit for car to 8
454 # warning sound 454 # warning sound
455 trigger_event("fuel_warning1") 455 trigger_event("fuel_warning1", slot + 1)
456 cli.box.speedlimit(slot, 8) 456 cli.box.speedlimit(slot, 8)
457 if (self.slot[slot]["fuel_last"] == 6) and (f == 5): 457 if (self.slot[slot]["fuel_last"] == 6) and (f == 5):
458 # 5 percent, set speed limit for car to 6 458 # 5 percent, set speed limit for car to 6
459 # warning sound 459 # warning sound
460 trigger_event("fuel_warning2") 460 trigger_event("fuel_warning2", slot + 1)
461 cli.box.speedlimit(slot, 6) 461 cli.box.speedlimit(slot, 6)
462 if (self.slot[slot]["fuel_last"] == 1) and (f == 0): 462 if (self.slot[slot]["fuel_last"] == 1) and (f == 0):
463 # fuel empty 463 # fuel empty
464 # set speedlimit to 4 464 # set speedlimit to 4
465 cli.box.speedlimit(slot, 4) 465 cli.box.speedlimit(slot, 4)
466 if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): 466 if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20):
467 cli.box.speedlimit(slot, 15) 467 cli.box.speedlimit(slot, 15)
468 if (self.slot[slot]["fuel_last"] < f) and (f == 100): 468 if (self.slot[slot]["fuel_last"] < f) and (f == 100):
469 trigger_event("fuel_full") 469 trigger_event("fuel_full", slot + 1)
470 self.render_slots() 470 self.render_slots()
471 471
472 if rx[:1] == "~": 472 if rx[:1] == "~":
473 # jumpstart occured 473 # jumpstart occured
474 slot = int(rx[1:2]) 474 slot = int(rx[1:2])
485 self.sysclk = int(data[5], 16) 485 self.sysclk = int(data[5], 16)
486 if (devtype == 4): 486 if (devtype == 4):
487 # pitlane sent something 487 # pitlane sent something
488 if (status == 5): 488 if (status == 5):
489 self.slot[slot]["status"] = "PITLANE" 489 self.slot[slot]["status"] = "PITLANE"
490 trigger_event("pitlane_enter") 490 trigger_event("pitlane_enter", slot + 1)
491 if (status == 7): 491 if (status == 7):
492 self.slot[slot]["status"] = "IN-RACE" 492 self.slot[slot]["status"] = "IN-RACE"
493 trigger_event("pitlane_exit") 493 trigger_event("pitlane_exit", slot + 1)
494 494
495 self.render_slots() 495 self.render_slots()
496 496
497 if rx == "!RACE PREPARE": 497 if rx == "!RACE PREPARE":
498 # reset current race status 498 # reset current race status

mercurial