# HG changeset patch # User Malte Bayer # Date 1323429682 -3600 # Node ID 9293f3efcc06e06c6d67234393a782f45ac2a078 # Parent 68eca8057d68f93ed87058443cb8f8d4a8ca3e47 added live display to CLI (lap counter, last and best time) diff -r 68eca8057d68 -r 9293f3efcc06 slotUI/SlotCli.py --- a/slotUI/SlotCli.py Fri Dec 09 11:54:19 2011 +0100 +++ b/slotUI/SlotCli.py Fri Dec 09 12:21:22 2011 +0100 @@ -24,10 +24,11 @@ self.slot_dummy = { "name": "Unnamed", "laps": 0, - "last": 0, - "best": 0, + "last": 0.00, + "best": 0.00, "fuel": 0, "position": 0, + "drive": 0, } self.slot = [ @@ -72,6 +73,7 @@ if name != "": self.slot[slot]["name"] = name self.cleartop() + self.scr.refresh() curses.noecho() def monitor(self): @@ -88,6 +90,10 @@ self.scr.keypad(1) # enable special keys self.scr.nodelay(1) # disable delay on readkey + self.render_slots() + self.scr.refresh() + + while 1: key = self.scr.getch() if key == ord('q'): break @@ -98,18 +104,44 @@ elif key == ord('4'): self.readName(3) elif key == ord('5'): self.readName(4) elif key == ord('6'): self.readName(5) + elif key == ord('a'): + if self.slot[4]["drive"] > 0: self.slot[4]["drive"] -= 1 + cli.box.speedminimum(4, self.slot[4]["drive"]) + elif key == ord('s'): + if self.slot[4]["drive"] < 16: self.slot[4]["drive"] += 1 + cli.box.speedminimum(4, self.slot[4]["drive"]) + elif key == ord('y'): + if self.slot[5]["drive"] > 0: self.slot[5]["drive"] -= 1 + cli.box.speedminimum(5, self.slot[5]["drive"]) + elif key == ord('x'): + if self.slot[5]["drive"] < 16: self.slot[5]["drive"] += 1 + cli.box.speedminimum(5, self.slot[4]["drive"]) - self.render_slots() - self.scr.refresh() + + # is there something in the rx buffer? + rx = self.box.com.readline() + if rx != "": + # we have received something + data = rx.split(":") + if rx[:2] == "L:": + # update lap time info + slot = int(data[3]) - 1 + t = int(data[4], 16) + l = int(data[2], 16) + t = t / 2000.00 # time in seconds + self.slot[slot]["laps"] = l + self.slot[slot]["last"] = t + if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): self.slot[slot]["best"] = t + self.render_slots() + + + self.scr.refresh() # terminate curses.nocbreak() self.scr.keypad(0) curses.echo() curses.endwin() - - - print repr(self.slot) return None if __name__ == "__main__":