Sat, 10 Dec 2011 17:12:47 +0100
made fuel divisor configurable
25
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
1 | #!/usr/bin/env python |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
2 | """ |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
3 | Freeslot project |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
4 | Command line interface |
646ee4dc3a6b
started communication class and CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
diff
changeset
|
5 | """ |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
6 | |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
7 | from freeslot import Blackbox |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
8 | from optparse import OptionParser |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
9 | import sys |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
10 | from copy import copy |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
11 | import curses |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
12 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
13 | VERSION = "1.2" |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
14 | MAXSLOTS = 6 |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
15 | TERM = { |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
16 | "caption": "\033[1;37m\033[1;44m", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
17 | "text": "\033[1;30m", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
18 | } |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
19 | |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
20 | class SlotCli(): |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
21 | def __init__(self): |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
22 | self.box = Blackbox() |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
23 | self.box.connect() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
24 | self.slot_dummy = { |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
25 | "name": "Unnamed", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
26 | "laps": 0, |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
27 | "last": 0.00, |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
28 | "best": 0.00, |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
29 | "fuel": 0, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
30 | "position": 0, |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
31 | "drive": 0, |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
32 | } |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
33 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
34 | self.slot = [ |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
35 | copy(self.slot_dummy), copy(self.slot_dummy), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
36 | copy(self.slot_dummy), copy(self.slot_dummy), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
37 | copy(self.slot_dummy), copy(self.slot_dummy), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
38 | ] |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
39 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
40 | def update_positions(self): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
41 | for idx in range(MAXSLOTS): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
42 | self.slot[idx]["position"] = idx + 1 |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
43 | # TODO |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
44 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
45 | def render_slots(self): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
46 | self.update_positions() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
47 | self.scr.addstr(3,0, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
48 | "Pos | #/Name | Laps | Best | Last | Fuel |", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
49 | curses.color_pair(2)) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
50 | for idx in range(MAXSLOTS): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
51 | self.scr.addstr((3 + self.slot[idx]["position"]), 0, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
52 | "%3i | %15s | %4i | %5.2fs | %5.2fs | %3i%% |" % ( |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
53 | self.slot[idx]["position"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
54 | self.slot[idx]["name"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
55 | self.slot[idx]["laps"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
56 | self.slot[idx]["best"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
57 | self.slot[idx]["last"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
58 | self.slot[idx]["fuel"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
59 | ) ) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
60 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
61 | def cleartop(self): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
62 | self.scr.addstr(0,0, "%80s" % "Live monitor running, press keys to control or (q)uit") |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
63 | self.scr.addstr(1,0, "%80s" % " ") |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
64 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
65 | def readName(self, slot): |
56
a20f59a3016c
ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents:
55
diff
changeset
|
66 | self.scr.nodelay(0) # enable delay on readkey |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
67 | curses.echo() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
68 | self.scr.addstr(0,0, "Enter Name for Controller %i [%s]:" % ( |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
69 | slot + 1, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
70 | self.slot[slot]["name"]), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
71 | curses.color_pair(1)) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
72 | self.scr.refresh() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
73 | name = self.scr.getstr(1,0, 15) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
74 | if name != "": |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
75 | self.slot[slot]["name"] = name |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
76 | self.cleartop() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
77 | self.scr.refresh() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
78 | curses.noecho() |
56
a20f59a3016c
ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents:
55
diff
changeset
|
79 | self.scr.nodelay(1) # disable delay on readkey |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
80 | |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
81 | def monitor_init(self): |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
82 | """ |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
83 | Send initializing commands for live monitoring |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
84 | """ |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
85 | self.box.com.query("F1\n") # set fuel logic enabled |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
86 | self.box.com.query("*1\n") # set live fuel info |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
87 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
88 | def monitor(self): |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
89 | """ |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
90 | Live Monitor on the console |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
91 | Keyboard loop to control it??? |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
92 | """ |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
93 | self.monitor_init() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
94 | self.scr = curses.initscr() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
95 | curses.start_color() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
96 | curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) # standard text |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
97 | curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE) # label |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
98 | curses.noecho() # disable key echo |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
99 | curses.cbreak() # do not buffer keypresses |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
100 | self.scr.keypad(1) # enable special keys |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
101 | self.scr.nodelay(1) # disable delay on readkey |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
102 | |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
103 | self.cleartop() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
104 | self.render_slots() |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
105 | self.scr.refresh() |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
106 | |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
107 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
108 | while 1: |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
109 | key = self.scr.getch() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
110 | if key == ord('q'): break |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
111 | elif key == ord(' '): self.cyclemode() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
112 | elif key == ord('1'): self.readName(0) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
113 | elif key == ord('2'): self.readName(1) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
114 | elif key == ord('3'): self.readName(2) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
115 | elif key == ord('4'): self.readName(3) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
116 | elif key == ord('5'): self.readName(4) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
117 | elif key == ord('6'): self.readName(5) |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
118 | elif key == ord('a'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
119 | if self.slot[4]["drive"] > 0: self.slot[4]["drive"] -= 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
120 | cli.box.speedminimum(4, self.slot[4]["drive"]) |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
121 | elif key == ord('s'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
122 | if self.slot[4]["drive"] < 16: self.slot[4]["drive"] += 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
123 | cli.box.speedminimum(4, self.slot[4]["drive"]) |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
124 | elif key == ord('y'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
125 | if self.slot[5]["drive"] > 0: self.slot[5]["drive"] -= 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
126 | cli.box.speedminimum(5, self.slot[5]["drive"]) |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
127 | elif key == ord('x'): |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
128 | if self.slot[5]["drive"] < 16: self.slot[5]["drive"] += 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
129 | cli.box.speedminimum(5, self.slot[4]["drive"]) |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
130 | |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
131 | |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
132 | # is there something in the rx buffer? |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
133 | rx = self.box.com.readline() |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
134 | if rx != "": |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
135 | # we have received something |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
136 | data = rx.split(":") |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
137 | if rx[:2] == "L:": |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
138 | # update lap time info |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
139 | slot = int(data[3]) - 1 |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
140 | t = int(data[4], 16) |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
141 | l = int(data[2], 16) |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
142 | t /= 2000.00 |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
143 | self.slot[slot]["laps"] = l |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
144 | self.slot[slot]["last"] = t |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
145 | if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): self.slot[slot]["best"] = t |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
146 | self.render_slots() |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
147 | |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
148 | if rx[:2] == "F:": |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
149 | # update fuel level |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
150 | slot = int(data[1]) |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
151 | f = int(data[2], 16) |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
152 | f = f / 100 # fuel in percent |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
153 | self.slot[slot]["fuel"] = f |
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
154 | self.render_slots() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
155 | |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
156 | self.scr.refresh() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
157 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
158 | # terminate |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
159 | curses.nocbreak() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
160 | self.scr.keypad(0) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
161 | curses.echo() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
162 | curses.endwin() |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
163 | return None |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
164 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
165 | def cyclemode(self): |
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
166 | pass |
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
167 | |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
168 | if __name__ == "__main__": |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
169 | parser = OptionParser(version="%prog " + VERSION) |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
170 | parser.add_option("--live", dest="live", action="store_true", default=False, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
171 | help="Run Live monitor on console", metavar="[0-5]") |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
172 | |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
173 | parser.add_option("--carid", dest="carid", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
174 | help="Required for programming a car directly", metavar="[0-5]") |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
175 | parser.add_option("--fuel", dest="fuel", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
176 | help="Set maximum CAR fuel level", metavar="[0-15]") |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
177 | parser.add_option("--brake", dest="brake", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
178 | help="Set CAR brake strength", metavar="[0-15]") |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
179 | parser.add_option("--speed", dest="speed", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
180 | help="Set maximum CAR speed", metavar="[0-15]") |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
181 | parser.add_option("--blink", dest="blink", |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
182 | help="Set car lights blinking state", metavar="[on|off]") |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
183 | parser.add_option("--limit", dest="limit", |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
184 | help="Controlled SPEED LIMIT (15 = no limit)", metavar="[0-15]") |
50
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
185 | parser.add_option("--drive", dest="drive", |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
186 | help="Controlled SPEED MINIMUM (0 = disabled)", metavar="[0-15]") |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
187 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
188 | (options, args) = parser.parse_args() |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
189 | cli = SlotCli() |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
190 | # should a CLI function be started? |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
191 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
192 | if options.live: |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
193 | # start the live monitor |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
194 | cli.monitor() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
195 | sys.exit(0) |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
196 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
197 | # check commandline if we have to program something |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
198 | if not options.carid: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
199 | print "Option --carid is required for all car programming commands!\nUse --help to get a list of available commands" |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
200 | sys.exit(1) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
201 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
202 | if options.fuel: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
203 | print "setFuel: " + cli.box.progcar(int(options.carid), "fuel", int(options.fuel)) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
204 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
205 | if options.speed: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
206 | print "setSpeed: " + cli.box.progcar(int(options.carid), "speed", int(options.speed)) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
207 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
208 | if options.brake: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
209 | print "setBrake: " + cli.box.progcar(int(options.carid), "brake", int(options.brake)) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
210 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
211 | if options.blink: |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
212 | state = False |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
213 | if options.blink == "on": |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
214 | state = True |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
215 | print "setBlink: " + cli.box.blinkcar(int(options.carid), state) |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
216 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
217 | if options.limit: |
36
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
218 | print "Change Speed Limit: " + cli.box.speedlimit(int(options.carid), int(options.limit)) |
aea84f4f5a12
feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents:
35
diff
changeset
|
219 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
220 | if options.drive: |
50
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
221 | print "Change minimum Speed drive: " + cli.box.speedminimum(int(options.carid), int(options.drive)) |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
222 |