slotUI/SlotCli.py

changeset 85
a637228562a7
parent 82
c89221096db7
child 86
79fb119cf3c3
equal deleted inserted replaced
84:39d361d87755 85:a637228562a7
190 if rx != "": 190 if rx != "":
191 self.scr.addstr(10,0, 191 self.scr.addstr(10,0,
192 "Last RX: %19s" % rx, curses.color_pair(2)) 192 "Last RX: %19s" % rx, curses.color_pair(2))
193 self.scr.refresh() 193 self.scr.refresh()
194 # we have received something 194 # we have received something
195 data = rx.split(":") 195 try:
196 if rx[:2] == "L:": 196 data = rx.split(":")
197 # update lap time info 197 if rx[:2] == "L:":
198 l = int(data[2], 16) 198 # update lap time info
199 slot = int(data[3]) - 1 199 l = int(data[2], 16)
200 t = int(data[4], 16) / 2000.00 200 slot = int(data[3]) - 1
201 self.sysclk = int(data[5], 16) / 2000.00 201 t = int(data[4], 16) / 2000.00
202 self.slot[slot]["laps"] = l 202 self.sysclk = int(data[5], 16) / 2000.00
203 self.slot[slot]["last"] = t 203 self.slot[slot]["laps"] = l
204 self.slot[slot]["clk"] = self.sysclk 204 self.slot[slot]["last"] = t
205 if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0): self.slot[slot]["best"] = t 205 self.slot[slot]["clk"] = self.sysclk
206 if self.bestlap > t: 206 if (self.slot[slot]["best"] > t) or (self.slot[slot]["best"] == 0):
207 trigger_sound("lap_record") 207 self.slot[slot]["best"] = t
208 self.bestlap = t 208 if self.bestlap > t:
209 209 trigger_sound("lap_record")
210 self.slot[slot]["status"] = "IN-RACE" 210 self.bestlap = t
211 self.render_slots() 211
212 212 self.slot[slot]["status"] = "IN-RACE"
213 if rx[:2] == "F:": 213 self.render_slots()
214 # update fuel level 214
215 slot = int(data[1]) 215 if rx[:2] == "F:":
216 f = int(data[2], 16) 216 # update fuel level
217 f = f / 100 # fuel in percent 217 slot = int(data[1])
218 self.sysclk = int(data[3], 16) / 2000.00 218 f = int(data[2], 16)
219 self.slot[slot]["fuel_last"] = self.slot[slot]["fuel"] 219 f = f / 100 # fuel in percent
220 self.slot[slot]["fuel"] = f 220 self.sysclk = int(data[3], 16) / 2000.00
221 if self.slot[slot]["fuel_last"] != f: 221 self.slot[slot]["fuel_last"] = self.slot[slot]["fuel"]
222 # 10 percent fuel, set speed limit for car to 8 222 self.slot[slot]["fuel"] = f
223 if (self.slot[slot]["fuel_last"] == 11) and (f == 10): 223 if self.slot[slot]["fuel_last"] != f:
224 # warning sound 224 if (self.slot[slot]["fuel_last"] == 11) and (f == 10):
225 trigger_sound("fuel_warning1") 225 # 10 percent fuel, set speed limit for car to 8
226 cli.box.speedlimit(slot, 8) 226 # warning sound
227 # 5 percent, set speed limit for car to 4 227 trigger_sound("fuel_warning1")
228 if (self.slot[slot]["fuel_last"] == 6) and (f == 5): 228 cli.box.speedlimit(slot, 8)
229 # warning sound 229 if (self.slot[slot]["fuel_last"] == 6) and (f == 5):
230 trigger_sound("fuel_warning2") 230 # 5 percent, set speed limit for car to 4
231 cli.box.speedlimit(slot, 4) 231 # warning sound
232 if (self.slot[slot]["fuel_last"] == 1) and (f == 0): 232 trigger_sound("fuel_warning2")
233 # set speedlimit to 2 233 cli.box.speedlimit(slot, 4)
234 cli.box.speedlimit(slot, 3) 234 if (self.slot[slot]["fuel_last"] == 1) and (f == 0):
235 if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20): 235 # fuel empty
236 cli.box.speedlimit(slot, 15) 236 # set speedlimit to 3
237 if (self.slot[slot]["fuel_last"] < f) and (f == 100): 237 cli.box.speedlimit(slot, 3)
238 trigger_sound("fuel_full") 238 if (self.slot[slot]["fuel_last"] < f) and (f >= 11) and (f < 20):
239 self.render_slots() 239 cli.box.speedlimit(slot, 15)
240 240 if (self.slot[slot]["fuel_last"] < f) and (f == 100):
241 if rx[:1] == "~": 241 trigger_sound("fuel_full")
242 # jumpstart occured 242 self.render_slots()
243 slot = int(rx[1:2]) 243
244 t = int(data[1], 16) / 2000.00 244 if rx[:1] == "~":
245 self.slot[slot]["jumpstart"] = t 245 # jumpstart occured
246 self.slot[slot]["status"] = "Jumpstart!" 246 slot = int(rx[1:2])
247 247 t = int(data[1], 16) / 2000.00
248 if rx[:3] == "RW:": 248 self.slot[slot]["jumpstart"] = t
249 # ResponseWire packet, do nothing at the moment, just decode 249 self.slot[slot]["status"] = "Jumpstart!"
250 slot = int(data[1]) 250
251 devtype = int(data[2]) 251 if rx[:3] == "RW:":
252 sender = int(data[3], 16) 252 # ResponseWire packet, do nothing at the moment, just decode
253 status = int(data[4], 16) 253 slot = int(data[1])
254 self.sysclk = int(data[5], 16) 254 devtype = int(data[2])
255 if (devtype == 4): 255 sender = int(data[3], 16)
256 # pitlane sent something 256 status = int(data[4], 16)
257 if (status == 5): 257 self.sysclk = int(data[5], 16)
258 self.slot[slot]["status"] = "PITLANE" 258 if (devtype == 4):
259 trigger_sound("pitlane_enter") 259 # pitlane sent something
260 if (status == 6): 260 if (status == 5):
261 self.slot[slot]["status"] = "IN-RACE" 261 self.slot[slot]["status"] = "PITLANE"
262 trigger_sound("pitlane_exit") 262 trigger_sound("pitlane_enter")
263 263 if (status == 6):
264 self.render_slots() 264 self.slot[slot]["status"] = "IN-RACE"
265 265 trigger_sound("pitlane_exit")
266 if rx == "!RACE PREPARE": 266
267 # reset current race status 267 self.render_slots()
268 # and display PREPARE PHASE 268
269 self.reset_slots() 269 if rx == "!RACE PREPARE":
270 for slot in range(MAXSLOTS): 270 # reset current race status
271 self.slot[slot]["status"] = "Prepare" 271 # and display PREPARE PHASE
272 trigger_sound("race_prepare") 272 self.reset_slots()
273 273 for slot in range(MAXSLOTS):
274 if rx == "!RACE START": 274 self.slot[slot]["status"] = "Prepare"
275 for slot in range(MAXSLOTS): 275 trigger_sound("race_prepare")
276 if self.slot[slot]["status"] == "~~~~~~~~~~": 276
277 self.slot[slot]["status"] = "Idle" 277 if rx == "!RACE START":
278 trigger_sound("race_start") 278 for slot in range(MAXSLOTS):
279 279 if self.slot[slot]["status"] == "~~~~~~~~~~":
280 if rx == "!COUNTDOWN": 280 self.slot[slot]["status"] = "Idle"
281 # countdown initiated 281 trigger_sound("race_start")
282 for slot in range(MAXSLOTS): 282
283 self.slot[slot]["status"] = "~~~~~~~~~~" 283 if rx == "!COUNTDOWN":
284 trigger_sound("countdown_start") 284 # countdown initiated
285 285 for slot in range(MAXSLOTS):
286 self.scr.addstr(10,31, 286 self.slot[slot]["status"] = "~~~~~~~~~~"
287 "Race Timer: %7.3f min" % (self.sysclk / 60), 287 trigger_sound("countdown_start")
288 curses.color_pair(2)) 288
289 289 self.scr.addstr(10,31,
290 self.scr.refresh() 290 "Race Timer: %7.3f min" % (self.sysclk / 60),
291 curses.color_pair(2))
292
293 self.scr.refresh()
294
295 except Exception:
296 trigger_sound("data_error")
297 pass
291 298
292 # terminate 299 # terminate
293 curses.nocbreak() 300 curses.nocbreak()
294 self.scr.keypad(0) 301 self.scr.keypad(0)
295 curses.echo() 302 curses.echo()

mercurial