slotUI/slotCli.py

changeset 137
94d71156517b
parent 124
0b12a8bf23b2
child 139
7127e7082ee0
equal deleted inserted replaced
136:e7336e63acf6 137:94d71156517b
6 6
7 from freeslot import Blackbox, LOGLEVEL 7 from freeslot import Blackbox, LOGLEVEL
8 from optparse import OptionParser 8 from optparse import OptionParser
9 from operator import itemgetter 9 from operator import itemgetter
10 from subprocess import Popen, PIPE 10 from subprocess import Popen, PIPE
11 from logger import eventLogger
11 import sys, os 12 import sys, os
12 from copy import copy 13 from copy import copy
13 import curses 14 import curses
14 from time import sleep 15 from time import sleep, time
15 import ConfigParser 16 import ConfigParser
16 17
17 import SimpleXMLRPCServer 18 import SimpleXMLRPCServer
18 import xmlrpclib 19 import xmlrpclib
19 import threading 20 import threading
20 21
21 22
22 VERSION = "1.8" 23 VERSION = "1.8.1"
23 MAXSLOTS = 6 24 MAXSLOTS = 6
24 TERM = { 25 TERM = {
25 "caption": "\033[1;37m\033[1;44m", 26 "caption": "\033[1;37m\033[1;44m",
26 "text": "\033[1;30m", 27 "text": "\033[1;30m",
27 } 28 }
117 self.test = test 118 self.test = test
118 self.laplimit = 999 # race laplimit 119 self.laplimit = 999 # race laplimit
119 self.timelimit = 0 # race timelimit 120 self.timelimit = 0 # race timelimit
120 self.firstpos = -1 # first position slot 121 self.firstpos = -1 # first position slot
121 self.freerun = True # freerun mode = sort order by best lap 122 self.freerun = True # freerun mode = sort order by best lap
123 self.raceName = "Freestyle"
124 self.log = eventLogger("events.log")
122 125
123 def reset_slots(self): 126 def reset_slots(self):
124 idx = 0 127 idx = 0
125 for slt in self.slot: 128 for slt in self.slot:
126 slt["laps"] = 0 129 slt["laps"] = 0
249 self.slot[slot]["profilename"] = "default" 252 self.slot[slot]["profilename"] = "default"
250 self.slot[slot]["profile"].read("profiles/default") 253 self.slot[slot]["profile"].read("profiles/default")
251 self.slot[slot]["limit"] = self.slot[slot]["profile"].getint("Settings", "Limit") 254 self.slot[slot]["limit"] = self.slot[slot]["profile"].getint("Settings", "Limit")
252 self.slot[slot]["name"] = name 255 self.slot[slot]["name"] = name
253 self.flash_car_settings(slot) 256 self.flash_car_settings(slot)
257 self.cleartop()
258 self.scr.refresh()
259 curses.noecho()
260 self.scr.nodelay(1) # disable delay on readkey
261
262 def readRaceName(self):
263 self.scr.nodelay(0) # enable delay on readkey
264 curses.echo()
265 self.scr.addstr(0,0, "Enter Race Name [%s]:" % (
266 self.raceName),
267 curses.color_pair(1))
268 self.scr.refresh()
269 name = self.scr.getstr(1,0, 15)
270 if name != "":
271 self.raceName = name
254 self.cleartop() 272 self.cleartop()
255 self.scr.refresh() 273 self.scr.refresh()
256 curses.noecho() 274 curses.noecho()
257 self.scr.nodelay(1) # disable delay on readkey 275 self.scr.nodelay(1) # disable delay on readkey
258 276
450 #elif key == ord('w'): self.readLimit(1) 468 #elif key == ord('w'): self.readLimit(1)
451 #elif key == ord('e'): self.readLimit(2) 469 #elif key == ord('e'): self.readLimit(2)
452 #elif key == ord('r'): self.readLimit(3) 470 #elif key == ord('r'): self.readLimit(3)
453 #elif key == ord('t'): self.readLimit(4) 471 #elif key == ord('t'): self.readLimit(4)
454 #elif key == ord('z'): self.readLimit(5) 472 #elif key == ord('z'): self.readLimit(5)
473 elif key == ord('n'): self.readRaceName()
455 elif key == ord('a'): 474 elif key == ord('a'):
456 if self.slot[4]["drive"] > 0: self.slot[4]["drive"] -= 1 475 if self.slot[4]["drive"] > 0: self.slot[4]["drive"] -= 1
457 cli.box.speedminimum(4, self.slot[4]["drive"]) 476 cli.box.speedminimum(4, self.slot[4]["drive"])
458 elif key == ord('s'): 477 elif key == ord('s'):
459 if self.slot[4]["drive"] < 16: self.slot[4]["drive"] += 1 478 if self.slot[4]["drive"] < 16: self.slot[4]["drive"] += 1
512 # we have lap limit reached! 531 # we have lap limit reached!
513 trigger_event("win", slot + 1) 532 trigger_event("win", slot + 1)
514 self.raceactive = False 533 self.raceactive = False
515 self.slot[slot]["status"] = "WINNER!" 534 self.slot[slot]["status"] = "WINNER!"
516 self.box.query("+") # stop race 535 self.box.query("+") # stop race
536
537 tmpname = "n/a"
538 if not self.freerun:
539 tmpname = self.raceName
540 self.log.push([
541 time(),
542 self.sysclk,
543 tmpname,
544 slot,
545 self.slot[slot]["name"],
546 l,
547 t,
548 self.slot[slot]["best"],
549 self.laplimit,
550 self.timelimit
551 ])
552
517 553
518 self.render_slots() 554 self.render_slots()
519 555
520 if rx[:2] == "F:": 556 if rx[:2] == "F:":
521 # update fuel level 557 # update fuel level

mercurial