Sat, 17 Dec 2011 15:38:17 +0100
improved live display with colors
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 | |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
7 | from freeslot import Blackbox, LOGLEVEL |
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 |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
9 | from operator import itemgetter |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
10 | from subprocess import Popen, PIPE |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
11 | import sys, os |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
12 | from copy import copy |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
13 | 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
|
14 | |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
15 | VERSION = "1.5" |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
16 | MAXSLOTS = 6 |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
17 | TERM = { |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
18 | "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
|
19 | "text": "\033[1;30m", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
20 | } |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
21 | |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
22 | # disable debug log output |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
23 | LOGLEVEL = 10 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
24 | |
81 | 25 | SOUNDPREFIX = "quake-" |
26 | ||
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
27 | SOUNDS = { |
81 | 28 | "countdown_start": os.path.abspath(SOUNDPREFIX + "sound/countdown.mp3"), |
29 | "race_start": os.path.abspath(SOUNDPREFIX + "sound/racestart.mp3"), | |
30 | "race_prepare": os.path.abspath(SOUNDPREFIX + "sound/siren.mp3"), | |
31 | "lap_record": os.path.abspath(SOUNDPREFIX + "sound/laprecord.mp3"), | |
32 | "fuel_warning1": os.path.abspath(SOUNDPREFIX + "sound/fuel1.mp3"), | |
33 | "fuel_warning2": os.path.abspath(SOUNDPREFIX + "sound/fuel2.mp3"), | |
34 | "fuel_full": os.path.abspath(SOUNDPREFIX + "sound/fuel_full.mp3"), | |
35 | "pitlane_enter": os.path.abspath(SOUNDPREFIX + "sound/pitlane_enter.mp3"), | |
36 | "pitlane_exit": os.path.abspath(SOUNDPREFIX + "sound/pitlane_exit.mp3"), | |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
37 | "data_error": os.path.abspath(SOUNDPREFIX + "sound/data_error.mp3"), |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
38 | "panic": os.path.abspath(SOUNDPREFIX + "sound/panic.mp3"), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
39 | "panic_shortcut": os.path.abspath(SOUNDPREFIX + "sound/panic_shortcut.mp3"), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
40 | "resume": os.path.abspath(SOUNDPREFIX + "sound/resume.mp3"), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
41 | |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
42 | } |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
43 | |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
44 | def trigger_sound(what): |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
45 | if what in SOUNDS: |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
46 | Popen(["/usr/bin/mpg123", "-q", SOUNDS[what]]) |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
47 | #os.spawnlp(os.P_NOWAIT, "/usr/bin/mpg123", "mpg123", SOUNDS[what]) |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
48 | #Popen(["/usr/bin/mpg123", SOUNDS[what]]).pid |
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
49 | |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
50 | class SlotCli(): |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
51 | def __init__(self, test = None): |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
52 | self.box = Blackbox() |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
53 | if not test: |
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
54 | self.box.connect() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
55 | self.slot_dummy = { |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
56 | "name": "Unnamed", |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
57 | "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
|
58 | "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
|
59 | "best": 0.00, |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
60 | "fuel": 0, |
81 | 61 | "fuel_last": 0, |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
62 | "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
|
63 | "drive": 0, |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
64 | "status": "Idle", |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
65 | "clk": 0, |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
66 | "car": 0, |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
67 | } |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
68 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
69 | self.slot = [ |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
70 | 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
|
71 | 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
|
72 | 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
|
73 | ] |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
74 | self.reset_slots() |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
75 | self.sysclk = 0.00 |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
76 | self.bestlap = 9999999.00 |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
77 | self.test = test |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
78 | self.laplimit = 999; |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
79 | self.timelimit = 0; |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
80 | |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
81 | def reset_slots(self): |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
82 | idx = 0 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
83 | for slt in self.slot: |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
84 | slt["laps"] = 0 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
85 | slt["last"] = 0.00 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
86 | slt["best"] = 0.00 |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
87 | slt["fuel"] = 100 |
81 | 88 | slt["fuel_last"] = 0 |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
89 | slt["position"] = idx |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
90 | slt["car"] = idx # used for sort order calculation |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
91 | slt["status"] = self.slot_dummy["status"] |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
92 | slt["clk"] = 0 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
93 | idx += 1 |
82 | 94 | self.bestlap = 99999.00 |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
95 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
96 | def update_positions(self): |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
97 | order1 = sorted(self.slot, key=itemgetter( |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
98 | "clk")) |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
99 | order2 = sorted(self.slot, key=itemgetter( |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
100 | "laps"), reverse=True) |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
101 | idx = 1 |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
102 | for tst in order2: |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
103 | self.slot[tst["car"]]["position"] = idx |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
104 | idx += 1 |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
105 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
106 | def render_slots(self): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
107 | self.update_positions() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
108 | self.scr.addstr(3,0, |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
109 | #"Pos | #/Name | Laps | Best | Last | Fuel | Status ", |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
110 | "Pos | #/Name ", |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
111 | curses.color_pair(2)) |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
112 | self.scr.addstr(4,4, |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
113 | " Laps | Best | Last | Fuel | Status ", |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
114 | curses.color_pair(2)) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
115 | for idx in range(MAXSLOTS): |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
116 | """ |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
117 | self.scr.addstr((3 + (self.slot[idx]["position"] * 2)), 0, |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
118 | "%3i | %i %15s | %4i | %7.2fs | %7.2fs | %3i%% | %10s" % ( |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
119 | self.slot[idx]["position"], |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
120 | self.slot[idx]["car"] + 1, self.slot[idx]["name"], |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
121 | self.slot[idx]["laps"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
122 | self.slot[idx]["best"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
123 | self.slot[idx]["last"], |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
124 | self.slot[idx]["fuel"], |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
125 | self.slot[idx]["status"], |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
126 | ), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
127 | curses.color_pair(11 + idx) ) |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
128 | """ |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
129 | self.scr.addstr((3 + (self.slot[idx]["position"] * 2)), 0, |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
130 | "%3i | %i %15s %48s" % ( |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
131 | self.slot[idx]["position"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
132 | self.slot[idx]["car"] + 1, self.slot[idx]["name"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
133 | "", |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
134 | ), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
135 | curses.color_pair(11 + idx) ) |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
136 | self.scr.addstr((4 + (self.slot[idx]["position"] * 2)), 4, |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
137 | " %4i | %7.2fs | %7.2fs | %3i%% | %10s %19s" % ( |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
138 | self.slot[idx]["laps"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
139 | self.slot[idx]["best"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
140 | self.slot[idx]["last"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
141 | self.slot[idx]["fuel"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
142 | self.slot[idx]["status"], |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
143 | "" |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
144 | ), |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
145 | curses.color_pair(11 + idx) ) |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
146 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
147 | def cleartop(self): |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
148 | 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
|
149 | 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
|
150 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
151 | def readName(self, slot): |
56
a20f59a3016c
ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents:
55
diff
changeset
|
152 | 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
|
153 | curses.echo() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
154 | 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
|
155 | slot + 1, |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
156 | self.slot[slot]["name"]), |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
157 | curses.color_pair(1)) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
158 | self.scr.refresh() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
159 | 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
|
160 | if name != "": |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
161 | self.slot[slot]["name"] = name |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
162 | 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
|
163 | self.scr.refresh() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
164 | curses.noecho() |
56
a20f59a3016c
ui fix, added car5+6 detector to blackbox
Malte Bayer <mbayer@neo-soft.org>
parents:
55
diff
changeset
|
165 | 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
|
166 | |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
167 | def readInt(self, msg, default): |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
168 | self.scr.nodelay(0) # enable delay on readkey |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
169 | curses.echo() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
170 | self.scr.addstr(0,0, "%s [%i]:" % ( |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
171 | msg, |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
172 | default, |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
173 | curses.color_pair(1)) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
174 | ) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
175 | self.scr.refresh() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
176 | inp = self.scr.getstr(1,0, 4) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
177 | if inp != "": |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
178 | try: |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
179 | inp = int(inp) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
180 | except Exception: |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
181 | inp = None |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
182 | else: |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
183 | inp = None |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
184 | self.cleartop() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
185 | self.scr.refresh() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
186 | curses.noecho() |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
187 | self.scr.nodelay(1) # disable delay on readkey |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
188 | return inp |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
189 | |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
190 | |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
191 | def monitor_init(self): |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
192 | """ |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
193 | Send initializing commands for live monitoring |
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
194 | """ |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
195 | self.box.query("F1\n") # set fuel logic enabled |
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
196 | self.box.query("*1\n") # set live fuel info |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
197 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
198 | def monitor(self): |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
199 | """ |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
200 | Live Monitor on the console |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
201 | Keyboard loop to control it??? |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
202 | """ |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
203 | # clear garbage in UART rx buffer |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
204 | while self.box.readline() != "": pass |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
205 | |
74
173d0863a804
added live init to slotcli
Malte Bayer <mbayer@neo-soft.org>
parents:
61
diff
changeset
|
206 | self.monitor_init() |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
207 | self.scr = curses.initscr() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
208 | curses.start_color() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
209 | 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
|
210 | curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLUE) # label |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
211 | curses.init_pair(11, curses.COLOR_BLACK, curses.COLOR_YELLOW) # player 1 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
212 | curses.init_pair(12, curses.COLOR_BLACK, curses.COLOR_GREEN) # player 2 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
213 | curses.init_pair(13, curses.COLOR_BLACK, curses.COLOR_RED) # player 3 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
214 | curses.init_pair(14, curses.COLOR_BLACK, curses.COLOR_MAGENTA) # player 4 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
215 | curses.init_pair(15, curses.COLOR_WHITE, curses.COLOR_BLACK) # player 5 slot |
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
216 | curses.init_pair(16, curses.COLOR_WHITE, curses.COLOR_BLACK) # player 6 slot |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
217 | curses.noecho() # disable key echo |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
218 | 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
|
219 | 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
|
220 | 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
|
221 | |
59
361bc4602cf7
added fuel management to blackbox, cars dont get stuck at the moment
Malte Bayer <mbayer@neo-soft.org>
parents:
56
diff
changeset
|
222 | 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
|
223 | 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
|
224 | 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
|
225 | |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
226 | |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
227 | while 1: |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
228 | key = self.scr.getch() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
229 | if key == ord('q'): break |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
230 | elif key == ord(' '): self.box.query("+") # panic / resume |
90
7ed95dbadf1f
added remote start button press
Malte Bayer <mbayer@neo-soft.org>
parents:
89
diff
changeset
|
231 | elif key == 10: self.box.query("#") # remote start button press |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
232 | 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
|
233 | 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
|
234 | 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
|
235 | 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
|
236 | 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
|
237 | 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
|
238 | 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
|
239 | 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
|
240 | 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
|
241 | 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
|
242 | 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
|
243 | 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
|
244 | 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
|
245 | 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
|
246 | 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
|
247 | 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
|
248 | 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
|
249 | cli.box.speedminimum(5, self.slot[4]["drive"]) |
94
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
250 | elif key == ord('t'): |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
251 | tmp = self.readInt("Set new Race TIME limit", self.timelimit) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
252 | if tmp: self.timelimit = tmp |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
253 | elif key == ord('l'): |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
254 | tmp = self.readInt("Set new Race LAP limit", self.laplimit) |
c7ff8cde6b1e
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
93
diff
changeset
|
255 | if tmp: self.laplimit = tmp |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
256 | |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
257 | |
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
258 | # is there something in the rx buffer? |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
259 | rx = self.box.readline() |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
260 | if (rx != "") or self.test: |
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
261 | self.scr.addstr(17,0, |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
262 | "Last RX: %19s" % rx, curses.color_pair(2)) |
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
263 | self.scr.refresh() |
55
9293f3efcc06
added live display to CLI (lap counter, last and best time)
Malte Bayer <mbayer@neo-soft.org>
parents:
54
diff
changeset
|
264 | # we have received something |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
265 | try: |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
266 | data = rx.split(":") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
267 | if rx[:2] == "L:": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
268 | # update lap time info |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
269 | l = int(data[2], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
270 | slot = int(data[3]) - 1 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
271 | t = int(data[4], 16) / 2000.00 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
272 | self.sysclk = int(data[5], 16) / 2000.00 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
273 | self.slot[slot]["laps"] = l |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
274 | self.slot[slot]["last"] = t |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
275 | self.slot[slot]["clk"] = self.sysclk |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
276 | if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
277 | self.slot[slot]["best"] = t |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
278 | if self.bestlap > t: |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
279 | trigger_sound("lap_record") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
280 | self.bestlap = t |
78
d9126a55295c
added sound triggers to live mode
Malte Bayer <mbayer@neo-soft.org>
parents:
77
diff
changeset
|
281 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
282 | self.slot[slot]["status"] = "IN-RACE" |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
283 | 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
|
284 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
285 | if rx[:2] == "F:": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
286 | # update fuel level |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
287 | slot = int(data[1]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
288 | f = int(data[2], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
289 | f = f / 100 # fuel in percent |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
290 | self.sysclk = int(data[3], 16) / 2000.00 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
291 | self.slot[slot]["fuel_last"] = self.slot[slot]["fuel"] |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
292 | self.slot[slot]["fuel"] = f |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
293 | if self.slot[slot]["fuel_last"] != f: |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
294 | if (self.slot[slot]["fuel_last"] == 11) and (f == 10): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
295 | # 10 percent fuel, set speed limit for car to 8 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
296 | # warning sound |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
297 | trigger_sound("fuel_warning1") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
298 | cli.box.speedlimit(slot, 8) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
299 | if (self.slot[slot]["fuel_last"] == 6) and (f == 5): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
300 | # 5 percent, set speed limit for car to 4 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
301 | # warning sound |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
302 | trigger_sound("fuel_warning2") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
303 | cli.box.speedlimit(slot, 4) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
304 | if (self.slot[slot]["fuel_last"] == 1) and (f == 0): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
305 | # fuel empty |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
306 | # set speedlimit to 3 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
307 | cli.box.speedlimit(slot, 3) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
308 | if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
309 | cli.box.speedlimit(slot, 15) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
310 | if (self.slot[slot]["fuel_last"] < f) and (f == 100): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
311 | trigger_sound("fuel_full") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
312 | 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
|
313 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
314 | if rx[:1] == "~": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
315 | # jumpstart occured |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
316 | slot = int(rx[1:2]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
317 | t = int(data[1], 16) / 2000.00 |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
318 | self.slot[slot]["jumpstart"] = t |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
319 | self.slot[slot]["status"] = "Jumpstart!" |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
320 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
321 | if rx[:3] == "RW:": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
322 | # ResponseWire packet, do nothing at the moment, just decode |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
323 | slot = int(data[1]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
324 | devtype = int(data[2]) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
325 | sender = int(data[3], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
326 | status = int(data[4], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
327 | self.sysclk = int(data[5], 16) |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
328 | if (devtype == 4): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
329 | # pitlane sent something |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
330 | if (status == 5): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
331 | self.slot[slot]["status"] = "PITLANE" |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
332 | trigger_sound("pitlane_enter") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
333 | if (status == 6): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
334 | self.slot[slot]["status"] = "IN-RACE" |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
335 | trigger_sound("pitlane_exit") |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
336 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
337 | self.render_slots() |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
338 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
339 | if rx == "!RACE PREPARE": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
340 | # reset current race status |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
341 | # and display PREPARE PHASE |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
342 | self.reset_slots() |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
343 | for slot in range(MAXSLOTS): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
344 | self.slot[slot]["status"] = "Prepare" |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
345 | trigger_sound("race_prepare") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
346 | |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
347 | if rx == "!RACE START": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
348 | for slot in range(MAXSLOTS): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
349 | if self.slot[slot]["status"] == "~~~~~~~~~~": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
350 | self.slot[slot]["status"] = "Idle" |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
351 | trigger_sound("race_start") |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
352 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
353 | if rx == "!COUNTDOWN": |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
354 | # countdown initiated |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
355 | for slot in range(MAXSLOTS): |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
356 | self.slot[slot]["status"] = "~~~~~~~~~~" |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
357 | trigger_sound("countdown_start") |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
358 | |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
359 | if rx == "!PANIC": |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
360 | # panic mode |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
361 | trigger_sound("panic") |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
362 | |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
363 | if rx == "!SHORTCUT": |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
364 | # panic mode |
93
ee4f9b8a36e9
improved live display with colors
Malte Bayer <mbayer@neo-soft.org>
parents:
90
diff
changeset
|
365 | trigger_sound("panic_shortcut") |
89
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
366 | |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
367 | if rx == "!RESUME": |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
368 | # panic mode |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
369 | trigger_sound("resume") |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
370 | |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
371 | |
4b5b4c7ba03d
added panic mode, shortcircuit can be resumed now
Malte Bayer <mbayer@neo-soft.org>
parents:
87
diff
changeset
|
372 | |
87
761863c71884
added empty lines between live data display entries
Malte Bayer <mbayer@neo-soft.org>
parents:
86
diff
changeset
|
373 | self.scr.addstr(17,31, |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
374 | "Race Timer: %7.3f min" % (self.sysclk / 60), |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
375 | curses.color_pair(2)) |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
376 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
377 | self.scr.refresh() |
77
cede78304992
finished live CLI, BB firmware improvements and fixes
Malte Bayer <mbayer@neo-soft.org>
parents:
74
diff
changeset
|
378 | |
85
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
379 | except Exception: |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
380 | trigger_sound("data_error") |
a637228562a7
added exception drop in uart rx tree
Malte Bayer <mbayer@neo-soft.org>
parents:
82
diff
changeset
|
381 | pass |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
382 | |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
383 | # terminate |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
384 | curses.nocbreak() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
385 | self.scr.keypad(0) |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
386 | curses.echo() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
387 | curses.endwin() |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
388 | return None |
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
389 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
390 | def cyclemode(self): |
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
391 | pass |
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
392 | |
27
3e617fcf999a
added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents:
25
diff
changeset
|
393 | 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
|
394 | 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
|
395 | 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
|
396 | 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
|
397 | |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
398 | parser.add_option("--slot", dest="carid", |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
399 | 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
|
400 | 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
|
401 | 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
|
402 | 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
|
403 | 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
|
404 | 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
|
405 | 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
|
406 | 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
|
407 | 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
|
408 | 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
|
409 | 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
|
410 | parser.add_option("--drive", dest="drive", |
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
411 | help="Controlled SPEED MINIMUM (0 = disabled)", metavar="[0-15]") |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
412 | parser.add_option("--test", dest="test", action="store_true", default=False, |
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
413 | help="", metavar="") |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
414 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
415 | (options, args) = parser.parse_args() |
86
79fb119cf3c3
added test option without communication
Malte Bayer <mbayer@neo-soft.org>
parents:
85
diff
changeset
|
416 | cli = SlotCli(options.test) |
35
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
417 | # 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
|
418 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
419 | if options.live: |
54
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
420 | # start the live monitor |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
421 | cli.monitor() |
68eca8057d68
added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents:
50
diff
changeset
|
422 | 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
|
423 | |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
424 | # check commandline if we have to program something |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
425 | 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
|
426 | 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
|
427 | 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
|
428 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
429 | 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
|
430 | 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
|
431 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
432 | 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
|
433 | 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
|
434 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
435 | 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
|
436 | 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
|
437 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
438 | 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
|
439 | state = False |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
440 | 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
|
441 | state = True |
00166228a419
cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents:
27
diff
changeset
|
442 | 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
|
443 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
444 | 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
|
445 | 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
|
446 | |
58
042c490fdfaa
better code quality
Tobias Paepke <tobias.paepke@paepke.net>
parents:
56
diff
changeset
|
447 | if options.drive: |
50
84b8ab4cd79e
implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents:
36
diff
changeset
|
448 | 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
|
449 |