slotUI/SlotCli.py

Fri, 09 Dec 2011 11:54:19 +0100

author
Malte Bayer <mbayer@neo-soft.org>
date
Fri, 09 Dec 2011 11:54:19 +0100
changeset 54
68eca8057d68
parent 50
84b8ab4cd79e
child 55
9293f3efcc06
permissions
-rwxr-xr-x

added livemode display to slotcli, without communication yet

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
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
9 import time, 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
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
13 VERSION = "1.1"
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,
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
27 "last": 0,
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
28 "best": 0,
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,
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
31 }
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
32
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
33 self.slot = [
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
34 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
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 ]
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 def update_positions(self):
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
40 for idx in range(MAXSLOTS):
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
41 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
42 # TODO
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
43
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
44 def render_slots(self):
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
45 self.update_positions()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
46 self.scr.addstr(3,0,
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
47 "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
48 curses.color_pair(2))
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
49 for idx in range(MAXSLOTS):
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
50 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
51 "%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
52 self.slot[idx]["position"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
53 self.slot[idx]["name"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
54 self.slot[idx]["laps"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
55 self.slot[idx]["best"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
56 self.slot[idx]["last"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
57 self.slot[idx]["fuel"],
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
58 ) )
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 def cleartop(self):
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
61 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
62 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
63
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
64 def readName(self, slot):
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
65 curses.echo()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
66 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
67 slot + 1,
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
68 self.slot[slot]["name"]),
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
69 curses.color_pair(1))
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
70 self.scr.refresh()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
71 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
72 if name != "":
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
73 self.slot[slot]["name"] = name
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
74 self.cleartop()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
75 curses.noecho()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
76
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
77 def monitor(self):
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
78 """
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
79 Live Monitor on the console
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
80 Keyboard loop to control it???
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
81 """
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
82 self.scr = curses.initscr()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
83 curses.start_color()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
84 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
85 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
86 curses.noecho() # disable key echo
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
87 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
88 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
89 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
90
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
91 while 1:
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
92 key = self.scr.getch()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
93 if key == ord('q'): break
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
94 elif key == ord(' '): self.cyclemode()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
95 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
96 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
97 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
98 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
99 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
100 elif key == ord('6'): self.readName(5)
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
101
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
102 self.render_slots()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
103 self.scr.refresh()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
104
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
105 # terminate
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
106 curses.nocbreak()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
107 self.scr.keypad(0)
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
108 curses.echo()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
109 curses.endwin()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
110
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
111
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
112 print repr(self.slot)
27
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
113 return None
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
114
3e617fcf999a added exception, started SlotCli class
Malte Bayer <mbayer@neo-soft.org>
parents: 25
diff changeset
115 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
116 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
117 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
118 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
119
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132 parser.add_option("--drive", dest="drive",
84b8ab4cd79e implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
133 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
134
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
135 (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
136 cli = SlotCli()
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
137 # 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
138
54
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
139 if options.live == True:
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
140 # start the live monitor
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
141 cli.monitor()
68eca8057d68 added livemode display to slotcli, without communication yet
Malte Bayer <mbayer@neo-soft.org>
parents: 50
diff changeset
142 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
143
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
144 # check commandline if we have to program something
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
145 if options.carid == None:
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
146 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
147 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
148
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
149 if options.fuel != None:
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
150 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
151
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
152 if options.speed != None:
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
153 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
154
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
155 if options.brake != None:
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
156 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
157
35
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
158 if options.blink != None:
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
159 state = False
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
160 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
161 state = True
00166228a419 cli: implemented setting of fuel, brake, speed, blinkstate for any car
Malte Bayer <mbayer@neo-soft.org>
parents: 27
diff changeset
162 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
163
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
164 if options.limit != None:
aea84f4f5a12 feature: program a specific controller speed limit without changing the car's acceleration
Malte Bayer <mbayer@neo-soft.org>
parents: 35
diff changeset
165 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
166
50
84b8ab4cd79e implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
167 if options.drive != None:
84b8ab4cd79e implemented new --drive command to CLI
Malte Bayer <mbayer@neo-soft.org>
parents: 36
diff changeset
168 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
169

mercurial